Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

penseur

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

penseur - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

lib/criteria.js

75

lib/db.js

@@ -0,8 +1,11 @@

'use strict';
// Load Modules
var Boom = require('boom');
var Hoek = require('hoek');
var Items = require('items');
var RethinkDB = require('rethinkdb');
var Table = require('./table');
const Boom = require('boom');
const Hoek = require('hoek');
const Items = require('items');
const RethinkDB = require('rethinkdb');
const Criteria = require('./criteria');
const Table = require('./table');

@@ -12,3 +15,3 @@

var internals = {};
const internals = {};

@@ -38,6 +41,4 @@

var self = this;
RethinkDB.connect(this._settings, (err, connection) => {
RethinkDB.connect(this._settings, function (err, connection) {
if (err) {

@@ -47,3 +48,3 @@ return callback(err);

self._connection = connection;
this._connection = connection;
return callback(null);

@@ -64,7 +65,7 @@ });

var tables = Object.keys(this.tables);
for (var i = 0, il = tables.length; i < il; ++i) {
var table = this.tables[tables[i]];
for (var c = 0, cl = table._cursors.length; c < cl; ++c) {
table._cursors[c].close();
const tables = Object.keys(this.tables);
for (let i = 0; i < tables.length; ++i) {
const table = this.tables[tables[i]];
for (let j = 0; j < table._cursors.length; ++j) {
table._cursors[j].close();
}

@@ -77,3 +78,3 @@

this._connection.close(function (err) { // Explicit callback to avoid generating a promise
this._connection.close((err) => { // Explicit callback to avoid generating a promise

@@ -87,6 +88,8 @@ return next(err);

const Proto = this._settings.extended || Table;
tables = [].concat(tables);
for (var i = 0, il = tables.length; i < il; ++i) {
var table = tables[i];
for (let i = 0; i < tables.length; ++i) {
const table = tables[i];
if (this.tables[table]) {

@@ -96,3 +99,3 @@ return;

var record = new Table(table, this);
const record = new Proto(table, this);

@@ -113,8 +116,6 @@ // Decorate object with tables

var self = this;
// Connect if not connected already
if (!this._connection) {
this.connect(function (err) {
this.connect((err) => {

@@ -125,3 +126,3 @@ if (err) {

return self.establish(tables, callback);
return this.establish(tables, callback);
});

@@ -132,3 +133,3 @@

RethinkDB.dbList().run(this._connection, function (err, names) {
RethinkDB.dbList().run(this._connection, (err, names) => {

@@ -139,7 +140,7 @@ if (err) {

if (names.indexOf(self._name) === -1) {
if (names.indexOf(this._name) === -1) {
// Create new database
RethinkDB.dbCreate(self._name).run(self._connection, function (err, created) {
RethinkDB.dbCreate(this._name).run(this._connection, (err, created) => {

@@ -150,3 +151,3 @@ if (err) {

return self._createTable(tables, callback);
return this._createTable(tables, callback);
});

@@ -158,3 +159,3 @@ }

return self._createTable(tables, callback);
return this._createTable(tables, callback);
}

@@ -167,6 +168,4 @@ });

var self = this;
RethinkDB.db(this._name).tableList().run(this._connection, (err, names) => {
RethinkDB.db(this._name).tableList().run(this._connection, function (err, names) {
if (err) {

@@ -176,3 +175,3 @@ return callback(err);

var each = function (table, next) {
const each = (table, next) => {

@@ -183,5 +182,5 @@ if (names.indexOf(table) === -1) {

RethinkDB.db(self._name).tableCreate(table).run(self._connection, function (err, result) {
RethinkDB.db(this._name).tableCreate(table).run(this._connection, (err, result) => {
self.table(table);
this.table(table);
return next(err);

@@ -194,4 +193,4 @@ });

self.table(table);
return self.tables[table].empty(next);
this.table(table);
return this.tables[table].empty(next);
}

@@ -216,3 +215,3 @@ };

var callback = arguments[arguments.length - 1];
const callback = arguments[arguments.length - 1];
return callback(Boom.internal('Simulated database error'));

@@ -233,3 +232,3 @@ };

return new Table.Criteria(criteria, 'fields');
return new Criteria(criteria, 'fields');
};

@@ -0,1 +1,4 @@

'use strict';
exports.Db = require('./db');
exports.Table = require('./table');

@@ -0,5 +1,9 @@

'use strict';
// Load Modules
var Boom = require('boom');
var RethinkDB = require('rethinkdb');
const Boom = require('boom');
const RethinkDB = require('rethinkdb');
const Cursor = require('./cursor');
const Criteria = require('./criteria');

@@ -9,330 +13,264 @@

var internals = {};
const internals = {};
exports = module.exports = internals.Table = function (name, db) {
exports = module.exports = class {
this._name = name;
this._db = db;
this._table = RethinkDB.db(this._db._name).table(name);
this._cursors = [];
};
constructor(name, db) {
this._name = name;
this._db = db;
internals.Table.prototype.get = function (id, callback) {
if (Array.isArray(id)) {
this._run(this._table.getAll(RethinkDB.args(id)), 'get', id, callback);
return;
this._table = RethinkDB.db(this._db._name).table(name);
this._cursors = [];
}
this._run(this._table.get(id), 'get', id, callback);
};
get(id, callback) {
internals.Table.prototype.query = function (criteria, callback) {
this._run(internals.wrap(criteria).select(this._table), 'query', criteria, callback);
};
internals.Table.prototype.single = function (criteria, callback) {
var self = this;
this._run(internals.wrap(criteria).select(this._table), 'single', criteria, callback, function (ignore, result) {
if (!result) {
return callback(null, null);
if (Array.isArray(id)) {
this._run(this._table.getAll(RethinkDB.args(id)), 'get', id, callback);
return;
}
if (result.length !== 1) {
return self.error('single', 'Found multiple items', criteria, callback);
}
this._run(this._table.get(id), 'get', id, callback);
}
return callback(null, result[0]);
});
};
query(criteria, callback) {
this._run(Criteria.wrap(criteria).select(this._table), 'query', criteria, callback);
}
internals.Table.prototype.count = function (criteria, callback) {
single(criteria, callback) {
this._run(internals.wrap(criteria).select(this._table).count(), 'count', { criteria: criteria }, callback);
};
this._run(Criteria.wrap(criteria).select(this._table), 'single', criteria, callback, (ignore, result) => {
if (!result) {
return callback(null, null);
}
internals.Table.prototype.insert = function (items, callback) {
if (result.length !== 1) {
return this._error('single', 'Found multiple items', criteria, callback);
}
this._run(this._table.insert(items), 'insert', items, callback, function (ignore, result) {
return callback(null, result[0]);
});
};
// Single item
count(criteria, callback) {
if (!Array.isArray(items)) {
return callback(null, items.id !== undefined ? items.id : result.generated_keys[0]);
}
this._run(Criteria.wrap(criteria).select(this._table).count(), 'count', { criteria: criteria }, callback);
};
// Items array
insert(items, callback) {
var generated = result.generated_keys || [];
if (generated.length === items.length) {
return callback(null, result.generated_keys);
}
this._run(this._table.insert(items), 'insert', items, callback, (ignore, result) => {
// Mixed array
// Single item
var ids = [];
for (var g = 0, i = 0, il = items.length; i < il; ++i) {
if (items[i].id !== undefined) {
ids.push(items[i].id);
if (!Array.isArray(items)) {
return callback(null, items.id !== undefined ? items.id : result.generated_keys[0]);
}
else {
ids.push(result.generated_keys[g++]);
}
}
return callback(null, ids);
});
};
// Items array
const generated = result.generated_keys || [];
if (generated.length === items.length) {
return callback(null, result.generated_keys);
}
internals.Table.prototype.update = function (id, changes, callback) {
// Mixed array
var self = this;
const ids = [];
let g = 0;
for (let i = 0; i < items.length; ++i) {
if (items[i].id !== undefined) {
ids.push(items[i].id);
}
else {
ids.push(result.generated_keys[g++]);
}
}
this._run(this._table.get(id).update(changes), 'update', { id: id, changes: changes }, callback, function (ignore, result) {
return callback(null, ids);
});
};
if (!result.replaced &&
!result.unchanged) {
update(id, changes, callback) {
return self.error('update', 'No item found to update', { id: id, changes: changes }, callback);
}
this._run(this._table.get(id).update(changes), 'update', { id: id, changes: changes }, callback, (ignore, result) => {
return callback(null);
});
};
if (!result.replaced &&
!result.unchanged) {
return this._error('update', 'No item found to update', { id: id, changes: changes }, callback);
}
internals.Table.prototype.increment = function (id, field, value, callback) {
return callback(null);
});
};
var self = this;
increment(id, field, value, callback) {
var changes = {};
changes[field] = RethinkDB.row(field).add(value);
this._run(this._table.get(id).update(changes, { returnChanges: true }), 'increment', { id: id, field: field, value: value }, callback, function (ignore, result) {
const changes = {};
changes[field] = RethinkDB.row(field).add(value);
this._run(this._table.get(id).update(changes, { returnChanges: true }), 'increment', { id: id, field: field, value: value }, callback, (ignore, result) => {
if (!result.replaced) {
return self.error('increment', 'No item found to update', { id: id, field: field, value: value }, callback);
}
if (!result.replaced) {
return this._error('increment', 'No item found to update', { id: id, field: field, value: value }, callback);
}
var inc = result.changes[0].new_val[field];
return callback(null, inc);
});
};
const inc = result.changes[0].new_val[field];
return callback(null, inc);
});
};
append(id, field, value, callback) {
internals.Table.prototype.append = function (id, field, value, callback) {
const changes = {};
changes[field] = RethinkDB.row(field).append(value);
this._run(this._table.get(id).update(changes), 'append', { id: id, field: field, value: value }, callback, (ignore, result) => {
var self = this;
if (!result.replaced) {
return this._error('append', 'No item found to update', { id: id, field: field, value: value }, callback);
}
var changes = {};
changes[field] = RethinkDB.row(field).append(value);
this._run(this._table.get(id).update(changes), 'append', { id: id, field: field, value: value }, callback, function (ignore, result) {
return callback(null);
});
};
if (!result.replaced) {
return self.error('append', 'No item found to update', { id: id, field: field, value: value }, callback);
}
unset(id, fields, callback) {
return callback(null);
});
};
const changes = (item) => item.without(fields);
this._run(this._table.get(id).replace(changes), 'unset', { id: id, fields: fields }, callback, (ignore, result) => {
internals.Table.prototype.unset = function (id, fields, callback) {
if (!result.replaced &&
!result.unchanged) {
var self = this;
return this._error('unset', 'No item found to update', { id: id, fields: fields }, callback);
}
var changes = function (item) {
return item.without(fields);
return callback(null);
});
};
this._run(this._table.get(id).replace(changes), 'unset', { id: id, fields: fields }, callback, function (ignore, result) {
remove(criteria, callback) {
if (!result.replaced &&
!result.unchanged) {
const isSingle = (typeof criteria !== 'object');
const selection = (isSingle ? this._table.get(criteria)
: (Array.isArray(criteria) ? this._table.getAll(RethinkDB.args(criteria))
: this._table.filter(criteria)));
return self.error('unset', 'No item found to update', { id: id, fields: fields }, callback);
}
this._run(selection.delete(), 'remove', criteria, callback, (ignore, result) => {
return callback(null);
});
};
if (isSingle &&
!result.deleted) {
return this._error('remove', 'No item found to remove', criteria, callback);
}
internals.Table.prototype.remove = function (criteria, callback) {
return callback(null);
});
};
var self = this;
empty(callback) {
var isSingle = (typeof criteria !== 'object');
var selection = (isSingle ? this._table.get(criteria)
: (Array.isArray(criteria) ? this._table.getAll(RethinkDB.args(criteria))
: this._table.filter(criteria)));
this._run(this._table.delete(), 'empty', null, callback);
};
this._run(selection.delete(), 'remove', criteria, callback, function (ignore, result) {
sync(callback) {
if (isSingle &&
!result.deleted) {
this._table.sync().run(this._db._connection, (err, result) => {
return self.error('remove', 'No item found to remove', criteria, callback);
}
return callback(null);
});
};
internals.Table.prototype.empty = function (callback) {
this._run(this._table.delete(), 'empty', null, callback);
};
internals.Table.prototype._run = function (request, action, inputs, callback, next) {
var self = this;
next = next || callback; // next() must never return an error
request.run(this._db._connection, function (err, result) {
if (err) {
return self.error(action, err, inputs, callback);
}
// Single item
if (!result ||
typeof result.toArray !== 'function') {
return next(null, result);
}
// Cursor
var cursor = result;
cursor.toArray(function (err, results) {
if (err) {
return self.error(action, err, inputs, callback);
return this._error('sync', err, null, callback);
}
cursor.close();
return next(null, results.length ? results : null);
return callback();
});
});
};
};
changes(criteria, each, callback) {
internals.Table.prototype.error = function (action, err, inputs, callback) {
callback = callback || each;
return callback(Boom.internal('Database error', { error: err, table: this._name, action: action, inputs: inputs }));
};
internals.Table.prototype.changes = function (criteria, each, callback) {
var self = this;
callback = callback || each;
var request = this._table;
if (criteria !== '*') {
if (typeof criteria !== 'object') {
request = this._table.get(criteria);
let request = this._table;
if (criteria !== '*') {
if (typeof criteria !== 'object') {
request = this._table.get(criteria);
}
else if (Array.isArray(criteria)) {
request = this._table.getAll(RethinkDB.args(criteria));
}
else {
request = this._table.filter(criteria);
}
}
else if (Array.isArray(criteria)) {
request = this._table.getAll(RethinkDB.args(criteria));
}
else {
request = this._table.filter(criteria);
}
}
request.changes().run(this._db._connection, { includeStates: true }, function (err, cursor) {
request.changes().run(this._db._connection, { includeStates: true }, (err, cursor) => {
if (err) {
return self.error('changes', err, criteria, callback);
}
self._cursors.push(cursor);
var isReady = false;
cursor.each(function (err, item) {
if (err) {
return self.error('changes', err, criteria, each);
return this._error('changes', err, criteria, callback);
}
if (item.state) {
isReady = (item.state === 'ready');
return;
}
this._cursors.push(cursor);
if (isReady) {
return each(null, { before: item.old_val || null, after: item.new_val || null });
}
});
let isReady = false;
cursor.each((err, item) => {
return callback(null, new internals.Cursor(cursor));
});
};
if (err) {
return this._error('changes', err, criteria, each);
}
if (item.state) {
isReady = (item.state === 'ready');
return;
}
internals.Table.prototype.sync = function (callback) {
if (isReady) {
return each(null, { before: item.old_val || null, after: item.new_val || null });
}
});
var self = this;
return callback(null, new Cursor(cursor));
});
};
this._table.sync().run(this._db._connection, function (err, result) {
_run(request, action, inputs, callback, next) {
if (err) {
return self.error('sync', err, null, callback);
}
next = next || callback; // next() must never return an error
return callback();
});
};
request.run(this._db._connection, (err, result) => {
if (err) {
return this._error(action, err, inputs, callback);
}
internals.Cursor = function (cursor) {
// Single item
this._cursor = cursor;
};
if (!result ||
typeof result.toArray !== 'function') {
return next(null, result);
}
internals.Cursor.prototype.close = function () {
// Cursor
this._cursor.close();
};
const cursor = result;
cursor.toArray((err, results) => {
if (err) {
return this._error(action, err, inputs, callback);
}
exports.Criteria = internals.Criteria = function (criteria, type) {
cursor.close();
return next(null, results.length ? results : null);
});
});
};
this.criteria = criteria;
this.type = type || 'filter';
};
_error(action, err, inputs, callback) {
internals.Criteria.prototype.select = function (table) {
return table[this.type === 'fields' ? 'hasFields' : 'filter'](this.criteria);
return callback(Boom.internal('Database error', { error: err, table: this._name, action: action, inputs: inputs }));
};
};
internals.wrap = function (criteria) {
if (criteria instanceof internals.Criteria) {
return criteria;
}
return new internals.Criteria(criteria);
};
{
"name": "penseur",
"description": "Lightweight RethinkDB wrapper",
"version": "2.1.0",
"version": "2.2.0",
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)",

@@ -12,13 +12,13 @@ "repository": "git://github.com/hueniverse/penseur",

"engines": {
"node": "4.x.x"
"node": ">=4.x.x"
},
"dependencies": {
"boom": "2.x.x",
"hoek": "2.x.x",
"items": "1.x.x",
"boom": "3.x.x",
"hoek": "3.x.x",
"items": "2.x.x",
"rethinkdb": "2.x.x"
},
"devDependencies": {
"code": "1.x.x",
"lab": "5.x.x"
"code": "2.x.x",
"lab": "7.x.x"
},

@@ -25,0 +25,0 @@ "scripts": {

@@ -0,7 +1,9 @@

'use strict';
// Load modules
var Code = require('code');
var Lab = require('lab');
var Penseur = require('..');
var RethinkDB = require('rethinkdb');
const Code = require('code');
const Lab = require('lab');
const Penseur = require('..');
const RethinkDB = require('rethinkdb');

@@ -11,3 +13,3 @@

var internals = {};
const internals = {};

@@ -17,22 +19,22 @@

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;
const lab = exports.lab = Lab.script();
const describe = lab.describe;
const it = lab.it;
const expect = Code.expect;
describe('Db', function () {
describe('Db', () => {
it('establishes and interacts with a database', function (done) {
it('establishes and interacts with a database', (done) => {
var db = new Penseur.Db('penseurtest', { host: 'localhost', port: 28015 });
const db = new Penseur.Db('penseurtest', { host: 'localhost', port: 28015 });
db.establish(['test'], function (err) {
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, value: 'x' }, function (err, result) {
db.test.insert({ id: 1, value: 'x' }, (err, result) => {
expect(err).to.not.exist();
db.test.get(1, function (err, item) {
db.test.get(1, (err, item) => {

@@ -47,11 +49,45 @@ expect(err).to.not.exist();

describe('connect()', function () {
it('overrides table methods', (done) => {
it('uses default server location', function (done) {
const Override = class extends Penseur.Table {
insert(items, callback) {
var db = new Penseur.Db('penseurtest');
items = [].concat(items);
for (let i = 0; i < items.length; ++i) {
items[i].flag = true;
}
db.connect(function (err) {
return super.insert(items, callback);
}
};
const db = new Penseur.Db('penseurtest', { host: 'localhost', port: 28015, extended: Override });
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, value: 'x' }, (err, result) => {
expect(err).to.not.exist();
db.test.get(1, (err, item) => {
expect(err).to.not.exist();
expect(item.value).to.equal('x');
expect(item.flag).to.equal(true);
db.close(done);
});
});
});
});
describe('connect()', () => {
it('uses default server location', (done) => {
const db = new Penseur.Db('penseurtest');
db.connect((err) => {
expect(err).to.not.exist();
db.close(done);

@@ -61,7 +97,7 @@ });

it('fails connecting to missing server', function (done) {
it('fails connecting to missing server', (done) => {
var db = new Penseur.Db('penseurtest', { host: 'example.com', timeout: 0.001 });
const db = new Penseur.Db('penseurtest', { host: 'example.com', timeout: 0.001 });
db.connect(function (err) {
db.connect((err) => {

@@ -74,13 +110,13 @@ expect(err).to.exist();

describe('close()', function () {
describe('close()', () => {
it('ignores unconnected state', function (done) {
it('ignores unconnected state', (done) => {
var db = new Penseur.Db('penseurtest');
const db = new Penseur.Db('penseurtest');
db.close(done);
});
it('allows no callback', function (done) {
it('allows no callback', (done) => {
var db = new Penseur.Db('penseurtest');
const db = new Penseur.Db('penseurtest');
db.close();

@@ -91,9 +127,9 @@ done();

describe('table()', function () {
describe('table()', () => {
it('skips decorating object when table name conflicts', function (done) {
it('skips decorating object when table name conflicts', (done) => {
var db = new Penseur.Db('penseurtest');
const db = new Penseur.Db('penseurtest');
db.establish(['connect'], function (err) {
db.establish(['connect'], (err) => {

@@ -107,8 +143,8 @@ expect(err).to.not.exist();

it('skips decorating object when table already set up', function (done) {
it('skips decorating object when table already set up', (done) => {
var db = new Penseur.Db('penseurtest');
const db = new Penseur.Db('penseurtest');
db.table('abc');
db.establish(['abc'], function (err) {
db.establish(['abc'], (err) => {

@@ -122,14 +158,14 @@ expect(err).to.not.exist();

describe('establish()', function () {
describe('establish()', () => {
it('creates new database', function (done) {
it('creates new database', (done) => {
var db = new Penseur.Db('penseurtest');
db.connect(function (err) {
const db = new Penseur.Db('penseurtest');
db.connect((err) => {
expect(err).to.not.exist();
RethinkDB.dbDrop(db._name).run(db._connection, function (err, dropped) {
RethinkDB.dbDrop(db._name).run(db._connection, (err, dropped) => {
db.establish(['test'], function (err) {
db.establish(['test'], (err) => {

@@ -143,7 +179,7 @@ expect(err).to.not.exist();

it('fails creating a database', function (done) {
it('fails creating a database', (done) => {
var db = new Penseur.Db('penseur-test');
const db = new Penseur.Db('penseur-test');
db.establish(['test'], function (err) {
db.establish(['test'], (err) => {

@@ -155,7 +191,7 @@ expect(err).to.exist();

it('fails connecting to missing server', function (done) {
it('fails connecting to missing server', (done) => {
var db = new Penseur.Db('penseurtest', { host: 'example.com', timeout: 0.001 });
const db = new Penseur.Db('penseurtest', { host: 'example.com', timeout: 0.001 });
db.establish(['test'], function (err) {
db.establish(['test'], (err) => {

@@ -167,6 +203,6 @@ expect(err).to.exist();

it('errors on database dbList() error', { parallel: false }, function (done) {
it('errors on database dbList() error', { parallel: false }, (done) => {
var db = new Penseur.Db('penseurtest');
var orig = RethinkDB.dbList;
const db = new Penseur.Db('penseurtest');
const orig = RethinkDB.dbList;
RethinkDB.dbList = function () {

@@ -184,3 +220,3 @@

db.establish(['test'], function (err) {
db.establish(['test'], (err) => {

@@ -192,12 +228,12 @@ expect(err).to.exist();

it('errors on database dbCreate() error', { parallel: false }, function (done) {
it('errors on database dbCreate() error', { parallel: false }, (done) => {
var db = new Penseur.Db('penseur-test');
db.connect(function (err) {
const db = new Penseur.Db('penseur-test');
db.connect((err) => {
expect(err).to.not.exist();
RethinkDB.dbDrop(db._name).run(db._connection, function (err, dropped) {
RethinkDB.dbDrop(db._name).run(db._connection, (err, dropped) => {
var orig = RethinkDB.dbCreate;
const orig = RethinkDB.dbCreate;
RethinkDB.dbCreate = function () {

@@ -215,3 +251,3 @@

db.establish(['test'], function (err) {
db.establish(['test'], (err) => {

@@ -226,8 +262,8 @@ expect(err).to.exist();

describe('_createTable', function () {
describe('_createTable', () => {
it('errors on database dbList() error', { parallel: false }, function (done) {
it('errors on database dbList() error', { parallel: false }, (done) => {
var db = new Penseur.Db('penseurtest');
var orig = RethinkDB.db;
const db = new Penseur.Db('penseurtest');
const orig = RethinkDB.db;
RethinkDB.db = function () {

@@ -250,3 +286,3 @@

db.establish(['test'], function (err) {
db.establish(['test'], (err) => {

@@ -259,16 +295,16 @@ expect(err).to.exist();

describe('disable()', function () {
describe('disable()', () => {
it('simulates an error', function (done) {
it('simulates an error', (done) => {
var db = new Penseur.Db('penseurtest', { host: 'localhost', port: 28015, test: true });
const db = new Penseur.Db('penseurtest', { host: 'localhost', port: 28015, test: true });
db.establish(['test'], function (err) {
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, value: 'x' }, function (err, result) {
db.test.insert({ id: 1, value: 'x' }, (err, result) => {
expect(err).to.not.exist();
db.test.get(1, function (err, item1) {
db.test.get(1, (err, item1) => {

@@ -279,3 +315,3 @@ expect(err).to.not.exist();

db.disable('test', 'get');
db.test.get(1, function (err, item2) {
db.test.get(1, (err, item2) => {

@@ -285,3 +321,3 @@ expect(err).to.exist();

db.enable('test', 'get');
db.test.get(1, function (err, item3) {
db.test.get(1, (err, item3) => {

@@ -288,0 +324,0 @@ expect(err).to.not.exist();

@@ -0,7 +1,8 @@

'use strict';
// Load modules
var Code = require('code');
var Hoek = require('hoek');
var Lab = require('lab');
var Penseur = require('..');
const Code = require('code');
const Lab = require('lab');
const Penseur = require('..');

@@ -11,3 +12,3 @@

var internals = {};
const internals = {};

@@ -17,19 +18,19 @@

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;
const lab = exports.lab = Lab.script();
const describe = lab.describe;
const it = lab.it;
const expect = Code.expect;
describe('Table', { parallel: false }, function () {
describe('Table', { parallel: false }, () => {
describe('get()', function () {
describe('get()', () => {
it('fails on database error', function (done) {
it('fails on database error', (done) => {
var db = new Penseur.Db('penseurtest');
const db = new Penseur.Db('penseurtest');
db.table('invalid');
db.connect(function (err) {
db.connect((err) => {
db.invalid.get(1, function (err, item) {
db.invalid.get(1, (err, item) => {

@@ -42,13 +43,13 @@ expect(err).to.exist();

it('returns the requested objects', function (done) {
it('returns the requested objects', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.get([1, 3], function (err, result) {
db.test.get([1, 3], (err, result) => {

@@ -63,13 +64,13 @@ expect(err).to.not.exist();

it('returns the requested objects found (partial)', function (done) {
it('returns the requested objects found (partial)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.get([1, 3, 4], function (err, result) {
db.test.get([1, 3, 4], (err, result) => {

@@ -84,13 +85,13 @@ expect(err).to.not.exist();

it('returns the requested objects found (duplicates)', function (done) {
it('returns the requested objects found (duplicates)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.get([1, 3, 3], function (err, result) {
db.test.get([1, 3, 3], (err, result) => {

@@ -105,13 +106,13 @@ expect(err).to.not.exist();

it('returns the requested objects found (none)', function (done) {
it('returns the requested objects found (none)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.get([4, 5, 6], function (err, result) {
db.test.get([4, 5, 6], (err, result) => {

@@ -127,15 +128,15 @@ expect(err).to.not.exist();

describe('query()', function () {
describe('query()', () => {
it('returns the requested objects', function (done) {
it('returns the requested objects', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.query({ a: 1 }, function (err, result) {
db.test.query({ a: 1 }, (err, result) => {

@@ -151,15 +152,15 @@ expect(err).to.not.exist();

describe('single()', function () {
describe('single()', () => {
it('returns the requested object', function (done) {
it('returns the requested object', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.single({ a: 2 }, function (err, result) {
db.test.single({ a: 2 }, (err, result) => {

@@ -174,13 +175,13 @@ expect(err).to.not.exist();

it('returns nothing', function (done) {
it('returns nothing', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.single({ a: 3 }, function (err, result) {
db.test.single({ a: 3 }, (err, result) => {

@@ -195,13 +196,13 @@ expect(err).to.not.exist();

it('errors on multiple matches', function (done) {
it('errors on multiple matches', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.single({ a: 1 }, function (err, result) {
db.test.single({ a: 1 }, (err, result) => {

@@ -217,15 +218,15 @@ expect(err).to.exist();

describe('count()', function () {
describe('count()', () => {
it('returns the number requested object', function (done) {
it('returns the number requested object', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.count({ a: 1 }, function (err, result) {
db.test.count({ a: 1 }, (err, result) => {

@@ -240,13 +241,13 @@ expect(err).to.not.exist();

it('returns the number of object with given field', function (done) {
it('returns the number of object with given field', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.count(db.fields(['a']), function (err, result) {
db.test.count(db.fields(['a']), (err, result) => {

@@ -262,11 +263,11 @@ expect(err).to.not.exist();

describe('insert()', function () {
describe('insert()', () => {
it('returns the generate key', function (done) {
it('returns the generate key', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ a: 1 }, function (err, keys) {
db.test.insert({ a: 1 }, (err, keys) => {

@@ -280,9 +281,9 @@ expect(err).to.not.exist();

it('returns the generate key (existing)', function (done) {
it('returns the generate key (existing)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 11, a: 1 }, function (err, keys) {
db.test.insert({ id: 11, a: 1 }, (err, keys) => {

@@ -296,9 +297,9 @@ expect(err).to.not.exist();

it('returns the generate keys', function (done) {
it('returns the generate keys', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ a: 1 }, { a: 2 }], function (err, keys) {
db.test.insert([{ a: 1 }, { a: 2 }], (err, keys) => {

@@ -312,9 +313,9 @@ expect(err).to.not.exist();

it('returns the generate keys when keys are present', function (done) {
it('returns the generate keys when keys are present', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { a: 2 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { a: 2 }], (err, keys) => {

@@ -329,9 +330,9 @@ expect(err).to.not.exist();

it('returns the generate keys when keys are present (last)', function (done) {
it('returns the generate keys when keys are present (last)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ a: 1 }, { id: 1, a: 2 }], function (err, keys) {
db.test.insert([{ a: 1 }, { id: 1, a: 2 }], (err, keys) => {

@@ -346,9 +347,9 @@ expect(err).to.not.exist();

it('returns the generate keys when keys are present (mixed)', function (done) {
it('returns the generate keys when keys are present (mixed)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ a: 1 }, { id: 1, a: 2 }, { id: 2, a: 3 }, { a: 4 }, { a: 5 }, { id: 3, a: 6 }, { id: 4, a: 7 }], function (err, keys) {
db.test.insert([{ a: 1 }, { id: 1, a: 2 }, { id: 2, a: 3 }, { a: 4 }, { a: 5 }, { id: 3, a: 6 }, { id: 4, a: 7 }], (err, keys) => {

@@ -367,19 +368,19 @@ expect(err).to.not.exist();

describe('update()', function () {
describe('update()', () => {
it('updates a record', function (done) {
it('updates a record', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {
expect(err).to.not.exist();
db.test.update(1, { a: 2 }, function (err) {
db.test.update(1, { a: 2 }, (err) => {
expect(err).to.not.exist();
db.test.get(1, function (err, item) {
db.test.get(1, (err, item) => {

@@ -395,10 +396,10 @@ expect(err).to.not.exist();

it('errors on unknown key', function (done) {
it('errors on unknown key', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.update(2, { a: 2 }, function (err) {
db.test.update(2, { a: 2 }, (err) => {

@@ -412,19 +413,19 @@ expect(err).to.exist();

describe('increment()', function () {
describe('increment()', () => {
it('updates a record', function (done) {
it('updates a record', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {
expect(err).to.not.exist();
db.test.increment(1, 'a', 5, function (err) {
db.test.increment(1, 'a', 5, (err) => {
expect(err).to.not.exist();
db.test.get(1, function (err, item) {
db.test.get(1, (err, item) => {

@@ -440,10 +441,10 @@ expect(err).to.not.exist();

it('errors on unknown key', function (done) {
it('errors on unknown key', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.increment(1, 'a', 5, function (err) {
db.test.increment(1, 'a', 5, (err) => {

@@ -457,19 +458,19 @@ expect(err).to.exist();

describe('append()', function () {
describe('append()', () => {
it('updates a record', function (done) {
it('updates a record', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: [1] }, function (err, keys) {
db.test.insert({ id: 1, a: [1] }, (err, keys) => {
expect(err).to.not.exist();
db.test.append(1, 'a', 5, function (err) {
db.test.append(1, 'a', 5, (err) => {
expect(err).to.not.exist();
db.test.get(1, function (err, item) {
db.test.get(1, (err, item) => {

@@ -485,10 +486,10 @@ expect(err).to.not.exist();

it('errors on unknown key', function (done) {
it('errors on unknown key', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.append(1, 'a', 5, function (err) {
db.test.append(1, 'a', 5, (err) => {

@@ -502,19 +503,19 @@ expect(err).to.exist();

describe('unset()', function () {
describe('unset()', () => {
it('updates a record', function (done) {
it('updates a record', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {
expect(err).to.not.exist();
db.test.unset(1, 'a', function (err) {
db.test.unset(1, 'a', (err) => {
expect(err).to.not.exist();
db.test.get(1, function (err, item) {
db.test.get(1, (err, item) => {

@@ -530,10 +531,10 @@ expect(err).to.not.exist();

it('errors on unknown key', function (done) {
it('errors on unknown key', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.unset(1, 'a', function (err) {
db.test.unset(1, 'a', (err) => {

@@ -547,19 +548,19 @@ expect(err).to.exist();

describe('remove()', function () {
describe('remove()', () => {
it('removes a record', function (done) {
it('removes a record', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {
expect(err).to.not.exist();
db.test.remove(1, function (err) {
db.test.remove(1, (err) => {
expect(err).to.not.exist();
db.test.get(1, function (err, item) {
db.test.get(1, (err, item) => {

@@ -575,17 +576,17 @@ expect(err).to.not.exist();

it('removes multiple records', function (done) {
it('removes multiple records', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.remove([1, 2], function (err) {
db.test.remove([1, 2], (err) => {
expect(err).to.not.exist();
db.test.count({ a: 1 }, function (err, count) {
db.test.count({ a: 1 }, (err, count) => {

@@ -601,17 +602,17 @@ expect(err).to.not.exist();

it('removes records using criteria', function (done) {
it('removes records using criteria', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.remove({ a: 1 }, function (err) {
db.test.remove({ a: 1 }, (err) => {
expect(err).to.not.exist();
db.test.count({ a: 1 }, function (err, count) {
db.test.count({ a: 1 }, (err, count) => {

@@ -627,10 +628,10 @@ expect(err).to.not.exist();

it('errors on unknown key', function (done) {
it('errors on unknown key', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.remove(1, function (err) {
db.test.remove(1, (err) => {

@@ -643,10 +644,10 @@ expect(err).to.exist();

it('ignored error on unknown keys', function (done) {
it('ignored error on unknown keys', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.remove([1], function (err) {
db.test.remove([1], (err) => {

@@ -660,18 +661,18 @@ expect(err).to.not.exist();

describe('_run()', function () {
describe('_run()', () => {
it('errors on invalid cursor', { parallel: false }, function (done) {
it('errors on invalid cursor', { parallel: false }, (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test._table.filter({ a: 1 }).run(db._connection, function (err, cursor) {
db.test._table.filter({ a: 1 }).run(db._connection, (err, cursor) => {
var proto = Object.getPrototypeOf(cursor);
var orig = proto.toArray;
const proto = Object.getPrototypeOf(cursor);
const orig = proto.toArray;
proto.toArray = function (callback) {

@@ -685,3 +686,3 @@

db.test.query({ a: 1 }, function (err, result) {
db.test.query({ a: 1 }, (err, result) => {

@@ -697,26 +698,23 @@ expect(err).to.exist();

describe('changes()', function () {
describe('changes()', () => {
it('reports on a record update (*)', function (done) {
it('reports on a record update (*)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const changes = [];
const each = (err, item) => changes.push(item.after.id);
changes.push(item.after.id);
};
db.test.changes('*', each, (err, cursor) => {
db.test.changes('*', each, function (err, cursor) {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {
expect(err).to.not.exist();
db.test.update(1, { a: 2 }, function (err) {
db.test.update(1, { a: 2 }, (err) => {

@@ -733,24 +731,21 @@ expect(err).to.not.exist();

it('manually closes a cursor', function (done) {
it('manually closes a cursor', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const changes = [];
const each = (err, item) => changes.push(item.after.id);
changes.push(item.after.id);
};
db.test.changes('*', each, (err, cursor) => {
db.test.changes('*', each, function (err, cursor) {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {
expect(err).to.not.exist();
db.test.update(1, { a: 2 }, function (err) {
db.test.update(1, { a: 2 }, (err) => {

@@ -768,28 +763,25 @@ expect(err).to.not.exist();

it('reports on a record update (id)', function (done) {
it('reports on a record update (id)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const changes = [];
const each = (err, item) => changes.push(item.after.id);
changes.push(item.after.id);
};
db.test.insert([{ id: 1, a: 1 }], (err, keys1) => {
db.test.insert([{ id: 1, a: 1 }], function (err, keys1) {
expect(err).to.not.exist();
db.test.changes(1, each, function (err, cursor) {
db.test.changes(1, each, (err, cursor) => {
expect(err).to.not.exist();
db.test.update(1, { a: 2 }, function (err, keys2) {
db.test.update(1, { a: 2 }, (err, keys2) => {
expect(err).to.not.exist();
db.test.insert({ id: 2, a: 2 }, function (err) {
db.test.insert({ id: 2, a: 2 }, (err) => {

@@ -807,28 +799,25 @@ expect(err).to.not.exist();

it('reports on a record update (ids)', function (done) {
it('reports on a record update (ids)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const changes = [];
const each = (err, item) => changes.push(item.after.id);
changes.push(item.after.id);
};
db.test.insert([{ id: 1, a: 1 }], (err, keys1) => {
db.test.insert([{ id: 1, a: 1 }], function (err, keys1) {
expect(err).to.not.exist();
db.test.changes([1, 2], each, function (err, cursor) {
db.test.changes([1, 2], each, (err, cursor) => {
expect(err).to.not.exist();
db.test.update(1, { a: 2 }, function (err, keys2) {
db.test.update(1, { a: 2 }, (err, keys2) => {
expect(err).to.not.exist();
db.test.insert({ id: 2, a: 2 }, function (err) {
db.test.insert({ id: 2, a: 2 }, (err) => {

@@ -846,28 +835,25 @@ expect(err).to.not.exist();

it('reports on a record update (query)', function (done) {
it('reports on a record update (query)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const changes = [];
const each = (err, item) => changes.push(item.after.id);
changes.push(item.after.id);
};
db.test.insert([{ id: 1, a: 1 }], (err, keys1) => {
db.test.insert([{ id: 1, a: 1 }], function (err, keys1) {
expect(err).to.not.exist();
db.test.changes({ a: 2 }, each, function (err, cursor) {
db.test.changes({ a: 2 }, each, (err, cursor) => {
expect(err).to.not.exist();
db.test.update(1, { a: 2 }, function (err, keys2) {
db.test.update(1, { a: 2 }, (err, keys2) => {
expect(err).to.not.exist();
db.test.insert({ id: 2, a: 2 }, function (err) {
db.test.insert({ id: 2, a: 2 }, (err) => {

@@ -885,24 +871,21 @@ expect(err).to.not.exist();

it('reports on a record update (delete)', function (done) {
it('reports on a record update (delete)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const changes = [];
const each = (err, item) => changes.push(item.before.id + ':' + (item.after === null));
changes.push(item.before.id + ':' + (item.after === null));
};
db.test.insert([{ id: 1, a: 1 }], (err, keys1) => {
db.test.insert([{ id: 1, a: 1 }], function (err, keys1) {
expect(err).to.not.exist();
db.test.changes(1, each, function (err, cursor) {
db.test.changes(1, each, (err, cursor) => {
expect(err).to.not.exist();
db.test.remove(1, function (err) {
db.test.remove(1, (err) => {

@@ -918,20 +901,17 @@ expect(err).to.not.exist();

it('reports on a record update (id missing)', function (done) {
it('reports on a record update (id missing)', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const changes = [];
const each = (err, item) => changes.push(item.after.id);
changes.push(item.after.id);
};
db.test.changes(1, each, (err, cursor) => {
db.test.changes(1, each, function (err, cursor) {
expect(err).to.not.exist();
db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {

@@ -946,11 +926,10 @@ expect(err).to.not.exist();

it('errors on bad cursor', function (done) {
it('errors on bad cursor', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
var changes = [];
var each = function (err, item) {
const each = (err, item) => {

@@ -963,8 +942,8 @@ if (err) {

db.test.changes('*', each, function (err, cursor) {
db.test.changes('*', each, (err, cursor) => {
expect(err).to.not.exist();
var orig = cursor._cursor._next;
cursor._cursor._next = function (next) {
const orig = cursor._cursor._next;
cursor._cursor._next = (next) => {

@@ -975,3 +954,3 @@ cursor._cursor._next = orig;

db.test.insert({ id: 1, a: 1 }, function (err, keys) {
db.test.insert({ id: 1, a: 1 }, (err, keys) => {

@@ -984,9 +963,9 @@ expect(err).to.not.exist();

it('errors on invalid table', function (done) {
it('errors on invalid table', (done) => {
var db = new Penseur.Db('penseurtest');
const db = new Penseur.Db('penseurtest');
db.table('invalid');
db.connect(function (err) {
db.connect((err) => {
db.invalid.changes('*', function (err, item) {
db.invalid.changes('*', (err, item) => {

@@ -1000,15 +979,15 @@ expect(err).to.exist();

describe('sync()', function () {
describe('sync()', () => {
it('returns when write is complete', function (done) {
it('returns when write is complete', (done) => {
var db = new Penseur.Db('penseurtest');
db.establish(['test'], function (err) {
const db = new Penseur.Db('penseurtest');
db.establish(['test'], (err) => {
expect(err).to.not.exist();
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], function (err, keys) {
db.test.insert([{ id: 1, a: 1 }, { id: 2, a: 2 }, { id: 3, a: 1 }], (err, keys) => {
expect(err).to.not.exist();
db.test.sync(function (err) {
db.test.sync((err) => {

@@ -1022,9 +1001,9 @@ expect(err).to.not.exist();

it('fails on database error', function (done) {
it('fails on database error', (done) => {
var db = new Penseur.Db('penseurtest');
const db = new Penseur.Db('penseurtest');
db.table('invalid');
db.connect(function (err) {
db.connect((err) => {
db.invalid.sync(function (err) {
db.invalid.sync((err) => {

@@ -1031,0 +1010,0 @@ expect(err).to.exist();

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