Ditto 1.1.9-alpha1
Public Member Functions | Properties | List of all members
DittoSDK.DittoCollection Class Reference

A reference to a collection in a DittoStore. More...

Public Member Functions

DittoPendingCursorOperation Find (string query)
 Creates a cursor for the documents in this collection that match the provided query. More...
 
DittoPendingCursorOperation Find (string query, Dictionary< string, object > queryArgs)
 Creates a cursor for the documents in this collection that match the provided query, with any placeholders replaced by the relevant provided query arguments. More...
 
DittoPendingCursorOperation FindAll ()
 Creates a cursor for all of the documents in this collection. More...
 
DittoPendingIDSpecificOperation FindById (DittoDocumentID id)
 Creates an accessor for a single document by its unique identifier. More...
 
DittoPendingIDSpecificOperation FindById (object id)
 Creates a pending operation for a single document based on its unique identifier. More...
 
unsafe DittoDocumentID Upsert (Dictionary< string, object > data, DittoWriteStrategy writeStrategy=DittoWriteStrategy.Merge)
 Inserts a new document into the collection and returns its ID. If the document already exists, the behavior is determined by the given writeStrategy. More...
 
DittoDocumentID Insert (Dictionary< string, object > data, DittoDocumentID id=null, bool isDefault=false)
 Inserts a document into a collection. More...
 
unsafe DittoDocumentID InsertWithStrategy (Dictionary< string, object > data, DittoDocumentID id=null, DittoWriteStrategy writeStrategy=DittoWriteStrategy.Overwrite)
 Inserts a document into a collection. More...
 
unsafe DittoAttachment NewAttachment (string path, Dictionary< string, string > metadata=null)
 Creates a new attachment, which can then be inserted into a document. More...
 
DittoAttachmentFetcher FetchAttachment (DittoAttachmentToken token, Action< DittoAttachmentFetchEvent > onFetchEvent)
 Trigger an attachment to be downloaded locally to the device and observe its progress as it does so. More...
 

Properties

string Name [get]
 Gets the name of the collection.
 

Detailed Description

A reference to a collection in a DittoStore.

This is the entrypoint for inserting documents into a collection, as well querying a collection.

Member Function Documentation

◆ FetchAttachment()

DittoAttachmentFetcher DittoSDK.DittoCollection.FetchAttachment ( DittoAttachmentToken  token,
Action< DittoAttachmentFetchEvent onFetchEvent 
)
inline

Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.

When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report changes to the attachment's fetch attempt as it tries to download it. Assuming it succeeds in downloading the attachment it will call the onFetchEvent lambda with a completed event object, which will hold a reference to the attachment.

Parameters
tokenThe DittoAttachmentToken relevant to the attachment that you wish to download and observe.
onFetchEventA lambda that will be called when the attachment fetch attempt has a new event to deliver.
Returns
A DittoAttachmentFetcher object, which must be kept alive for the fetch request to proceed and for you to be notified about the attachment fetch attempt's events. If the attachment fetcher could not be created then null will be returned. This can happen if, for example, an invalid attachment token was provided.

◆ Find() [1/2]

DittoPendingCursorOperation DittoSDK.DittoCollection.Find ( string  query)
inline

Creates a cursor for the documents in this collection that match the provided query.

Parameters
queryA ditto query string.
Returns
A cursor for the query.

◆ Find() [2/2]

DittoPendingCursorOperation DittoSDK.DittoCollection.Find ( string  query,
Dictionary< string, object >  queryArgs 
)
inline

Creates a cursor for the documents in this collection that match the provided query, with any placeholders replaced by the relevant provided query arguments.

This is the recommended method to use when performing queries on a collection if you have any dynamic data included in the query string. It allows you to provide a query string with placeholders, in the form of $args.my_arg_name, along with an accompanying dictionary of arguments, in the form of { "my_arg_name": "some value" }, and the placeholders will be appropriately replaced by the matching provided arguments from the dictionary. This includes handling things like wrapping strings in quotation marks and arrays in square brackets, for example.

Parameters
queryA ditto query string.
queryArgsThe arguments to use to replace placeholders in the provided query.
Returns
A cursor for the query.

◆ FindAll()

DittoPendingCursorOperation DittoSDK.DittoCollection.FindAll ( )
inline

Creates a cursor for all of the documents in this collection.

Returns
A cursor for all documents in the collection.

◆ FindById() [1/2]

DittoPendingIDSpecificOperation DittoSDK.DittoCollection.FindById ( DittoDocumentID  id)
inline

Creates an accessor for a single document by its unique identifier.

Parameters
idThe id of the document in this collection.
Returns
A cursor for a single document.

◆ FindById() [2/2]

DittoPendingIDSpecificOperation DittoSDK.DittoCollection.FindById ( object  id)
inline

Creates a pending operation for a single document based on its unique identifier.

Parameters
idThe id of the document in this collection.
Returns
A cursor for a single document.

◆ Insert()

DittoDocumentID DittoSDK.DittoCollection.Insert ( Dictionary< string, object >  data,
DittoDocumentID  id = null,
bool  isDefault = false 
)
inline

Inserts a document into a collection.

Parameters
dataThe document content.
idThe primary key or identifier for this document. If this is null then Ditto will assign it a unique identifier. This cannot be changed once inserted.
isDefaultSet to true if the document should assume all values are default. See https://docs.ditto.live/concepts/data-model.
Returns
The unique document ID or null if the document could not be inserted.

◆ InsertWithStrategy()

unsafe DittoDocumentID DittoSDK.DittoCollection.InsertWithStrategy ( Dictionary< string, object >  data,
DittoDocumentID  id = null,
DittoWriteStrategy  writeStrategy = DittoWriteStrategy.Overwrite 
)
inline

Inserts a document into a collection.

Parameters
dataThe document content.
idThe primary key or identifier for this document. If this is null then Ditto will assign it a unique identifier. This cannot be changed once inserted.
writeStrategySpecifies the desired strategy for inserting a document. The default value is DittoWriteStrategy.Overwrite.
Returns
The unique document ID or null if the document could not be inserted.

◆ NewAttachment()

unsafe DittoAttachment DittoSDK.DittoCollection.NewAttachment ( string  path,
Dictionary< string, string >  metadata = null 
)
inline

Creates a new attachment, which can then be inserted into a document.

The file residing at the provided path will be copied into Ditto's store. The DittoAttachment object that is returned is what you can then use to insert an attachment into a document.

You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment.

Below is a snippet to show how you can use the NewAttachment functionality to insert an attachment into a document.

var attachment = coll.NewAttachment("/path/to/my/file.pdf", metadata);

var docId = coll.Insert(new Dictionary<string, object> { { "other", "string" }, { "attachment", attachment } });

Parameters
pathThe path to the file that you want to create an attachment with.
metadataMetadata relating to the attachment.
Returns
A DittoAttachment object, which can be used to insert the attachment into a document.

◆ Upsert()

unsafe DittoDocumentID DittoSDK.DittoCollection.Upsert ( Dictionary< string, object >  data,
DittoWriteStrategy  writeStrategy = DittoWriteStrategy.Merge 
)
inline

Inserts a new document into the collection and returns its ID. If the document already exists, the behavior is determined by the given writeStrategy.

Parameters
dataThe document content.
writeStrategySpecifies the desired strategy for inserting a document. The default value is DittoWriteStrategy.Merge.
Returns
The unique document ID or null if the document could not be inserted.