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 1.2.1 to 1.3.0

17

benchmarks/commonUtilities.js

@@ -100,4 +100,6 @@ /**

if (i === n) { // Finished
console.log("===== RESULT (insert) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s");
var opsPerSecond = Math.floor(1000* n / profiler.elapsedSinceLastStep());
console.log("===== RESULT (insert) ===== " + opsPerSecond + " ops/s");
profiler.step('Finished inserting ' + n + ' docs');
profiler.insertOpsPerSecond = opsPerSecond;
return cb();

@@ -157,3 +159,3 @@ }

ins[i] = [];
for (j = 0; j < arraySize; j += 1) {

@@ -163,3 +165,3 @@ ins[i].push((i + j) % n);

}
profiler.step("Finding " + n + " documents WITH $IN OPERATOR");

@@ -257,6 +259,7 @@

if (i === n) { // Finished
console.log("===== RESULT (1 remove + 1 insert) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s");
console.log("====== IMPORTANT: Please note that this is the time that was needed to perform " + n + " removes and " + n + " inserts");
console.log("====== The extra inserts are needed to keep collection size at " + n + " items for the benchmark to make sense");
console.log("====== Use the insert speed logged above to calculate the actual remove speed, which is higher (should be significantly so if you use indexing)");
// opsPerSecond corresponds to 1 insert + 1 remove, needed to keep collection size at 10,000
// We need to subtract the time taken by one insert to get the time actually taken by one remove
var opsPerSecond = Math.floor(1000 * n / profiler.elapsedSinceLastStep());
var removeOpsPerSecond = Math.floor(1 / ((1 / opsPerSecond) - (1 / profiler.insertOpsPerSecond)))
console.log("===== RESULT (remove) ===== " + removeOpsPerSecond + " ops/s");
profiler.step('Finished removing ' + n + ' docs');

@@ -263,0 +266,0 @@ return cb();

@@ -0,0 +0,0 @@ var Datastore = require('../lib/datastore')

@@ -0,0 +0,0 @@ var Datastore = require('../lib/datastore')

@@ -0,0 +0,0 @@ var Datastore = require('../lib/datastore')

@@ -0,0 +0,0 @@ var Datastore = require('../lib/datastore')

@@ -0,0 +0,0 @@ var Datastore = require('../lib/datastore')

@@ -0,0 +0,0 @@ var Datastore = require('../lib/datastore')

@@ -29,3 +29,2 @@ var Datastore = require('../lib/datastore')

, async.apply(commonUtilities.removeDocs, { multi: false }, d, n, profiler)
// Test with multiple documents

@@ -32,0 +31,0 @@ , function (cb) { d.remove({}, { multi: true }, function () { return cb(); }); }

@@ -0,0 +0,0 @@ var Datastore = require('../lib/datastore')

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ console.log("Beginning tests");

@@ -0,0 +0,0 @@ console.log("Checking tests results");

var Datastore = require('./lib/datastore');
module.exports = Datastore;

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ var crypto = require('crypto')

@@ -16,4 +16,5 @@ var customUtils = require('./customUtils')

* @param {String} options.filename Optional, datastore will be in-memory only if not provided
* @param {Boolean} options.inMemoryOnly Optional, default to false
* @param {Boolean} options.nodeWebkitAppName Optional, specify the name of your NW app if you want options.filename to be relative to the directory where
* @param {Boolean} options.timestampData Optional, defaults to false. If set to true, createdAt and updatedAt will be created and populated automatically (if not specified by user)
* @param {Boolean} options.inMemoryOnly Optional, defaults to false
* @param {String} options.nodeWebkitAppName Optional, specify the name of your NW app if you want options.filename to be relative to the directory where
* Node Webkit stores application data such as cookies and local storage (the best place to store data in my opinion)

@@ -37,2 +38,3 @@ * @param {Boolean} options.autoload Optional, defaults to false

this.autoload = options.autoload || false;
this.timestampData = options.timestampData || false;
}

@@ -65,3 +67,3 @@

this.indexes._id = new Index({ fieldName: '_id', unique: true });
// Queue a load of the database right away and call the onload handler

@@ -140,13 +142,13 @@ // By default (no onload handler), if there is an error there, no operation will be possible so warn the user by throwing an exception

* @param {String} fieldName
* @param {Function} cb Optional callback, signature: err
* @param {Function} cb Optional callback, signature: err
*/
Datastore.prototype.removeIndex = function (fieldName, cb) {
var callback = cb || function () {};
delete this.indexes[fieldName];
this.persistence.persistNewState([{ $$indexRemoved: fieldName }], function (err) {
if (err) { return callback(err); }
return callback(null);
});
});
};

