Socket
Socket
Sign inDemoInstall

nedb

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nedb - npm Package Compare versions

Comparing version 0.10.11 to 0.11.0

browser-version/browser-specific/lib/storage.js

15

lib/customUtils.js

@@ -21,15 +21,4 @@ var crypto = require('crypto')

/**
* Callback signature: err
*/
function ensureFileDoesntExist (file, callback) {
fs.exists(file, function (exists) {
if (!exists) { return callback(null); }
fs.unlink(file, function (err) { return callback(err); });
});
}
// Interface
module.exports.uid = uid;
module.exports.uid = uid;
module.exports.ensureFileDoesntExist = ensureFileDoesntExist;

@@ -8,7 +8,6 @@ /**

var fs = require('fs')
var storage = require('./storage')
, path = require('path')
, model = require('./model')
, async = require('async')
, mkdirp = require('mkdirp')
, customUtils = require('./customUtils')

@@ -63,6 +62,15 @@ , Index = require('./indexes')

mkdirp(dir, function (err) { return callback(err); });
storage.mkdirp(dir, function (err) { return callback(err); });
};
Persistence.ensureFileDoesntExist = function (file, callback) {
storage.exists(file, function (exists) {
if (!exists) { return callback(null); }
storage.unlink(file, function (err) { return callback(err); });
});
};
/**

@@ -125,8 +133,8 @@ * Return the path the datafile if the given filename is relative to the directory where Node Webkit stores

async.waterfall([
async.apply(customUtils.ensureFileDoesntExist, self.tempFilename)
, async.apply(customUtils.ensureFileDoesntExist, self.oldFilename)
async.apply(Persistence.ensureFileDoesntExist, self.tempFilename)
, async.apply(Persistence.ensureFileDoesntExist, self.oldFilename)
, function (cb) {
fs.exists(self.filename, function (exists) {
storage.exists(self.filename, function (exists) {
if (exists) {
fs.rename(self.filename, self.oldFilename, function (err) { return cb(err); });
storage.rename(self.filename, self.oldFilename, function (err) { return cb(err); });
} else {

@@ -138,8 +146,8 @@ return cb();

, function (cb) {
fs.writeFile(self.tempFilename, toPersist, function (err) { return cb(err); });
storage.writeFile(self.tempFilename, toPersist, function (err) { return cb(err); });
}
, function (cb) {
fs.rename(self.tempFilename, self.filename, function (err) { return cb(err); });
storage.rename(self.tempFilename, self.filename, function (err) { return cb(err); });
}
, async.apply(customUtils.ensureFileDoesntExist, self.oldFilename)
, async.apply(Persistence.ensureFileDoesntExist, self.oldFilename)
], function (err) { if (err) { return callback(err); } else { return callback(null); } })

@@ -204,3 +212,3 @@ };

fs.appendFile(self.filename, toPersist, 'utf8', function (err) {
storage.appendFile(self.filename, toPersist, 'utf8', function (err) {
return callback(err);

@@ -258,14 +266,14 @@ });

fs.exists(self.filename, function (filenameExists) {
storage.exists(self.filename, function (filenameExists) {
// Write was successful
if (filenameExists) { return callback(null); }
fs.exists(self.oldFilename, function (oldFilenameExists) {
storage.exists(self.oldFilename, function (oldFilenameExists) {
// New database
if (!oldFilenameExists) {
return fs.writeFile(self.filename, '', 'utf8', function (err) { callback(err); });
return storage.writeFile(self.filename, '', 'utf8', function (err) { callback(err); });
}
// Write failed, use old version
fs.rename(self.oldFilename, self.filename, function (err) { return callback(err); });
storage.rename(self.oldFilename, self.filename, function (err) { return callback(err); });
});

@@ -300,3 +308,4 @@ });

self.ensureDatafileIntegrity(function (exists) {
fs.readFile(self.filename, 'utf8', function (err, rawData) {
storage.readFile(self.filename, 'utf8', function (err, rawData) {
if (err) { return cb(err); }

@@ -309,3 +318,3 @@ var treatedData = Persistence.treatRawData(rawData);

});
// Fill cached database (i.e. all indexes) with data

@@ -312,0 +321,0 @@ try {

{
"name": "nedb",
"version": "0.10.11",
"version": "0.11.0",
"author": {

@@ -39,8 +39,4 @@ "name": "Louis Chatriot",

},
"browser": {
"./lib/customUtils.js": "./browser-version/browser-specific/lib/customUtils.js",
"./lib/persistence.js": "./browser-version/browser-specific/lib/persistence.js"
},
"main": "index",
"licence": "MIT"
}

@@ -11,3 +11,3 @@ # NeDB (Node embedded database)

NeDB was benchmarked against the popular client-side database <a href="http://www.taffydb.com/" target="_blank">TaffyDB</a> and <a href="https://github.com/louischatriot/taffydb-benchmark" target="_blank">NeDB is much, much faster</a>. That's why there is now <a href="#browser-version">a browser version</a>.
NeDB was benchmarked against the popular client-side database <a href="http://www.taffydb.com/" target="_blank">TaffyDB</a> and <a href="https://github.com/louischatriot/taffydb-benchmark" target="_blank">NeDB is much, much faster</a>. That's why there is now <a href="#browser-version">a browser version</a>, which can also provide persistence.

@@ -44,2 +44,3 @@ Check the <a href="https://github.com/louischatriot/nedb/wiki/Change-log" target="_blank">change log in the wiki</a> if you think nedb doesn't behave as the documentation describes! Most of the issues I get are due to non-latest version NeDBs.

* <a href="#indexing">Indexing</a>
* <a href="#browser-version">Browser version</a>

@@ -594,9 +595,11 @@ ### Creating/loading a database

It has been tested and is compatible with Chrome, Safari, Firefox, IE 10, IE 9. Please open an issue if you need compatibility with IE 8/IE 7, I think it will need some work and am not sure it is needed, since most complex webapplications - the ones that would need NeDB - only work on modern browsers. To launch the tests, simply open the file `browser-version/test/index.html` in a browser and you'll see the results of the tests for this browser.
It has been tested and is compatible with Chrome, Safari, Firefox, IE 10, IE 9. Please open an issue if you need compatibility with IE 8/IE 7, I think it will need some work and am not sure it is needed, since most complex webapplications - the ones that would need NeDB - only work on modern browsers anyway. To launch the tests, simply open the file `browser-version/test/index.html` in a browser and you'll see the results of the tests for this browser.
If you fork and modify nedb, you can build the browser version from the sources, the build script is `browser-version/build.js`.
**The browser version is still young!** For now you can only use it as an in-memory database in browser environments, I'll implement persistence later.
As of v0.11, NeDB is also persistent on the browser. To use this, simply create the collection with the `filename` option which will be the name of the `localStorage` variable storing data. Persistence should work on all browsers where NeDB works.
**Browser persistence is still young! It has been tested on most major browsers but please report any bugs you find**
## Performance

@@ -603,0 +606,0 @@ ### Speed

@@ -10,27 +10,18 @@ var should = require('chai').should()

describe('ensureFileDoesntExist', function () {
it('Doesnt do anything if file already doesnt exist', function (done) {
customUtils.ensureFileDoesntExist('workspace/nonexisting', function (err) {
assert.isNull(err);
fs.existsSync('workspace/nonexisting').should.equal(false);
done();
});
describe('uid', function () {
it('Generates a string of the expected length', function () {
customUtils.uid(3).length.should.equal(3);
customUtils.uid(16).length.should.equal(16);
customUtils.uid(42).length.should.equal(42);
customUtils.uid(1000).length.should.equal(1000);
});
it('Deletes file if it exists', function (done) {
fs.writeFileSync('workspace/existing', 'hello world', 'utf8');
fs.existsSync('workspace/existing').should.equal(true);
customUtils.ensureFileDoesntExist('workspace/existing', function (err) {
assert.isNull(err);
fs.existsSync('workspace/existing').should.equal(false);
done();
});
// Very small probability of conflict
it('Generated uids should not be the same', function () {
customUtils.uid(56).should.not.equal(customUtils.uid(56));
});
});
});

@@ -494,5 +494,5 @@ var should = require('chai').should()

async.waterfall([
async.apply(customUtils.ensureFileDoesntExist, dbFile)
, async.apply(customUtils.ensureFileDoesntExist, dbFile + '~')
, async.apply(customUtils.ensureFileDoesntExist, dbFile + '~~')
async.apply(Persistence.ensureFileDoesntExist, dbFile)
, async.apply(Persistence.ensureFileDoesntExist, dbFile + '~')
, async.apply(Persistence.ensureFileDoesntExist, dbFile + '~~')
, function (cb) {

@@ -621,2 +621,27 @@ theDb = new Datastore({ filename: dbFile });

describe('ensureFileDoesntExist', function () {
it('Doesnt do anything if file already doesnt exist', function (done) {
Persistence.ensureFileDoesntExist('workspace/nonexisting', function (err) {
assert.isNull(err);
fs.existsSync('workspace/nonexisting').should.equal(false);
done();
});
});
it('Deletes file if it exists', function (done) {
fs.writeFileSync('workspace/existing', 'hello world', 'utf8');
fs.existsSync('workspace/existing').should.equal(true);
Persistence.ensureFileDoesntExist('workspace/existing', function (err) {
assert.isNull(err);
fs.existsSync('workspace/existing').should.equal(false);
done();
});
});
}); // ==== End of 'ensureFileDoesntExist' ====
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc