-
Notifications
You must be signed in to change notification settings - Fork 1
3. API References
Hieu Nguyen (Jack) edited this page Feb 1, 2019
·
2 revisions
In this page:
A list of APIs applied for a ClientDB instance
// Get collection
ClientDB.collect(collectionName: string) : ClientStore;
// Delete the whole database
ClientDB.destroy() : Promise<IResult>;
A list of APIs applied for a ClientStore instance
// Get a record
ClientStore.filter(query: Object) : Promise<IResult>;
// Insert record/s into a collection
ClientStore.insert(record: Array<Object> | Object) : Promise<IResult>;
// Update a record in a collection
ClientStore.update(id: string, changes: Object) : Promise<IResult>;
// Remove record/s ids from a collection
ClientStore.remove(ids: Array<string> | string) : Promise<IResult>;
// Remove all records
ClientStore.removeAllRecords() : Promise<IResult>;
// Get collection
ClientStore.subscribe(
eventName: "insert" | "update" | "remove" | "removeAll",
callback: (eventName: string, changes: { items: Array<Object>, changes: ChangesInterface }) : void);
// Data record interface
type IRecord = { [key: string]: any };
// Error interface, received when an operation failed
type IError = { property: string, message: string };
// Changes interface, received as part of any CRUD operation result
// to signal data changed in the database
type ChangesInterface = {
removed: number,
inserted: number,
unchange: number,
update: number
};
// CRUD result interface, received when performing any CRUD operation
type IResult = {
items: Array<IRecord>,
error?: Array<IError>,
changes?: ChangesInterface
}