underscore-db
Advanced tools
Comparing version 0.9.1 to 0.10.0
{ | ||
"name": "underscore-db", | ||
"main": "dist/underscore-db.js", | ||
"version": "0.8.0", | ||
"version": "0.10.0", | ||
"homepage": "https://github.com/typicode/underscore-db", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -25,3 +25,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
__empty: function(doc) { | ||
this.each(doc, function(value, key) { | ||
this.forEach(doc, function(value, key) { | ||
delete doc[key]; | ||
@@ -33,3 +33,3 @@ }); | ||
__update: function(dest, src) { | ||
this.each(src, function(value, key) { | ||
this.forEach(src, function(value, key) { | ||
dest[key] = value; | ||
@@ -68,3 +68,3 @@ }); | ||
this.__empty(d); | ||
this.extend(d, doc); | ||
this.assign(d, doc); | ||
} else { | ||
@@ -86,3 +86,3 @@ // push new object | ||
if (doc) this.__update(doc, attrs); | ||
if (doc) this.assign(doc, attrs, {id: id}); | ||
@@ -92,8 +92,8 @@ return doc; | ||
updateWhere: function(collection, whereAttrs, attrs) { | ||
updateWhere: function(collection, predicate, attrs) { | ||
var self = this; | ||
var docs = this.where(collection, whereAttrs); | ||
var docs = this.filter(collection, predicate); | ||
docs.forEach(function(doc) { | ||
self.__update(doc, attrs); | ||
self.assign(doc, attrs, {id: doc.id}); | ||
}); | ||
@@ -104,2 +104,13 @@ | ||
replaceById: function(collection, id, attrs) { | ||
var doc = this.getById(collection, id); | ||
if (doc) { | ||
this.__empty(doc); | ||
this.assign(doc, attrs, {id: id}); | ||
} | ||
return doc; | ||
}, | ||
removeById: function(collection, id) { | ||
@@ -113,5 +124,5 @@ var doc = this.getById(collection, id); | ||
removeWhere: function(collection, attrs) { | ||
removeWhere: function(collection, predicate) { | ||
var self = this; | ||
var docs = this.where(collection, attrs); | ||
var docs = this.filter(collection, predicate); | ||
@@ -118,0 +129,0 @@ docs.forEach(function(doc) { |
@@ -1,2 +0,2 @@ | ||
/*! underscore-db 0.9.0 */ | ||
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d=a("./");d.save=function(a,b){b=b||"db",localStorage.setItem(b,JSON.stringify(a,null,2))},d.load=function(a){return a=a||"db",JSON.parse(localStorage.getItem(a))},_.mixin(d)},{"./":2}],2:[function(a,b,c){function d(a,b){for(b=a="";a++<36;b+=51*a&52?(15^a?8^Math.random()*(20^a?16:4):4).toString(16):"-");return b}b.exports={__empty:function(a){this.each(a,function(b,c){delete a[c]})},__update:function(a,b){this.each(b,function(b,c){a[c]=b})},__remove:function(a,b){var c=this.indexOf(a,b);-1!=c&&a.splice(c,1)},__id:function(){var a=this.id||"id";return a},getById:function(a,b){var c=this;return this.find(a,function(a){return a[c.__id()]===b})},createId:function(a,b){return d()},insert:function(a,b){if(b[this.__id()]){var c=this.getById(a,b[this.__id()]);c?(this.__empty(c),this.extend(c,b)):a.push(b)}else b[this.__id()]=this.createId(a,b),a.push(b);return b},updateById:function(a,b,c){var d=this.getById(a,b);return d&&this.__update(d,c),d},updateWhere:function(a,b,c){var d=this,e=this.where(a,b);return e.forEach(function(a){d.__update(a,c)}),e},removeById:function(a,b){var c=this.getById(a,b);return this.__remove(a,c),c},removeWhere:function(a,b){var c=this,d=this.where(a,b);return d.forEach(function(b){c.__remove(a,b)}),d}}},{}]},{},[1]); | ||
/*! underscore-db 0.10.0 */ | ||
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d=a("./");d.save=function(a,b){b=b||"db",localStorage.setItem(b,JSON.stringify(a,null,2))},d.load=function(a){return a=a||"db",JSON.parse(localStorage.getItem(a))},_.mixin(d)},{"./":2}],2:[function(a,b,c){function d(a,b){for(b=a="";a++<36;b+=51*a&52?(15^a?8^Math.random()*(20^a?16:4):4).toString(16):"-");return b}b.exports={__empty:function(a){this.forEach(a,function(b,c){delete a[c]})},__update:function(a,b){this.forEach(b,function(b,c){a[c]=b})},__remove:function(a,b){var c=this.indexOf(a,b);-1!=c&&a.splice(c,1)},__id:function(){var a=this.id||"id";return a},getById:function(a,b){var c=this;return this.find(a,function(a){return a[c.__id()]===b})},createId:function(a,b){return d()},insert:function(a,b){if(b[this.__id()]){var c=this.getById(a,b[this.__id()]);c?(this.__empty(c),this.assign(c,b)):a.push(b)}else b[this.__id()]=this.createId(a,b),a.push(b);return b},updateById:function(a,b,c){var d=this.getById(a,b);return d&&this.assign(d,c,{id:b}),d},updateWhere:function(a,b,c){var d=this,e=this.filter(a,b);return e.forEach(function(a){d.assign(a,c,{id:a.id})}),e},replaceById:function(a,b,c){var d=this.getById(a,b);return d&&(this.__empty(d),this.assign(d,c,{id:b})),d},removeById:function(a,b){var c=this.getById(a,b);return this.__remove(a,c),c},removeWhere:function(a,b){var c=this,d=this.filter(a,b);return d.forEach(function(b){c.__remove(a,b)}),d}}},{}]},{},[1]); |
{ | ||
"name": "underscore-db", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"description": "Use JavaScript objects as databases", | ||
@@ -8,3 +8,3 @@ "main": "src/node.js", | ||
"test": "grunt test", | ||
"grunt": "grunt" | ||
"prepublish": "grunt" | ||
}, | ||
@@ -37,3 +37,3 @@ "author": "Typicode <typicode@gmail.com>", | ||
"grunt-mocha-test": "~0.7.0", | ||
"lodash": "^3.9.3", | ||
"lodash": "^4.6.1", | ||
"sinon": "~1.8.1", | ||
@@ -40,0 +40,0 @@ "underscore": "^1.8.3" |
@@ -1,2 +0,2 @@ | ||
# underscore-db [![Build Status](https://travis-ci.org/typicode/underscore-db.svg)](https://travis-ci.org/typicode/underscore-db) [![NPM version](https://badge.fury.io/js/underscore-db.svg)](http://badge.fury.io/js/underscore-db) [![Bower version](https://badge.fury.io/bo/underscore-db.svg)](http://badge.fury.io/bo/underscore-db) | ||
# underscore-db [![Build Status](https://travis-ci.org/typicode/underscore-db.svg)](https://travis-ci.org/typicode/underscore-db) [![NPM version](https://badge.fury.io/js/underscore-db.svg)](http://badge.fury.io/js/underscore-db) | ||
@@ -3,0 +3,0 @@ > Adds functions to Underscore/Lo-Dash for manipulating database-like objects. |
@@ -73,5 +73,5 @@ // UUID | ||
updateWhere: function(collection, whereAttrs, attrs) { | ||
updateWhere: function(collection, predicate, attrs) { | ||
var self = this; | ||
var docs = this.where(collection, whereAttrs); | ||
var docs = this.filter(collection, predicate); | ||
@@ -104,5 +104,5 @@ docs.forEach(function(doc) { | ||
removeWhere: function(collection, attrs) { | ||
removeWhere: function(collection, predicate) { | ||
var self = this; | ||
var docs = this.where(collection, attrs); | ||
var docs = this.filter(collection, predicate); | ||
@@ -109,0 +109,0 @@ docs.forEach(function(doc) { |
17508
287