Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sharedb-hooks

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sharedb-hooks

ShareDb hooks

  • 3.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
352
decreased by-38.57%
Maintainers
3
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 05 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc