npm install modella-leveldb
var model = require('modella');
var level = require('modella-leveldb')('./mydb');
var uid = require('uid');
var User = model('user')
.attr('id')
.attr('name')
.attr('email')
.attr('password');
User.use(level);
/**
* Initialize
*/
var user = new User;
user.id(uid(6))
.name('matt')
.email('mattmuelle@gmail.com')
.password('test');
user.save(function(err) {
console.log(user.toJSON());
});Initialize leveldb with a path to the database. If path doesn't exist, it will be created. options will be passed through to levelup
Alternatively, you can pass your own level db instance in.
Create a secondary index using leveldex. You may ensure that key is unique by passing unique : true in opts.
User.index('email', { unique: true });Get all models (static method)
Find a model (static method).
If you provide a secondary index, you can search by that key:
Model.find({ email: 'hi@lapwinglabs.com' } , fn);Save the model (instance method)
Remove the model (instance method)
All options will be passed through to levelup.
MIT