collection-sync / Exports / Collection
This interface defines several CRUD methods to operate on a collection. These methods can be implemented by accessing a local database, requesting a restful API (remote DB), etc.
-
↳
Collection
▸ commitSync(itemsToSync, ignoredItems, conflictItems): Promise<boolean>
Commits the sync operation. Database engines that don't support
this should implement a method that returns true (because the
data was already added without the need for a commit statement).
Make sure to commit the data from one specific sync process in order to avoid committing data
pushed by multiple users synchronizing at the same time.
| Name | Type |
|---|---|
itemsToSync |
SyncItem[] |
ignoredItems |
SyncItem[] |
conflictItems |
SyncItem[] |
Promise<boolean>
▸ countAll(): number | Promise<number>
Gets the number of items in the collection.
number | Promise<number>
▸ findByIds(ids): SyncItem[] | Promise<SyncItem[]>
Returns a list of records using an ID list as search query.
| Name | Type |
|---|---|
ids |
DocId[] |
SyncItem[] | Promise<SyncItem[]>
▸ initialize(): Promise<void>
Executes async logic to initialize collection or datastore (open file, create database connection, etc).
Promise<void>
▸ itemsNewerThan(date, limit): SyncItem[] | Promise<SyncItem[]>
Returns a list of items that have updatedAt greater than argument provided.
The list MUST be ordered by updatedAt ASC, otherwise an exception will be thrown (no syncing
will be executed).
| Name | Type |
|---|---|
date |
undefined | Date |
limit |
number |
SyncItem[] | Promise<SyncItem[]>
▸ latestUpdatedItem(): undefined | SyncItem | Promise<undefined | SyncItem>
Gets the highest updateAt date in the collection.
undefined | SyncItem | Promise<undefined | SyncItem>
▸ rollbackSync(itemsToSync, ignoredItems, conflictItems): void | Promise<void>
Rollbacks the current data that's being synchronized. Make sure to rollback the data from one specific sync process in order to avoid discarding data pushed by multiple users synchronizing at the same time.
| Name | Type |
|---|---|
itemsToSync |
SyncItem[] |
ignoredItems |
SyncItem[] |
conflictItems |
SyncItem[] |
void | Promise<void>
▸ syncBatch(items): SyncItem[] | Promise<SyncItem[]>
Syncs (upsert/delete) a batch (list) of items into this collection. Order of document processing doesn't need to be in any particular order.
| Name | Type |
|---|---|
items |
SyncItem[] |