4.0.0 • Published 4 years ago

sharedb-hooks v4.0.0

Weekly downloads
373
License
MIT
Repository
github
Last release
4 years ago

sharedb-hooks

The way to hook db-interactions on the server

Usage

First you should require the package and init it:

server.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:

  
  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

4.0.0

4 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

8 years ago

2.0.0

9 years ago

1.0.0

9 years ago