levelsync

0.3.0 • Public • Published

build status

LevelSync

LevelSync is a Backbone.Model replacement which uses LevelDB via the levelup interface.

Installation

npm install --save levelsync

Usage

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');
});

Changes from Backbone

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.

License

LevelSync is copyright (c) 2013 Todd Kennedy. Usage is provided under the terms of the MIT Licence

Dependencies (3)

Dev Dependencies (3)

Package Sidebar

Install

npm i levelsync

Weekly Downloads

1

Version

0.3.0

License

MIT

Last publish

Collaborators

  • toddself