rethinkdb-change-stream

1.0.1 • Public • Published

rethinkdb-change-stream NPM version Downloads

Information

Install

npm install rethinkdb-change-stream --save

API

changeStream(query)

  • query argument is a rethinkdb query object
    • This can be from thinky, rethinkdb, or rethinkdbdash
  • Returns a node.js Readable Stream
    • This stream can be piped anywhere you want, including http
    • Ending the stream will also end and clean up the change feed
    • If the change feed encounters an error, the stream will end
  • Readable stream emits data events with two attributes:
    • type is either insert, update, or delete
    • data is an object with two possible fields:
      • prev exists if the type is update or delete
        • This is the old value that was removed or updated
      • next exists if the type is update or insert
        • This is the new value that was inserted or updated to
      • If using thinky, both prev and next will be instances of their Model class

Example (using thinky)

ES6

import changeStream from 'rethinkdb-change-stream'
import User from 'models/User'
 
// tail all 18 year olds named "Eric"
var query = User.filter({
  first_name: 'Eric',
  age: 18
}).changes()
 
var stream = changeStream(query)
stream.on('data', () => {
  // obj.type === insert, update, or delete
  // obj.data === object with prev and next objects
})

ES5

var changeStream = require('rethinkdb-change-stream');
var User = require('models/User');
 
// tail all 18 year olds named "Eric"
var query = User.filter({
  first_name: 'Eric',
  age: 18
}).changes();
 
var stream = changeStream(query);
stream.on('data', function(obj){
  // obj.type === insert, update, or delete
  // obj.data === object with prev and next objects
});

Package Sidebar

Install

npm i rethinkdb-change-stream

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • fractal
  • yocontra