https://github.com/toddself/levelsync
A Backbone.Sync replacement using leveldb
https://github.com/toddself/levelsync
Last synced: about 1 year ago
JSON representation
A Backbone.Sync replacement using leveldb
- Host: GitHub
- URL: https://github.com/toddself/levelsync
- Owner: toddself
- License: mit
- Created: 2013-10-14T02:19:06.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-03-06T15:52:42.000Z (over 12 years ago)
- Last Synced: 2025-04-26T12:22:21.131Z (about 1 year ago)
- Language: JavaScript
- Size: 252 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://travis-ci.org/toddself/levelsync)
#LevelSync
LevelSync is a [`Backbone.Model`](http://backbonejs.org/#Model) replacement which uses [LevelDB](http://code.google.com/p/leveldb) via the [levelup](https://github.com/rvagg/node-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`](https://github.com/kriskowal/q) promise will be returned instead.
## License
LevelSync is copyright (c) 2013 Todd Kennedy. Usage is provided under the terms of the [MIT Licence](/LICENSE)