@@ -289,6 +291,8 @@

var callback = cb || function () {}
, preparedDoc
;
try {
this._insertInCache(newDoc);
preparedDoc = this.prepareDocumentForInsertion(newDoc)
this._insertInCache(preparedDoc);
} catch (e) {

@@ -298,5 +302,5 @@ return callback(e);

this.persistence.persistNewState(util.isArray(newDoc) ? newDoc : [newDoc], function (err) {
this.persistence.persistNewState(util.isArray(preparedDoc) ? preparedDoc : [preparedDoc], function (err) {
if (err) { return callback(err); }
return callback(null, newDoc);
return callback(null, model.deepCopy(preparedDoc));
});

@@ -319,2 +323,3 @@ };

* Prepare a document (or array of documents) to be inserted in a database
* Meaning adds _id and timestamps if necessary on a copy of newDoc to avoid any side effect on user input
* @api private

@@ -329,9 +334,10 @@ */

} else {
if (newDoc._id === undefined) {
newDoc._id = this.createNewId();
}
preparedDoc = model.deepCopy(newDoc);
if (preparedDoc._id === undefined) { preparedDoc._id = this.createNewId(); }
var now = new Date();
if (this.timestampData && preparedDoc.createdAt === undefined) { preparedDoc.createdAt = now; }
if (this.timestampData && preparedDoc.updatedAt === undefined) { preparedDoc.updatedAt = now; }
model.checkObject(preparedDoc);
}
return preparedDoc;

@@ -344,7 +350,7 @@ };

