|
|
@ -42,22 +42,25 @@ Datastore.prototype.resetIndexes = function (newData) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Ensure an index is kept for this field. Same parameters as lib/indexes |
|
|
|
* Ensure an index is kept for this field. Same parameters as lib/indexes |
|
|
|
* For now this function is synchronous, we need to test how much time it takes |
|
|
|
* For now this function is synchronous, we need to test how much time it takes |
|
|
|
|
|
|
|
* We use an async API for consistency with the rest of the code |
|
|
|
* @param {String} options.fieldName |
|
|
|
* @param {String} options.fieldName |
|
|
|
* @param {Boolean} options.unique |
|
|
|
* @param {Boolean} options.unique |
|
|
|
* @param {Boolean} options.sparse |
|
|
|
* @param {Boolean} options.sparse |
|
|
|
* @return {Boolean} true if index was created or already exists, false otherwise |
|
|
|
* @param {Function} cb Optional callback, signature: err |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Datastore.prototype.ensureIndex = function (options) { |
|
|
|
Datastore.prototype.ensureIndex = function (options, cb) { |
|
|
|
|
|
|
|
var callback = cb || function () {}; |
|
|
|
|
|
|
|
|
|
|
|
options = options || {}; |
|
|
|
options = options || {}; |
|
|
|
|
|
|
|
|
|
|
|
if (!options.fieldName) { return false; } |
|
|
|
if (!options.fieldName) { return callback({ missingFieldName: true }); } |
|
|
|
if (this.indexes[options.fieldName]) { return true; } |
|
|
|
if (this.indexes[options.fieldName]) { return callback(); } |
|
|
|
|
|
|
|
|
|
|
|
options.datastore = this; |
|
|
|
options.datastore = this; |
|
|
|
this.indexes[options.fieldName] = new Index(options); |
|
|
|
this.indexes[options.fieldName] = new Index(options); |
|
|
|
this.indexes[options.fieldName].insert(this.data); |
|
|
|
this.indexes[options.fieldName].insert(this.data); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return callback(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -106,7 +109,7 @@ Datastore.prototype.removeFromIndexes = function (doc) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Update a document in all indexes |
|
|
|
* Update a document in all indexes |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Datastore.prototype.removeFromIndexes = function (doc, newDoc) { |
|
|
|
Datastore.prototype.updateIndexes = function (doc, newDoc) { |
|
|
|
var self = this; |
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
|
|
Object.keys(this.indexes).forEach(function (i) { |
|
|
|
Object.keys(this.indexes).forEach(function (i) { |
|
|
|