@lgslabs/bits-pouch-crud v2.2.4
BITS PouchDB CRUD
The PouchDB-backed implementation of CRUD for BITS. This package extends the functionality provided in bits-memory-crud. All items in the collection are expected to be properly-formatted JSON objects with at least an id field.
Use
Importing
npm install @lgslabs/bits-pouch-crudconst {PouchDbCrudService, PouchDbCrudManager, PouchDbCrudMessenger, PouchDbCrudApi, PouchDbCrudRouter} = require('@lgslabs/bits-pouch-crud');Service
The Service is responsible for creating, loading, and unloading the manager, messenger, router (if desired), a public API (if desired), and any resources the subsystem may need.
createManager
Called in the Service's load function to create the manager. By default, it creates an instance of the base implementation of the PouchDB-backed CRUD manager. If the subsystem needs additional functionality, it is recommended to override this function.
createManager()- Returns Promise resolving to request or rejecting to error
Manager
The Manager is responsible for performing any operations related to the subsystem. It has default implementations for all CRUD operations. The manager is an EventEmitter to allow communication with the Messenger. To change the Manager class being used, override the createManager function in the Service to create and return the desired Manager implementation. The loadManager and unloadManager functions can be overridden in the event more customization is required.
_upsertDiff
Helper function which applies the update to the record.
NOTE: this function MUST be synchronous and return the record which will be put into the DB.
_upsertDiff(newItem, oldItem)newItemObject the item to upsertoldItemObject the existing record, or an empty Object if no matching record exists- Returns Promise resolving to an object, or rejecting to error