-
-
Notifications
You must be signed in to change notification settings - Fork 668
Table.hook('reading')
db.[tableName].hook('reading', function (obj) {
// You may return another object or modify existing object.
});
obj | Object that is about to be returned from database to caller |
The subscriber must return the resulting object. If not modifying the object, subscriber must return the given obj instance. If modifying or replacing object, return the new object or modified existing object.
This event is called whenever an object is about to be returned from database to the caller of Table.get() or any Collection method that results in a query execution.
If subscriber throws an exception, the read operation will fail and the caller of the read operation will get the failure as a Promise rejection that may be catched/handled or not. If the caller of the read operation does not catch the excetion using Promise.catch(), the transaction will be aborted.
Dexie CRUD events can be used to implement several addons to Dexie such as:
- Server Synchronization
- Automatic primary key generation
- Full-text search or other custom ways of indexing properties
- Manipulation of returned objects
The add-on Dexie.Syncable.js uses hook('creating')
, hook('updating')
and hook('deleting')
to make the database locally observable as well as syncable with a remote server.
The hook('reading')
is used internally by Dexie.js by the methods Table.defineClass() and Table.mapToClass() in order to make all objects retrieved from database inherit a given class using prototypal inheritance.
Dexie.js - minimalistic and bullet proof indexedDB library