*/
Datastore.prototype._insertInCache = function (newDoc) {
if (util.isArray(newDoc)) {
this._insertMultipleDocsInCache(newDoc);
Datastore.prototype._insertInCache = function (preparedDoc) {
if (util.isArray(preparedDoc)) {
this._insertMultipleDocsInCache(preparedDoc);
} else {
this.addToIndexes(this.prepareDocumentForInsertion(newDoc));
this.addToIndexes(preparedDoc);
}

@@ -358,6 +364,4 @@ };

*/
Datastore.prototype._insertMultipleDocsInCache = function (newDocs) {
var i, failingI, error
, preparedDocs = this.prepareDocumentForInsertion(newDocs)
;
Datastore.prototype._insertMultipleDocsInCache = function (preparedDocs) {
var i, failingI, error;

@@ -373,3 +377,3 @@ for (i = 0; i < preparedDocs.length; i += 1) {

}
if (error) {

@@ -379,3 +383,3 @@ for (i = 0; i < failingI; i += 1) {

}
throw error;

@@ -522,3 +526,3 @@ }

var toBeInserted;
try {

@@ -551,4 +555,4 @@ model.checkObject(updateQuery);

// Preparing update (if an error is thrown here neither the datafile nor
// the in-memory indexes are affected)
// Preparing update (if an error is thrown here neither the datafile nor
// the in-memory indexes are affected)
try {

@@ -559,2 +563,3 @@ for (i = 0; i < candidates.length; i += 1) {

modifiedDoc = model.modify(candidates[i], updateQuery);
if (self.timestampData) { modifiedDoc.updatedAt = new Date(); }
modifications.push({ oldDoc: candidates[i], newDoc: modifiedDoc });

@@ -566,11 +571,11 @@ }

}
// Change the docs in memory
try {
self.updateIndexes(modifications);
} catch (err) {
return callback(err);
}
// Update the datafile
// Change the docs in memory
try {
self.updateIndexes(modifications);
} catch (err) {
return callback(err);
}
// Update the datafile
self.persistence.persistNewState(_.pluck(modifications, 'newDoc'), function (err) {

@@ -577,0 +582,0 @@ if (err) { return callback(err); }

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ var BinarySearchTree = require('binary-search-tree').AVLTree

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

{
"name": "nedb",
"version": "1.2.1",
"version": "1.3.0",
"author": {

@@ -5,0 +5,0 @@ "name": "Louis Chatriot",

@@ -1,16 +0,9 @@

# NeDB - The Javascript Database
<img src="http://i.imgur.com/9O1xHFb.png" style="width: 25%; height: 25%; float: left;">
<img src="http://i.imgur.com/GdeQBmc.png" style="width: 25%; height: 25%; float: left;">
## The Javascript Database
**IMPORTANT NOTE: Please don't submit issues for questions regarding your code. Only actual bugs or feature requests will be answered, all others will be closed without comment. Also, please follow the <a href="#bug-reporting-guidelines">bug reporting guidelines</a>.**
**Embedded persistent or in memory database for Node.js, nw.js, Electron and browsers, 100% Javascript, no binary dependency**. API is a subset of MongoDB's and it's <a href="#speed">plenty fast</a>.
**Embedded persistent database for Node.js, Node Webkit and browsers, written in Javascript, with no binary dependency**, which
can be used with a simple `require` statement. The API is a subset of MongoDB's. You can use it as a persistent or an in-memory only datastore, and it can also be used in all recent browsers (Chrome, Firefox, Safari, IE9+).
**IMPORTANT NOTE**: Please don't submit issues for questions regarding your code. Only actual bugs or feature requests will be answered, all others will be closed without comment. Also, please follow the <a href="#bug-reporting-guidelines">bug reporting guidelines</a> and check the <a href="https://github.com/louischatriot/nedb/wiki/Change-log" target="_blank">change log</a> before submitting an already fixed bug :)
NeDB is not intended to be a replacement of large-scale databases such as MongoDB! Its goal is to provide you with a clean and easy way to query data and persist it to disk, for web applications that do not need lots of concurrent connections, for example a <a href="https://github.com/louischatriot/braindead-ci" target="_blank">continuous integration and deployment server</a> and desktop applications built with <a href="https://github.com/rogerwang/node-webkit" target="_blank">Node Webkit</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.
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.
## Support NeDB development

@@ -23,2 +16,3 @@ No time to <a href="#help-out">help out</a>? You can support NeDB development by sending money or bitcoins!

## Installation, tests

@@ -28,8 +22,7 @@ Module name on npm is `nedb`.

npm install nedb --save // Put latest version in your package.json
npm test // You'll need the dev dependencies to test it
npm test // You'll need the dev dependencies to launch tests
```
## API
It's a subset of MongoDB's API (the most used operations). The current API will not change, but I will add operations as they are needed. Summary of the API:
It's a subset of MongoDB's API (the most used operations).

@@ -57,2 +50,3 @@ * <a href="#creatingloading-a-database">Creating/loading a database</a>

* `inMemoryOnly` (optional, defaults to false): as the name implies.
* `timestampData` (optional, defaults to false): timestamp the insertion and last update of all documents, with the fields `createdAt` and `updatedAt`. User-specified values override automatic generation, usually useful for testing.
* `autoload` (optional, defaults to false): if used, the database will

@@ -615,17 +609,14 @@ automatically be loaded from the datafile upon creation (you don't

### Speed
NeDB is not intended to be a replacement of large-scale databases such as MongoDB, and as such was not designed for speed. That said, it is still pretty fast on the expected datasets, especially if you use indexing. On my machine (3 years old, no SSD), with a collection containing 10,000 documents, with indexing:
* Insert: **5,950 ops/s**
* Find: **25,440 ops/s**
* Update: **4,490 ops/s**
* Remove: **6,620 ops/s**
NeDB is not intended to be a replacement of large-scale databases such as MongoDB, and as such was not designed for speed. That said, it is still pretty fast on the expected datasets, especially if you use indexing. On a typical, not-so-fast dev machine, for a collection containing 10,000 documents, with indexing:
* Insert: **10,680 ops/s**
* Find: **43,290 ops/s**
* Update: **8,000 ops/s**
* Remove: **11,750 ops/s**
You can run the simple benchmarks I use by executing the scripts in the `benchmarks` folder. Run them with the `--help` flag to see how they work.
You can run these simple benchmarks by executing the scripts in the `benchmarks` folder. Run them with the `--help` flag to see how they work.
### Memory footprint
A copy of the whole database is kept in memory. This is not much on the
expected kind of datasets (20MB for 10,000 2KB documents). If requested, I'll introduce an
option to not use this cache to decrease memory footprint (at the cost
of a lower speed).
expected kind of datasets (20MB for 10,000 2KB documents).
## Use in other services

@@ -632,0 +623,0 @@ * <a href="https://github.com/louischatriot/connect-nedb-session"

@@ -0,0 +0,0 @@ var Nedb = require('../lib/datastore.js')

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

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

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

@@ -0,0 +0,0 @@ var Index = require('../lib/indexes')

@@ -0,0 +0,0 @@ var model = require('../lib/model')

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

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