DittoSyncKit  1.0.0-alpha1
Public Member Functions | Properties | List of all members
Ditto.SyncKit.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 FindAll ()
 Creates a cursor for all of the documents in this collection. More...
 
DittoPendingIDSpecificOperation FindById (string id)
 Creates an accessor for a single document by its unique identifier. More...
 
unsafe string Insert (Dictionary< string, object > data, string id=null, bool isDefault=false)
 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< DittoAttachmentStatus > onStatusChanged)
 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. More...
 

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 Ditto.SyncKit.DittoCollection.FetchAttachment ( DittoAttachmentToken  token,
Action< DittoAttachmentStatus onStatusChanged 
)
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 status of the attachment as it attempts to download it. Assuming it succeeds in downloading the attachment it wall call the onStatusChanged lambda with a completed status object, which will hold a reference to the attachment.

Parameters
tokenThe DittoAttachmentToken relevant to the attachment that you wish to download and observe.
onStatusChangedA lambda that will be called when the status of the attachment download changes.
Returns
A DittoAttachmentFetcher object, which must be kept alive for the fetch request to proceed and for you to be notified about the attachment's fetch status changes. 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()

DittoPendingCursorOperation Ditto.SyncKit.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.

◆ FindAll()

DittoPendingCursorOperation Ditto.SyncKit.DittoCollection.FindAll ( )
inline

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

Returns
A cursor for all documents in the collection.

◆ FindById()

DittoPendingIDSpecificOperation Ditto.SyncKit.DittoCollection.FindById ( string  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.

◆ Insert()

unsafe string Ditto.SyncKit.DittoCollection.Insert ( Dictionary< string, object >  data,
string  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 DittoSyncKit 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 identifier of the document.

◆ NewAttachment()

unsafe DittoAttachment Ditto.SyncKit.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 DittoSyncKit'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 how you can use the newAttachment functionality to insert an attachment into a document.

if let attachment = collection.insert.newAttachment("/path/to/my/file.pdf") { let docID = try!collection.insert(["attachment": attachment, "other": "string"]) }

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.

Property Documentation

◆ Name

string Ditto.SyncKit.DittoCollection.Name
get

Gets the name of the collection.