Skip to content

Commit

Permalink
Merge pull request #1870 from reebhub/Python_DocExt2_Cnt_At
Browse files Browse the repository at this point in the history
[Python] Document-extensions pages batch - Counters, Attachments [Replace C# samples]
  • Loading branch information
ppekrol committed Jul 10, 2024
2 parents 68b23e4 + 3153fcc commit 900961b
Show file tree
Hide file tree
Showing 63 changed files with 5,256 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Bulk Insert Attachments

---

{NOTE: }

* [bulk_insert](../../client-api/bulk-insert/how-to-work-with-bulk-insert-operation) is RavenDB's
high-performance data insertion operation.
Use its `attachments_for` interface to add attachments to multiple documents with great speed.
* Use `store`

* In this page:
* [Usage flow](../../document-extensions/attachments/bulk-insert#usage-flow)
* [Usage example](../../document-extensions/attachments/bulk-insert#usage-example)

{NOTE/}

{PANEL: Usage flow}

* Create a `bulk_insert` instance.

* Pass the Document ID to the instance's `attachments_for` method.

* To add an attachment, call the `store` method.
Pass it the attachment's name, stream, and type (optional).
`store` can be called repeatedly, as many times as needed.

* Note:
If an attachment with the specified name already exists on the document,
the bulk insert operation will overwrite it.

{PANEL/}

{PANEL: Usage example}

In this example, we attach a file to all User documents that match a query.
{CODE:python bulk_insert_attachment@DocumentExtensions\Attachments\BulkInsert.py /}

{PANEL/}

## Related articles

### Attachments

- [Storing](../../document-extensions/attachments/storing)
- [Loading](../../document-extensions/attachments/loading)
- [Deleting](../../document-extensions/attachments/deleting)
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ Use `session.advanced.attachments.rename` to rename an attachment.

| Parameter | Type | Description |
|---------------------------|----------|-----------------------------|
| __sourceEntity__ | `object` | Source entity |
| __destinationEntity__ | `object` | Destination entity |
| __sourceDocumentId__ | string | Source document Id |
| __destinationDocumentId__ | string | Destination document Id |
| __sourceName__ | string | Source attachment name |
| __destinationName__ | string | Destination attachment name |
| **sourceEntity** | `object` | Source entity |
| **destinationEntity** | `object` | Destination entity |
| **sourceDocumentId** | string | Source document Id |
| **destinationDocumentId** | string | Destination document Id |
| **sourceName** | string | Source attachment name |
| **destinationName** | string | Destination attachment name |


{CODE:nodejs syntax_rename@documentExtensions\attachments\copyMoveRename.js /}

| Parameter | Type | Description |
|----------------|----------|---------------------------------|
| __entity__ | `object` | The document entity |
| __documentId__ | string | The document Id |
| __name__ | string | Current name of attachment |
| __newName__ | string | The new name for the attachment |
| **entity** | `object` | The document entity |
| **documentId** | string | The document Id |
| **name** | string | Current name of attachment |
| **newName** | string | The new name for the attachment |

{PANEL/}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Attachments: Copy, Move, Rename

Attachments can be copied, moved, or renamed using built-in session methods.
All of those actions are executed when `save_changes` is called and take place on the server-side,
removing the need to transfer the entire attachment binary data over the network in order to perform the action.

{PANEL: Copy attachment}

Attachment can be copied using one of the `session.advanced.attachments.copy` methods:

### Syntax

{CODE:python copy_0@DocumentExtensions\Attachments\CopyMoveRename.py /}

### Example

{CODE:python copy_1@DocumentExtensions\Attachments\CopyMoveRename.py /}

{PANEL/}

{PANEL: Move attachment}

Attachment can be moved using one of the `session.advanced.attachments.move` methods:

### Syntax

{CODE:python move_0@DocumentExtensions\Attachments\CopyMoveRename.py /}

### Example

{CODE:python move_1@DocumentExtensions\Attachments\CopyMoveRename.py /}

{PANEL/}

{PANEL: Rename attachment}

Attachment can be renamed using one of the `session.advanced.attachments.rename` methods:

### Syntax

{CODE:python rename_0@DocumentExtensions\Attachments\CopyMoveRename.py /}

### Example

{CODE:python rename_1@DocumentExtensions\Attachments\CopyMoveRename.py /}

{PANEL/}

## Related Articles

### Attachments

- [What are Attachments](../../document-extensions/attachments/what-are-attachments)
- [Storing](../../document-extensions/attachments/storing)
- [Loading](../../document-extensions/attachments/loading)
- [Deleting](../../document-extensions/attachments/deleting)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Attachments: Deleting Attachments

**Delete** from `session.Advanced.Attachments` is used to remove an attachment from a document.

## Syntax

{CODE DeleteSyntax@DocumentExtensions\Attachments\Attachments.cs /}

## Example

{CODE-TABS}
{CODE-TAB:csharp:Sync DeleteAttachment@DocumentExtensions\Attachments\Attachments.cs /}
{CODE-TAB:csharp:Async DeleteAttachmentAsync@DocumentExtensions\Attachments\Attachments.cs /}
{CODE-TABS/}

## Related Articles

### Attachments

- [What are Attachments](../../document-extensions/attachments/what-are-attachments)
- [Storing](../../document-extensions/attachments/storing)
- [Loading](../../document-extensions/attachments/loading)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Attachments: Deleting Attachments

**Delete** from `session.advanced().attachments()` is used to remove an attachment from a document.

## Syntax

{CODE:java DeleteSyntax@DocumentExtensions\Attachments\Attachments.java /}

## Example

{CODE:java DeleteAttachment@DocumentExtensions\Attachments\Attachments.java /}

## Related Articles

### Attachments

- [What are Attachments](../../document-extensions/attachments/what-are-attachments)
- [Storing](../../document-extensions/attachments/storing)
- [Loading](../../document-extensions/attachments/loading)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Attachments: Deleting Attachments

The method `session.advanced.attachments.delete()` is used to remove an attachment from a document.

## Syntax

{CODE:nodejs DeleteSyntax@DocumentExtensions\Attachments\attachments.js /}

## Example

{CODE:nodejs DeleteAttachment@DocumentExtensions\Attachments\attachments.js /}

## Related Articles

### Attachments

- [What are Attachments](../../document-extensions/attachments/what-are-attachments)
- [Storing](../../document-extensions/attachments/storing)
- [Loading](../../document-extensions/attachments/loading)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Attachments: Deleting Attachments

**Delete** from `session.advanced.attachments` is used to remove an attachment from a document.

## Syntax

{CODE:python DeleteSyntax@DocumentExtensions\Attachments\Attachments.py /}

## Example

{CODE:python DeleteAttachment@DocumentExtensions\Attachments\Attachments.py /}

## Related Articles

### Attachments

- [What are Attachments](../../document-extensions/attachments/what-are-attachments)
- [Storing](../../document-extensions/attachments/storing)
- [Loading](../../document-extensions/attachments/loading)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

* Indexing attachments allows you to query for documents based on their attachments' details and content.

* __Static indexes__:
* **Static indexes**:
Both attachments' details and content can be indexed within a static-index definition.

* __Auto-indexes__:
* **Auto-indexes**:
Auto-indexing attachments via dynamic queries is not available at this time.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

* Indexing attachments allows you to query for documents based on their attachments' details and content.

* __Static indexes__:
* **Static indexes**:
Both attachments' details and content can be indexed within a static-index definition.

* __Auto-indexes__:
* **Auto-indexes**:
Auto-indexing attachments via dynamic queries is not available at this time.

* In this page:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

* Indexing attachments allows you to query for documents based on their attachments' details and content.

* __Static indexes__:
* **Static indexes**:
Both attachments' details and content can be indexed within a static-index definition.

* __Auto-indexes__:
* **Auto-indexes**:
Auto-indexing attachments via dynamic queries is not available at this time.

* In this page:
Expand All @@ -26,13 +26,13 @@

{NOTE: }

__The index__:
**The index**:

---

* To index attachments' details, call `attachmentsFor()` within the index definition.

* `attachmentsFor()` provides access to the __name__, __size__, __hash__, and __content-type__ of each attachment a document has.
* `attachmentsFor()` provides access to the **name**, **size**, **hash**, and **content-type** of each attachment a document has.
These details can then be used when defining the index-fields.

* To index attachments' content, see the examples below.
Expand All @@ -43,7 +43,7 @@ __The index__:

{NOTE: }

__Query the Index__:
**Query the Index**:

---

Expand All @@ -64,7 +64,7 @@ where attachmentNames == "photo.jpg" and attachmentSizes > 20000

{NOTE: }

__Sample data__:
**Sample data**:

---

Expand All @@ -79,11 +79,11 @@ __Sample data__:

{NOTE: }

__The index__:
**The index**:

---

* To index the __details & content__ for a specific attachment, call `loadAttachment()` within the index definition.
* To index the **details & content** for a specific attachment, call `loadAttachment()` within the index definition.

* In addition to accessing the attachment details, `loadAttachment()` provides access to the attachment's content,
which can be used when defining the index-fields.
Expand All @@ -94,7 +94,7 @@ __The index__:

{NOTE: }

__Query the Index__:
**Query the Index**:

---

Expand All @@ -116,11 +116,11 @@ where search(attachmentContent, "Colorado Dallas")

{NOTE: }

__The index__:
**The index**:

---

* Use `loadAttachments()` to be able to index the __details & content__ of ALL attachments.
* Use `loadAttachments()` to be able to index the **details & content** of ALL attachments.

* Note how the index example below is employing the [Fanout index](../../indexes/indexing-nested-data#fanout-index---multiple-index-entries-per-document) pattern.

Expand All @@ -130,7 +130,7 @@ __The index__:

{NOTE: }

__Query the Index__:
**Query the Index**:

---

Expand Down Expand Up @@ -162,7 +162,7 @@ where attachmentSize > 20000 or search(attachmentContent, "Colorado Dallas")

| Parameter | Type | Description |
|--------------|----------|---------------------------------------------------------|
| __document__ | `object` | The document whose attachments details you want to load |
| **document** | `object` | The document whose attachments details you want to load |

{CODE:nodejs syntax_2@documentExtensions\attachments\indexAttachments.js /}

Expand All @@ -172,8 +172,8 @@ where attachmentSize > 20000 or search(attachmentContent, "Colorado Dallas")

| Parameter | Type | Description |
|---------------------|-----------|------------------------------------------------|
| __document__ | `object` | The document whose attachment you want to load |
| __attachmentName__ | `string` | The name of the attachment to load |
| **document** | `object` | The document whose attachment you want to load |
| **attachmentName** | `string` | The name of the attachment to load |

{CODE:nodejs syntax_4@documentExtensions\attachments\indexAttachments.js /}

Expand Down
Loading

0 comments on commit 900961b

Please sign in to comment.