Permalink
Browse files

Update nStore to use the renamed Pattern lib.

  • Loading branch information...
1 parent d5035a5 commit 7f74bfa247afdc10afc7dee9fedc99028eeae530 @creationix committed Aug 24, 2010
Showing with 19 additions and 18 deletions.
  1. +1 −1 lib/file.js
  2. +7 −6 lib/nstore.js
  3. +11 −11 test/findTest.js
View
@@ -1,5 +1,5 @@
var fs = require('fs'),
- Queue = require('queue');
+ Queue = require('pattern/queue');
// Reads from a given file descriptor at a specified position and length
// Handles all OS level chunking for you.
View
@@ -1,16 +1,16 @@
var Path = require('path'),
fs = require('fs'),
Step = require('step'),
- Class = require('class'),
- Hash = require('hash'),
- Queue = require('queue'),
+ Pattern = require('pattern'),
+ Hash = require('pattern/hash'),
+ Queue = require('pattern/queue'),
File = require('./file');
const CHUNK_LENGTH = 40 * 1024,
TAB = 9,
NEWLINE = 10;
-var nStore = module.exports = Class.extend({
+var nStore = module.exports = Pattern.extend({
// Set up out local properties on the object
// and load the datafile.
@@ -26,6 +26,7 @@ var nStore = module.exports = Class.extend({
this.busy = false;
this.filterFn = null;
this.loadDatabase(callback);
+ Object.seal(this);
},
get length() {
@@ -217,7 +218,7 @@ var nStore = module.exports = Class.extend({
// New data for the disk index
updates[key] = {
- offset: offset + keyLength + 1,
+ position: offset + keyLength + 1,
length: docLength
};
@@ -329,4 +330,4 @@ var nStore = module.exports = Class.extend({
},
});
-
+Object.freeze(nStore);
View
@@ -2,7 +2,7 @@ require('./helper');
// Enable the cache plugin
// (that only caches some of the values to test the cache miss)
-nStore = nStore.extend(require('nstore/cache')(150));
+nStore = nStore.extend(require('nstore/cache')(1900));
// Enable the query plugin
nStore = nStore.extend(require('nstore/query')());
@@ -11,19 +11,19 @@ var queries = [
[{"age =": 50}, 2],
[{"age <": 50}, 100],
[{"age <=": 50}, 102],
- [{"age >=": 50}, 100],
- [{"age >": 50}, 98],
- [{"age !=": 50}, 198],
- [{"age <>": 50}, 198],
+ [{"age >=": 50}, 1900],
+ [{"age >": 50}, 1898],
+ [{"age !=": 50}, 1998],
+ [{"age <>": 50}, 1998],
[{age: 50, name: "USER 50"}, 1],
[{age: 50, name: "USER 51"}, 0],
[[{age: 50}, {name: "USER 51"}], 3],
[[{age: 50}, {name: "USER 50"}], 2],
[{"age <": 50, "age >=": 40}, 20],
- [{"name <": "USER 50", "name >": "USER 40"}, 10],
+ [{"name <": "USER 50", "name >": "USER 40"}, 110],
[[{age: 50}, {"name >": "USER 50", "age <": 60}], 74],
- [undefined, 200],
- [[], 200]
+ [undefined, 2000],
+ [[], 2000]
];
var start;
@@ -39,7 +39,7 @@ var store = nStore.new('fixtures/new.db', function () {
start = Date.now();
var group1 = this.group();
var group2 = this.group();
- for (var i = 0; i < 100; i++) {
+ for (var i = 0; i < 1000; i++) {
store.save(null, {name: "USER " + i, age: i}, group1());
store.save(null, {name: "User " + i, age: i}, group2());
}
@@ -53,11 +53,11 @@ var store = nStore.new('fixtures/new.db', function () {
store.all(function (err, result) {
if (err) throw err;
fulfill("all");
- assert.equal(Object.keys(result).length, 200, "There should be 200 rows");
+ assert.equal(Object.keys(result).length, 2000, "There should be 200 rows");
});
if (err) throw err;
- assert.equal(store.length, 200, "There should be 200 records now");
+ assert.equal(store.length, 2000, "There should be 200 records now");
var group = this.group();
queries.forEach(function (pair, i) {
store.find(pair[0], group());

0 comments on commit 7f74bfa

Please sign in to comment.