#LevelSync
LevelSync is a Backbone.Model
replacement which uses LevelDB via the levelup interface.
npm install --save levelsync
var levelup = require('level');
var db = levelup('./path/to/db');
var Backbone = require('backbone');
Backbone.sync = require('levelsync')(db);
var StatBlock = Backbone.Model.extend({
defaults: {
'str': 8,
'con': 8,
'wis': 8,
'dex': 8,
'int': 8,
'chr': 8
}
});
var myCharacter = new StatBlock();
myCharacter.set('str', 18);
myCharacter.set('name', 'LEROY JENKINS');
myCharacter.save(myCharacter.toJSON(), {cb: function(err){
if(!err) console.log(myCharacter.get('name'), 'was saved');
}});
// or
var promise = myCharacter.save();
promise.when(function(){
console.log(myCharacter.get('name'), 'was saved');
});
The options
hash accepts a new parameter, cb
. This callback will be use for all the level operations if set. It's signature should be (err, data)
. If this is not set, a q
promise will be returned instead.
LevelSync is copyright (c) 2013 Todd Kennedy. Usage is provided under the terms of the MIT Licence