New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

backbone-db

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-db - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

41

lib/db.js

@@ -104,8 +104,25 @@ var Backbone = require('backbone');

}
function store(model) {
var key = self._getKey(model, options);
self.store().setItem(key, JSON.stringify(model), function(err, res) {
self.records.push(model.get(model.idAttribute));
self.save(function() {});
return cb(err, model.toJSON(), res);
if(model.collection) {
var colKey = self._getKey(model.collection, options);
self.store().getItem(colKey, function(err, res) {
res = res && JSON.parse(res);
res = res || [];
res.push(model.get(model.idAttribute));
self.store().setItem(colKey, JSON.stringify(res), function(err) {
self.records.push(model.get(model.idAttribute));
self.save(function(err) {
return cb(err, model.toJSON(), res);
});
});
});
} else {
self.records.push(model.get(model.idAttribute));
self.save(function(err) {
return cb(err, model.toJSON(), res);
});
}
});

@@ -130,10 +147,18 @@ }

}
data = data && JSON.parse(data);
if(!Array.isArray(data) || data.length == 0) {
return cb(null, data || []);
}
var done = _.after(data.length, function(m) {
return cb(null,m);
});
data = data && JSON.parse(data);
data = data.map(function(id) {
data = self.store().getItem(self.name+':'+id, function(err, data) {
return JSON.parse(data);
data.forEach(function(id) {
var m = new model.model({id:id});
var key = self._getKey(m, options);
self.store().getItem(key, function(err, data) {
data = data && JSON.parse(data);
done(data);
});
});
return(err, data);
});

@@ -140,0 +165,0 @@ },

2

package.json
{
"name": "backbone-db",
"version": "0.0.4",
"version": "0.0.5",
"description": "Key-Value database storage interface, localStorage and in-process implementations",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -40,5 +40,13 @@ var Db = require('../');

var m = new MyCollection();
assert(m.length === 0);
m.create({"test":1},{success: function(model) {
assert(model.get("test") === 1);
t();
m.fetch({success: function() {
assert(m.length === 1);
t();
}, error: function(err){
assert(err);
}});
}, error: function(err) {

@@ -45,0 +53,0 @@ assert(err)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc