Skip to content

Commit

Permalink
Merge pull request #1 from pdulapalli/master
Browse files Browse the repository at this point in the history
Update library to use Lodash instead of Underscore.js
  • Loading branch information
pdulapalli authored Aug 13, 2019
2 parents aa3302e + fd26f1b commit aa7ab4a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Manage access to data, be it to find, update or remove it
*/
var model = require('./model')
, _ = require('underscore')
, _ = require('lodash')
;


Expand Down
4 changes: 2 additions & 2 deletions lib/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var customUtils = require('./customUtils')
, Executor = require('./executor')
, Index = require('./indexes')
, util = require('util')
, _ = require('underscore')
, _ = require('lodash')
, Persistence = require('./persistence')
, Cursor = require('./cursor')
;
Expand Down Expand Up @@ -636,7 +636,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
}

// Update the datafile
var updatedDocs = _.pluck(modifications, 'newDoc');
var updatedDocs = _.map(modifications, 'newDoc');
self.persistence.persistNewState(updatedDocs, function (err) {
if (err) { return callback(err); }
if (!options.returnUpdatedDocs) {
Expand Down
6 changes: 3 additions & 3 deletions lib/indexes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var BinarySearchTree = require('binary-search-tree').AVLTree
, model = require('./model')
, _ = require('underscore')
, _ = require('lodash')
, util = require('util')
;

Expand Down Expand Up @@ -77,7 +77,7 @@ Index.prototype.insert = function (doc) {
this.tree.insert(key, doc);
} else {
// If an insert fails due to a unique constraint, roll back all inserts before it
keys = _.uniq(key, projectForUnique);
keys = _.uniqBy(key, projectForUnique);

for (i = 0; i < keys.length; i += 1) {
try {
Expand Down Expand Up @@ -147,7 +147,7 @@ Index.prototype.remove = function (doc) {
if (!util.isArray(key)) {
this.tree.delete(key, doc);
} else {
_.uniq(key, projectForUnique).forEach(function (_key) {
_.uniqBy(key, projectForUnique).forEach(function (_key) {
self.tree.delete(_key, doc);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

var util = require('util')
, _ = require('underscore')
, _ = require('lodash')
, modifierFunctions = {}
, lastStepModifierFunctions = {}
, comparisonFunctions = {}
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"name": "nedb",
"version": "1.8.0",
"version": "1.9.0",
"author": {
"name": "Louis Chatriot",
"email": "louis.chatriot@gmail.com"
},
"contributors": [
"Louis Chatriot"
"Louis Chatriot",
"Anurag Dulapalli"
],
"description": "File-based embedded data store for node.js",
"keywords": [
"database",
"datastore",
"embedded"
],
"homepage": "https://github.com/louischatriot/nedb",
"homepage": "https://github.com/k4connect/nedb",
"repository": {
"type": "git",
"url": "git@github.com:louischatriot/nedb.git"
"url": "git@github.com:k4connect/nedb.git"
},
"dependencies": {
"async": "0.2.10",
"binary-search-tree": "0.2.5",
"localforage": "^1.3.0",
"mkdirp": "~0.5.1",
"underscore": "~1.4.4"
"lodash": "~4.17.15",
"mkdirp": "~0.5.1"
},
"devDependencies": {
"chai": "^3.2.0",
Expand Down
14 changes: 7 additions & 7 deletions test/cursor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var should = require('chai').should()
, testDb = 'workspace/test.db'
, fs = require('fs')
, path = require('path')
, _ = require('underscore')
, _ = require('lodash')
, async = require('async')
, model = require('../lib/model')
, Datastore = require('../lib/datastore')
Expand Down Expand Up @@ -201,15 +201,15 @@ describe('Cursor', function () {
db.insert({ name: 'zulu' });

db.find({}).sort({ name: 1 }).exec(function (err, docs) {
_.pluck(docs, 'name')[0].should.equal('zulu');
_.pluck(docs, 'name')[1].should.equal('alpha');
_.pluck(docs, 'name')[2].should.equal('charlie');
_.map(docs, 'name')[0].should.equal('zulu');
_.map(docs, 'name')[1].should.equal('alpha');
_.map(docs, 'name')[2].should.equal('charlie');

delete db.compareStrings;
db.find({}).sort({ name: 1 }).exec(function (err, docs) {
_.pluck(docs, 'name')[0].should.equal('alpha');
_.pluck(docs, 'name')[1].should.equal('charlie');
_.pluck(docs, 'name')[2].should.equal('zulu');
_.map(docs, 'name')[0].should.equal('alpha');
_.map(docs, 'name')[1].should.equal('charlie');
_.map(docs, 'name')[2].should.equal('zulu');

done();
});
Expand Down
28 changes: 14 additions & 14 deletions test/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var should = require('chai').should()
, testDb = 'workspace/test.db'
, fs = require('fs')
, path = require('path')
, _ = require('underscore')
, _ = require('lodash')
, async = require('async')
, model = require('../lib/model')
, Datastore = require('../lib/datastore')
Expand Down Expand Up @@ -136,9 +136,9 @@ describe('Database', function () {
d.insert({ somedata: 'again' }, function (err) {
d.find({}, function (err, docs) {
docs.length.should.equal(3);
_.pluck(docs, 'somedata').should.contain('ok');
_.pluck(docs, 'somedata').should.contain('another');
_.pluck(docs, 'somedata').should.contain('again');
_.map(docs, 'somedata').should.contain('ok');
_.map(docs, 'somedata').should.contain('another');
_.map(docs, 'somedata').should.contain('again');
done();
});
});
Expand Down Expand Up @@ -646,10 +646,10 @@ describe('Database', function () {
d.find({}, function (err, docs) {
assert.isNull(err);
docs.length.should.equal(3);
_.pluck(docs, 'somedata').should.contain('ok');
_.pluck(docs, 'somedata').should.contain('another');
_.map(docs, 'somedata').should.contain('ok');
_.map(docs, 'somedata').should.contain('another');
_.find(docs, function (d) { return d.somedata === 'another' }).plus.should.equal('additional data');
_.pluck(docs, 'somedata').should.contain('again');
_.map(docs, 'somedata').should.contain('again');
return cb();
});
}
Expand All @@ -669,7 +669,7 @@ describe('Database', function () {
d.find({ somedata: 'again' }, function (err, docs) {
assert.isNull(err);
docs.length.should.equal(2);
_.pluck(docs, 'somedata').should.not.contain('ok');
_.map(docs, 'somedata').should.not.contain('ok');
return cb();
});
}
Expand Down Expand Up @@ -769,14 +769,14 @@ describe('Database', function () {
d.find({ fruits: 'pear' }, function (err, docs) {
assert.isNull(err);
docs.length.should.equal(2);
_.pluck(docs, '_id').should.contain(doc1._id);
_.pluck(docs, '_id').should.contain(doc2._id);
_.map(docs, '_id').should.contain(doc1._id);
_.map(docs, '_id').should.contain(doc2._id);

d.find({ fruits: 'banana' }, function (err, docs) {
assert.isNull(err);
docs.length.should.equal(2);
_.pluck(docs, '_id').should.contain(doc1._id);
_.pluck(docs, '_id').should.contain(doc3._id);
_.map(docs, '_id').should.contain(doc1._id);
_.map(docs, '_id').should.contain(doc3._id);

d.find({ fruits: 'doesntexist' }, function (err, docs) {
assert.isNull(err);
Expand Down Expand Up @@ -2444,8 +2444,8 @@ describe('Database', function () {

d.indexes.b.tree.getNumberOfKeys().should.equal(1);
d.indexes.b.getMatching('same').length.should.equal(2);
_.pluck(d.indexes.b.getMatching('same'), '_id').should.contain(doc1._id);
_.pluck(d.indexes.b.getMatching('same'), '_id').should.contain(doc2._id);
_.map(d.indexes.b.getMatching('same'), '_id').should.contain(doc1._id);
_.map(d.indexes.b.getMatching('same'), '_id').should.contain(doc2._id);

// The same pointers are shared between all indexes
d.indexes.a.tree.getNumberOfKeys().should.equal(2);
Expand Down
2 changes: 1 addition & 1 deletion test/executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var should = require('chai').should()
, testDb = 'workspace/test.db'
, fs = require('fs')
, path = require('path')
, _ = require('underscore')
, _ = require('lodash')
, async = require('async')
, model = require('../lib/model')
, Datastore = require('../lib/datastore')
Expand Down
2 changes: 1 addition & 1 deletion test/indexes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var Index = require('../lib/indexes')
, customUtils = require('../lib/customUtils')
, should = require('chai').should()
, assert = require('chai').assert
, _ = require('underscore')
, _ = require('lodash')
, async = require('async')
, model = require('../lib/model')
;
Expand Down
2 changes: 1 addition & 1 deletion test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var model = require('../lib/model')
, should = require('chai').should()
, assert = require('chai').assert
, expect = require('chai').expect
, _ = require('underscore')
, _ = require('lodash')
, async = require('async')
, util = require('util')
, Datastore = require('../lib/datastore')
Expand Down
2 changes: 1 addition & 1 deletion test/persistence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var should = require('chai').should()
, testDb = 'workspace/test.db'
, fs = require('fs')
, path = require('path')
, _ = require('underscore')
, _ = require('lodash')
, async = require('async')
, model = require('../lib/model')
, customUtils = require('../lib/customUtils')
Expand Down

0 comments on commit aa7ab4a

Please sign in to comment.