Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derbyparty/sharedb-hooks
ShareDb hooks
https://github.com/derbyparty/sharedb-hooks
Last synced: 3 months ago
JSON representation
ShareDb hooks
- Host: GitHub
- URL: https://github.com/derbyparty/sharedb-hooks
- Owner: derbyparty
- Created: 2014-05-20T15:39:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-05-07T10:10:07.000Z (over 3 years ago)
- Last Synced: 2024-05-18T22:33:32.648Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 8
- Watchers: 9
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-derby - derby-hook - Derby store hook (Information)
README
## sharedb-hooks
The way to hook db-interactions on the server
### Usage
First you should require the package and init it:
server.js
```js
// Add 'hook' and 'onQuery' functions to the backend
require('sharedb-hooks')(backend);
// ...
```then you can use the function to hook model events, for example:
```js
backend.hook('create', 'todos', function(docId, value, session, backend) {
model = backend.createModel();
model.fetch ('todos.'+docId, function(err){
var time = +new Date();
model.set('todos.'+docId+'.ctime', time);
})
});
backend.hook('change', 'users.*.location', function(docId, value, op, session, backend){
model = backend.createModel()
console.log('User change location HOOK');
// ....
});
backend.hook('del', 'todos', function(docId, value, session, backend) {
model = backend.createModel();
// ....
});
```## MIT License 2016