Skip to content

Commit

Permalink
New version.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Feb 8, 2017
1 parent ade3ef5 commit 2a31fa4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions index.js
Expand Up @@ -131,7 +131,7 @@ Database.prototype.insert = function(doc, unique) {
}

builder = new DatabaseBuilder2();
var json = framework_builders.isSchema(doc) ? doc.$clean() : doc;
var json = typeof(doc.$clean) === 'function' ? doc.$clean() : doc;
self.pending_append.push({ doc: JSON.stringify(json), builder: builder });
setImmediate(() => self.next(1));
self.emit('insert', json);
Expand Down Expand Up @@ -650,9 +650,7 @@ Database.prototype.$reader = function() {
return self;
}

var index = 0;
var list = self.pending_reader.splice(0);

if (INMEMORY[self.name])
self.$reader2_inmemory('#', list, () => self.next(0));
else
Expand Down Expand Up @@ -958,7 +956,6 @@ Database.prototype.$views = function() {
}

var response = [];
var writers = [];

for (var i = 0; i < length; i++)
response.push({ response: [], name: views[i], builder: self.views[views[i]], count: 0, counter: 0 });
Expand Down Expand Up @@ -1114,7 +1111,6 @@ Database.prototype.$remove = function() {
reader.on('data', framework_utils.streamer(NEWLINE, function(value, index) {

var json = JSON.parse(value.trim());
var is = false;
var removed = false;

for (var i = 0; i < length; i++) {
Expand Down Expand Up @@ -1178,7 +1174,6 @@ Database.prototype.$remove_inmemory = function() {

for (var j = 0, jl = data.length; j < jl; j++) {
var json = data[j];
var is = false;
var removed = false;

for (var i = 0; i < length; i++) {
Expand Down Expand Up @@ -1236,7 +1231,10 @@ Database.prototype.$drop = function() {
});
} catch (e) {}

remove.wait((filename, next) => Fs.unlink(filename, next), () => self.next(0), 5);
remove.wait((filename, next) => Fs.unlink(filename, next), function() {
self.next(0);
self.free();
}, 5);

Object.keys(self.inmemory).forEach(function(key) {
self.inmemory[key] = undefined;
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nosql",
"version": "5.0.1-1",
"version": "5.0.1",
"description": "NoSQL embedded database for small Node.js projects (supports insert, update, remove, drop, views, binary files)",
"main": "./index.js",
"keywords": [ "nosql", "database", "embed", "embedded", "db", "binary"],
Expand Down
6 changes: 3 additions & 3 deletions utils.js
Expand Up @@ -163,11 +163,11 @@ exports.streamer = function(beg, end, callback) {
}

var indexer = 0;
var buffer = new Buffer(0);
var buffer = exports.createBufferSize(0);

beg = new Buffer(beg, 'utf8');
beg = exports.createBuffer(beg, 'utf8');
if (end)
end = new Buffer(end, 'utf8');
end = exports.createBuffer(end, 'utf8');

if (!end) {
var length = beg.length;
Expand Down

0 comments on commit 2a31fa4

Please sign in to comment.