nStore - easy database written for node.js in node.js
Ever wanted to fire up a quick node.js app, but didn’t want to mess with finding a database driver that worked with the latest node and then installed and set up that database. Ever wanted the simplicity of an in-process db engine (like sqlite).
Wait no more, nStore is here. It’s written in pure js and is contained in a single js file to include in your node project. It supports full CRUD operations on key based documents.
The data is persisted to disk using a smart append-only format that’s easily recoverable by design. You can update/insert documents by key, read documents by key, remove documents by key… (get the picture, it’s key/value based).
Also you can build a node stream interface from a document collection or query the collection using a filter function and get the results as a single callback.
Removing stale data is easy and efficient too. Just supply a filter function to the automatic data compacter and it will remove the offending documents while compacting the data file. Thus the file is never needlessly bloated with delete lines.
Here is a short example that creates a database, inserts a document, and pulls it back out.
// Load the library
var nStore = require('nstore');
// Create a store
var users = nStore('data/users.db');
// Insert a new document with key "creationix"
users.save("creationix", {name: "Tim Caswell": age: 28}, function (err) {
if (err) { throw err; }
// The save is finished and written to disk safely
});
// Then later pull it back out
users.get("creationix", function (err, doc, meta) {
// do something with the data
})
Try is out as a standalone database, or use it with Connect as a session store. http://github.com/creationix/nstore-session
Discussion
Sign in or Join to comment or subscribe