rethinkdb-change-stream
v1.0.1
Published
Transform rethinkdb change feeds into node streams
Downloads
18
Readme
rethinkdb-change-stream
Information
- Turns a RethinkDB change feed into a node stream.
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 deletedata
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
andnext
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
});