rethinkdb-stream
1.0.1 • Public • Published rethinkdb-stream
Convert a rethinkdb cursor into a readable stream (object mode stream)
Installation
npm i --save rethinkdb-stream
Usage
Changes Cursor Example:
var r = require('rethinkdb')
var conn = r.connect({})
var rethinkdbStream = require('rethinkdb-stream')
r.table('foo').changes().run(conn)
.then(function (cursor) {
var stream = rethinkdbStream(cursor)
stream.on('error', )
stream.pipe()
})
.then(function () {
return r.table('foo').insert({ id: 1 }).run(conn)
})
.then(function () {
return r.table('foo').insert({ id: 2 }).run(conn)
})
.then(function () {
return r.table('foo').insert({ id: 3 }).run(conn)
})
Query Cursor Example:
var r = require('rethinkdb')
var conn = r.connect({})
var rethinkdbStream = require('rethinkdb-stream')
var rows = [
{ id: 1 },
{ id: 2 },
{ id: 3 }
]
r.table('foo').insert(rows).run(conn).then(function () {
return r.table('foo').run(conn).then(function (cursor) {
var stream = rethinkdbStream(cursor)
stream.on('error', )
stream.pipe()
})
})
Close Example:
rethinkdb streams have a close
method which calls cursor.close()
var r = require('rethinkdb')
var conn = r.connect({})
var rethinkdbStream = require('rethinkdb-stream')
r.table('foo').changes().run(conn)
.then(function (cursor) {
var stream = rethinkdbStream(cursor)
stream.on('error', )
stream.pipe()
return stream.close()
})
.then(function () {
return r.table('foo').insert({ id: 1 }).run(conn)
})
.then(function () {
return r.table('foo').insert({ id: 2 }).run(conn)
})
.then(function () {
return r.table('foo').insert({ id: 3 }).run(conn)
})
License
MIT
Package Sidebar
Install
Weekly Downloads