JsonStreamDb is a toy Node.js stream database. Or something. Seriously, I have no idea what I'm doing.
var JsonStreamDb = require('jsonstreamdb');
var db = new JsonStreamDb('test.jsonstreamdb');
db.pipe(process.stdout, {history: true});
db.create('users', '47c0479c-2083-4797-8d3c-419de31d45a7', {userName: 'geon'});
db.update('users', '47c0479c-2083-4797-8d3c-419de31d45a7', {favoriteAnimal: 'kittens'});
db.delete('users', '47c0479c-2083-4797-8d3c-419de31d45a7');
Please note that JsonStreamDb inherits stream.PassThrough
. Since it is a stream, the standard stream API applies.
The constructor.
path
- Path to file for persistence. Only one JsonStreamDb instance should ever use it at once.options
- Standard stream options.
JsonStreamDb has an extra option; history
. If set to true
, pipe
will stream the entire database from disk before giving you the "live" updates.
Add a create-event to the db.
topic
- The topic the object belongs to.uuid
- A unique id.data
- The rest of the initial data.
Add an update-event to the db.
topic
- The topic the object belongs to.uuid
- The id of the object.data
- The changed data.
Add a delete-event to the db.
topic
- The topic the object belongs to.uuid
- The id of the object.
Create a JsonStreamDb event. You can add it to a db manually with db.write(myEvent)
.
type
- The update type. One of the strings- 'add' - Create
- 'set' - Update
- 'del' - Delete
topic
- The topic the object belongs to.uuid
- The id of the object.data
- The rest of the data.