flatsoup
v1.1.0
Published
event sourcing to a flat file
Downloads
3
Readme
flatsoup
event sourcing (append only log) to a flat file
install
npm install flatsoup
example
var pull = require('pull-stream');
var test = require('tape');
var flatsoup = require('flatsoup');
var database = 'demo';
var table = 'event_bucket';
var demo = new flatsoup(database, table);
demo.clear();
test('add events and listen as pull streams', function (t) {
t.plan(7);
demo.add({demo:true, order: 0}, function () {
t.ok(true, 'add handles callback')
});
demo.add({demo:false, order: 1});
var counter = 0;
var counter_latest = 1;
pull(
demo.pull_all(),
pull.drain(function (item) {
t.ok(item.value.order === counter, 'can pull event');
counter += 1;
})
);
pull(
demo.pull_all_latest(),
pull.drain(function (item) {
t.ok(item.value.order === counter_latest, 'can pull latest event');
counter_latest -= 1;
})
);
demo.get_all(function (results) {
t.ok(results[0].value.order < results[1].value.order, 'can get all with callback');
});
demo.get_all_latest(function (results) {
t.ok(results[0].value.order > results[1].value.order, 'can get latest with callback');
});
pull(
demo.pull_all_latest(),
pull.drain(function (item) {
console.log('[events found]', item)
})
)
});