backbone-db
Advanced tools
Comparing version 0.4.9 to 0.4.11
@@ -37,2 +37,3 @@ var Backbone = require('backbone'); | ||
function sort(property) { | ||
debug('sorting by %s',property||''); | ||
var sortOrder = 1; | ||
@@ -51,3 +52,3 @@ if (property[0] === '-') { | ||
if (!filterOptions.where) return callback(null, models); | ||
debug('filtering results: %s', JSON.stringify(filterOptions)); | ||
var filteredModels = []; | ||
@@ -129,3 +130,3 @@ var jq = jsonquery(filterOptions.where); | ||
self.save(function (err) { | ||
return cb(err, model.toJSON(), res); | ||
return cb(err, model.toJSON(options), res); | ||
}); | ||
@@ -226,8 +227,14 @@ }); | ||
} | ||
this.store().setItem(getKey(model), JSON.stringify(model), function (err, res) { | ||
// if models created with id. | ||
if (self.records.indexOf(getKey(model)) === -1) { | ||
self.records.push(getKey(model)); | ||
} | ||
cb(err, model.toJSON(), res); | ||
var id = getKey(model); | ||
this.store().getItem(id, function(err, data) { | ||
data = data || '{}'; | ||
data = JSON.parse(data); | ||
_.merge(data, model.toJSON(options)); | ||
self.store().setItem(id, JSON.stringify(data), function (err, res) { | ||
// if models created with id. | ||
if (self.records.indexOf(getKey(model)) === -1) { | ||
self.records.push(getKey(model)); | ||
} | ||
cb(err, model.toJSON(options), res); | ||
}); | ||
}); | ||
@@ -234,0 +241,0 @@ }, |
{ | ||
"name": "backbone-db", | ||
"version": "0.4.9", | ||
"version": "0.4.11", | ||
"description": "Key-Value database storage interface, localStorage and in-process implementations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,5 +6,5 @@ /** | ||
exports.shouldImplementDb = function (done) { | ||
var d = _.after(2, done); | ||
require('./test.model.js')(d); | ||
require('./test.collection.js')(d); | ||
require('./test.model.js')(function() { | ||
require('./test.collection.js')(done); | ||
}); | ||
}; |
@@ -30,3 +30,2 @@ var Db = require('../'); | ||
describe('Model', function () { | ||
require('./test.model.js')(); | ||
after(function () { | ||
@@ -37,6 +36,6 @@ this.db = new Db('mymodels'); | ||
}); | ||
require('./test.model.js')(); | ||
}); | ||
describe('Collection', function () { | ||
require('./test.collection.js')(); | ||
after(function () { | ||
@@ -47,3 +46,4 @@ this.db = new Db('mymodels'); | ||
}); | ||
require('./test.collection.js')(); | ||
}); | ||
}); |
@@ -47,2 +47,27 @@ var assert = require('assert'); | ||
it('should allow updating model', function (t) { | ||
var Model = this.Model; | ||
m.save({ | ||
update: 'test' | ||
}, { | ||
success: function () { | ||
var m2 = new Model({ | ||
id: m.id | ||
}); | ||
m2.fetch({ | ||
success: function () { | ||
assert.equal(m2.get('update'), 'test'); | ||
assert.equal(m2.get('counter'), 1); | ||
t(); | ||
}, | ||
error: function (model, err) { | ||
console.error(err); | ||
assert.ok(false); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
it('should inc Model counter', function (t) { | ||
@@ -49,0 +74,0 @@ var m2 = new this.Model({ |
Sorry, the diff of this file is not supported yet
162086
890