Alfred.js is a fast in-process key-value store for node.js.
Note that Alfred.js is still very young, so you shouldn't use it on live systems just yet.
What does it do?
Alfred supports:
- ODM (Object Document Model)
- multiple key-value maps in one database
- atomic operations on one record
- finder streams
- activity streams
- append-only files
- compactation
- buffered and unbuffered writes
- in-memory indexes
- sorting
- replication
- integrity checks
How can I install Alfred.js?
Install via npm:
$ npm install alfred
Examples:
Using the ODM:
var Alfred = require('alfred');
// Open database
Alfred.open('path/to/db', function(err, db) {
if (err) { throw err; }
// define User model and its properties
var User = db.define('User', {
indexes: [{name: 'age',
fn: function(user) { return user.age; }]
});
User.property('name', 'string', {
maxLength: 100
});
User.property('active', 'boolean');
// get user by id
User.get(id, function(user) {
console.log(user.inspect());
};
// find users
User.find({age: {$gt: 18}}).all(function(users) {
console.log('Found ' + users.length + ' users with more than 18 years') ;
});
});
Raw:
var Alfred = require('alfred');
// Open database
Alfred.open('path/to/db', function(err, db) {
if (err) { throw err; }
// find and log all users with age > 25 and <= 40
db.users.find({age: {$gt : 25, $lte: 40}}) (function(err, user) {
if (err) { throw err; }
console.log(user);
});
});
See the Examples page or the API.
How does it work?
Alfred.js stores data on append-only files, which is good for maintaining a consistent state (even when the writes are interrupted).
Writes are fast because many writes can occurr in parallel.
Reads are fast because indexes into files are kept in memory.
Alfred.js is generally fast also because you don't have any inter-process communication overhead.
Alfred.js lets you (optionally) use the power of javascript to filter your data set.