|
|
@ -100,21 +100,6 @@ Datastore.prototype.insert = function (newDoc, cb) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Check whether object is matched by the given query |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Datastore.match = function (obj, query) { |
|
|
|
|
|
|
|
var match = true |
|
|
|
|
|
|
|
, i, k; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(query).forEach(function (k) { |
|
|
|
|
|
|
|
if (obj[k] !== query[k]) { match = false; } |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return match; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Find all documents matching the query |
|
|
|
* Find all documents matching the query |
|
|
|
* @param {Object} query MongoDB-style query |
|
|
|
* @param {Object} query MongoDB-style query |
|
|
@ -126,7 +111,7 @@ Datastore.prototype.find = function (query, callback) { |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < self.data.length; i += 1) { |
|
|
|
for (i = 0; i < self.data.length; i += 1) { |
|
|
|
if (Datastore.match(self.data[i], query)) { |
|
|
|
if (model.match(self.data[i], query)) { |
|
|
|
res.push(model.deepCopy(self.data[i])); |
|
|
|
res.push(model.deepCopy(self.data[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -145,7 +130,7 @@ Datastore.prototype.findOne = function (query, callback) { |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < self.data.length; i += 1) { |
|
|
|
for (i = 0; i < self.data.length; i += 1) { |
|
|
|
if (Datastore.match(self.data[i], query)) { |
|
|
|
if (model.match(self.data[i], query)) { |
|
|
|
return callback(null, model.deepCopy(self.data[i])); |
|
|
|
return callback(null, model.deepCopy(self.data[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -226,7 +211,7 @@ Datastore.prototype.update = function (query, updateQuery, options, cb) { |
|
|
|
, function () { // Perform the update
|
|
|
|
, function () { // Perform the update
|
|
|
|
try { |
|
|
|
try { |
|
|
|
self.data.forEach(function (d) { |
|
|
|
self.data.forEach(function (d) { |
|
|
|
if (Datastore.match(d, query) && (multi || numReplaced === 0)) { |
|
|
|
if (model.match(d, query) && (multi || numReplaced === 0)) { |
|
|
|
numReplaced += 1; |
|
|
|
numReplaced += 1; |
|
|
|
newData.push(model.modify(d, updateQuery)); |
|
|
|
newData.push(model.modify(d, updateQuery)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -267,7 +252,7 @@ Datastore.prototype.remove = function (query, options, cb) { |
|
|
|
multi = options.multi !== undefined ? options.multi : false; |
|
|
|
multi = options.multi !== undefined ? options.multi : false; |
|
|
|
|
|
|
|
|
|
|
|
self.data.forEach(function (d) { |
|
|
|
self.data.forEach(function (d) { |
|
|
|
if (Datastore.match(d, query) && (multi || numRemoved === 0)) { |
|
|
|
if (model.match(d, query) && (multi || numRemoved === 0)) { |
|
|
|
numRemoved += 1; |
|
|
|
numRemoved += 1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
newData.push(d); |
|
|
|
newData.push(d); |
|
|
|