|
|
|
@ -65,6 +65,30 @@ Datastore.prototype.addToIndexes = function (doc) { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Remove one or several document(s) from all indexes |
|
|
|
|
*/ |
|
|
|
|
Datastore.prototype.removeFromIndexes = function (doc) { |
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
Object.keys(this.indexes).forEach(function (i) { |
|
|
|
|
self.indexes[i].remove(doc); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update a document in all indexes |
|
|
|
|
*/ |
|
|
|
|
Datastore.prototype.removeFromIndexes = function (doc, newDoc) { |
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
Object.keys(this.indexes).forEach(function (i) { |
|
|
|
|
self.indexes[i].update(doc, newDoc); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the list of candidates for a given query |
|
|
|
|
* Very crude implementation for now, we return the candidates given by the first usable index if any |
|
|
|
@ -254,13 +278,14 @@ Datastore.prototype.find = function (query, callback) { |
|
|
|
|
*/ |
|
|
|
|
Datastore.prototype.findOne = function (query, callback) { |
|
|
|
|
var self = this |
|
|
|
|
, candidates = this.getCandidates(query) |
|
|
|
|
, i |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
for (i = 0; i < self.data.length; i += 1) { |
|
|
|
|
if (model.match(self.data[i], query)) { |
|
|
|
|
return callback(null, model.deepCopy(self.data[i])); |
|
|
|
|
for (i = 0; i < candidates.length; i += 1) { |
|
|
|
|
if (model.match(candidates[i], query)) { |
|
|
|
|
return callback(null, model.deepCopy(candidates[i])); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|