0.11.1 • Published 13 years ago
lian v0.11.1
Lian
Simple object persistence for node.js with MongoDB.
var lian = require('lian')('localhost/mydb');
function Person (name) {
lian(this, 'person');
this.name = name;
}
Person.prototype.getGender = function () {
return this.gender;
}
var john = new Person('John Smith');
john.gender = "male";
john.save();Create a projection of Person to find the instance saved above.
var john = new Person('John Smith');
john.find().then(function (results) {
john = results[0];
john.name; // "John Smith"
john.getGender(); // "male"
});Make some changes to persist.
john.name = "John Anthony Smith";
john.save();Decoupled, lian's Store object can be used directly.
var Store = require('lian').Store,
lian = require('lian');
function Person (name) {
lian(this, 'person');
this.name = name;
}
var steve = new Person('steve');
typeof steve.insert // "undefined"
var store = new Store('localhost/mydb');
store.insert(steve);Goals
- Avoid writing result to object mapping code over and over.
- Instance based connections, multiple connections within the same process.
- All asynchronous operations should return a promise.
- Store provides an in-memory alternative, for testing.
Development 
Lian uses monk to talk to MongoDB and promised-io for futures.
Clone the repo...
git clone git://github.com/richardhodgson/lian.gitUse npm to install dependencies.
cd lian && \
npm install --devRun the tests.
make testThe tests mock out monk, there are integration tests expecting a MongoDB instance running on localhost:27017. They will create a lian-integration database.
make integration-test