turtlesoup
v1.0.6
Published
event sourcing helper for rethinkDB
Downloads
3
Maintainers
Readme
turtlesoup
Minimal Event Sourcing helper for RethinkDB & node.js
install
npm install turtlesoup --save
usage
/*
// first create a db and table
var r = require('rethinkdb');
r.connect(function (err, conn) {
r.create('demo').tableCreate('bucket').run(conn, function (){});
});
*/
var _turtlesoup = require('turtlesoup');
var turtlesoup = new _turtlesoup('demo', 'bucket'
setInterval(function () {
turtlesoup.add({ demo: Math.random() * 11, timestamp: new Date() });
}, 1000);
pull(
turtlesoup.get_all_latest(),
pull.log()
)
methods
add
turtlesoup.add({ demo: true, timestamp: new Date().toISOString() });
Add a new JSON object with mandatory timestamp field which needs to be a Javascript Date object.
get_all
turtlesoup.get_all(function (results) {
console.log(results);
});
// or
turtlesoup.get_latest(function({ demo: true }, function (results) {
console.log(results, 'filtered on demo property');
});
Returns an array of all items in the table.
get_all_latest
turtlesoup.get_all_latest(function (results) {
console.log(results);
});
// or
turtlesoup.get_all_latest(function({ demo: true }, function (results) {
console.log(results, 'filtered on demo property');
});
Returns an array of all the items in the table with the latest first.
pull_all
pull(
turtlesoup.pull_all(),
pull.log()
)
// or
turtlesoup.pull_all({ demo: true }) // filter on demo === true
Get each data item from a pull stream source.
pull_all_latest
pull(
turtlesoup.pull_all_latest(),
pull.log()
)
//
turtlesoup.pull_all_latest({ demo: true }) // filter on demo === true
Get each item from a pull stream source with the latest coming first.