1.0.1 • Published 10 years ago
rethinkdb-change-stream v1.0.1
rethinkdb-change-stream

Information
- Turns a RethinkDB change feed into a node stream.
Install
npm install rethinkdb-change-stream --saveAPI
changeStream(query)
queryargument 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:
typeis either insert, update, or deletedatais an object with two possible fields:prevexists if the type is update or delete- This is the old value that was removed or updated
nextexists if the type is update or insert- This is the new value that was inserted or updated to
- If using thinky, both
prevandnextwill 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
});