From b9e9e4cc38c9e3a4a21fa455ad2b1a48d5bed1b0 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Sun, 29 Sep 2013 16:58:02 +0200 Subject: [PATCH] In progress --- lib/datastore.js | 3 ++- lib/indexes.js | 2 ++ test/indexes.test.js | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/datastore.js b/lib/datastore.js index 6d0ed4a..5b0acee 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -489,10 +489,11 @@ Datastore.prototype.remove = function () { this.executor.push({ this: this, fn: this._remove, arguments: arguments }); }; + /* var db = new Datastore({ inMemoryOnly: true }) -//db.ensureIndex({ fieldName: 'tag' }); +db.ensureIndex({ fieldName: 'tag' }); db.insert({ tag: ['a', 'b', 'c'] }, function () { db.find({ tag: 'b' }, function (err, item) { diff --git a/lib/indexes.js b/lib/indexes.js index b7766ab..f69e4b9 100644 --- a/lib/indexes.js +++ b/lib/indexes.js @@ -14,6 +14,8 @@ function checkValueEquality (a, b) { /** * Create a new index + * All methods on an index guarantee that either the whole operation was successful and the index changed + * or the operation was unsuccessful and an error is thrown while the index is unchanged * @param {String} options.fieldName On which field should the index apply (can use dot notation to index on sub fields) * @param {Boolean} options.unique Optional, enforce a unique constraint (default: false) * @param {Boolean} options.sparse Optional, allow a sparse index (we can have documents for which fieldName is undefined) (default: false) diff --git a/test/indexes.test.js b/test/indexes.test.js index 0fc88e9..9a1ac1f 100644 --- a/test/indexes.test.js +++ b/test/indexes.test.js @@ -120,6 +120,19 @@ describe('Indexes', function () { assert.deepEqual(idx.tree.search('world'), []); assert.deepEqual(idx.tree.search('bloup'), []); }); + + describe.only('Array fields', function () { + + it('Inserts one entry per unique array element in the index', function () { + var obj = { arr: [], really: 'yeah' } + , idx = new Index({ fieldName: 'tf' }) + ; + + idx.insert(obj); + + }); + + }); // ==== End of 'Array fields' ==== // }); // ==== End of 'Insertion' ==== //