Socket
Socket
Sign inDemoInstall

better-sqlite3

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-sqlite3 - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

custom.js

3

benchmark/index.js

@@ -34,3 +34,4 @@ 'use strict';

function getTrials() {
return process.argv.slice(2).reduce(filterByArgs, require('./trials').map(addSearchTerms));
if (process.argv.length === 2) {return require('./trials').default.map(addSearchTerms);}
return process.argv.slice(2).reduce(filterByArgs, require('./trials').searchable.map(addSearchTerms));

@@ -37,0 +38,0 @@ function addSearchTerms(trial) {

'use strict';
module.exports = [
exports.default = [
{type: 'select', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'select-all', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'select-each', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'insert', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = WAL']},
{type: 'insert', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = DELETE']},
{type: 'transaction', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = WAL']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'nul'], pragma: ['journal_mode = DELETE']}
];
exports.searchable = [
{type: 'select', table: 'allSmall', columns: ['integer']},

@@ -45,15 +56,11 @@ {type: 'select', table: 'allSmall', columns: ['real']},

{type: 'transaction', table: 'textLarge', columns: ['text']},
{type: 'transaction', table: 'blobLarge', columns: ['blob']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'blob', 'nul'], pragma: ['journal_mode = WAL']},
{type: 'real-world', table: 'allSmall', columns: ['integer', 'real', 'text', 'blob', 'nul'], pragma: ['journal_mode = DELETE']}
{type: 'transaction', table: 'blobLarge', columns: ['blob']}
];
if (/^(1|true|on|yes)$/i.test(process.env.NO_CACHE)) {
module.exports.forEach(function (trial) {
trial.pragma = ['cache_size = 0'].concat(trial.pragma || []);
(function () {
var cacheSize = /^(1|true|on|yes)$/i.test(process.env.NO_CACHE) ? 'cache_size = 0' : 'cache_size = -16000';
var trials = [].concat.apply([], Object.keys(exports).map(function (key) {return exports[key];}));
trials.forEach(function (trial) {
trial.pragma = [cacheSize].concat(trial.pragma || []);
});
} else {
module.exports.forEach(function (trial) {
trial.pragma = ['cache_size = -16000'].concat(trial.pragma || []);
});
}
}());

@@ -10,10 +10,7 @@ 'use strict';

var stmt = betterSqlite3.prepare(SQL);
var betterSqlite3Insert = betterSqlite3.prepare(SQL);
benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).run(data);
betterSqlite3Insert.run(data);
});
benchmark.add(' + optimized', function () {
stmt.run(data);
});
benchmark.add('node-sqlite3', function (deferred) {

@@ -20,0 +17,0 @@ nodeSqlite3.run(SQL, data).then(function () {deferred.resolve();});

@@ -10,12 +10,8 @@ 'use strict';

var stmt = betterSqlite3.prepare(SQL).pluck();
var betterSqlite3Select = betterSqlite3.prepare(SQL);
benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).all(rowid % 1000 - 98);
betterSqlite3Select.all(rowid % 1000 - 98);
rowid += 100;
});
benchmark.add(' + optimized', function () {
stmt.all(rowid % 1000 - 98);
rowid += 100;
});
benchmark.add('node-sqlite3', function (deferred) {

@@ -22,0 +18,0 @@ nodeSqlite3.all(SQL, rowid % 1000 - 98).then(function () {deferred.resolve();});

@@ -10,12 +10,8 @@ 'use strict';

var stmt = betterSqlite3.prepare(SQL).pluck();
var betterSqlite3Select = betterSqlite3.prepare(SQL);
benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).each(rowid % 1000 - 98, function () {});
betterSqlite3Select.each(rowid % 1000 - 98, function () {});
rowid += 100;
});
benchmark.add(' + optimized', function () {
stmt.each(rowid % 1000 - 98, function () {});
rowid += 100;
});
benchmark.add('node-sqlite3', function (deferred) {

@@ -22,0 +18,0 @@ nodeSqlite3.each(SQL, rowid % 1000 - 98, function () {}).then(function () {deferred.resolve();});

@@ -10,10 +10,7 @@ 'use strict';

var stmt = betterSqlite3.prepare(SQL).pluck();
var betterSqlite3Select = betterSqlite3.prepare(SQL);
benchmark.add('better-sqlite3', function () {
betterSqlite3.prepare(SQL).get(rowid++ % 1000 + 1);
betterSqlite3Select.get(rowid++ % 1000 + 1);
});
benchmark.add(' + optimized', function () {
stmt.get(rowid++ % 1000 + 1);
});
benchmark.add('node-sqlite3', function (deferred) {

@@ -20,0 +17,0 @@ nodeSqlite3.get(SQL, rowid++ % 1000 + 1).then(function () {deferred.resolve();});

@@ -10,10 +10,7 @@ 'use strict';

var transaction = betterSqlite3.transaction(new Array(100).fill(SQL));
var betterSqlite3Transaction = betterSqlite3.transaction(new Array(100).fill(SQL));
benchmark.add('better-sqlite3', function () {
betterSqlite3.transaction(new Array(100).fill(SQL)).run(data);
betterSqlite3Transaction.run(data);
});
benchmark.add(' + optimized', function () {
transaction.run(data);
});
benchmark.add('node-sqlite3', function (deferred) {

@@ -20,0 +17,0 @@ var count = 0;

@@ -47,2 +47,28 @@ 'use strict';

var createFunction = CPPDatabase.prototype.register;
CPPDatabase.prototype.register = function register(options, func) {
if (typeof options === 'function') {
func = options;
}
if (typeof options !== 'object' || options === null) {
options = {};
}
if (typeof func !== 'function') {
throw new TypeError('Expected argument 2 to be a function.');
}
var name = 'name' in options ? options.name : func.name;
var defaultSafeIntegers = !('safeIntegers' in options);
var deterministic = getOption(options, 'deterministic');
var safeIntegers = getOption(options, 'safeIntegers');
var varargs = getOption(options, 'varargs');
var argCount = func.length;
if (typeof name !== 'string') {
throw new TypeError('Expected the "name" option to be a string.');
}
if (!varargs && typeof argCount !== 'number') {
throw new TypeError('Expected function.length to be a number.');
}
return createFunction.call(this, func, name, deterministic, defaultSafeIntegers, varargs, safeIntegers, argCount);
};
function pathExists(path) {

@@ -53,2 +79,9 @@ try {fs.accessSync(path); return true;}

function getOption(options, key) {
if (key in options && typeof options[key] !== 'boolean') {
throw new TypeError('Expected the "' + key + '" option to be a boolean.');
}
return !!options[key];
}
CPPDatabase.prototype.constructor = Database;

@@ -55,0 +88,0 @@ Database.prototype = Object.create(Object.prototype, toDescriptor(CPPDatabase.prototype));

{
"name": "better-sqlite3",
"version": "2.2.0",
"version": "2.3.0",
"description": "The fastest and simplest library for SQLite3 in Node.js.",

@@ -5,0 +5,0 @@ "homepage": "http://github.com/JoshuaWise/better-sqlite3",

@@ -12,6 +12,6 @@ # better-sqlite3 [![Build Status](https://travis-ci.org/JoshuaWise/better-sqlite3.svg?branch=master)](https://travis-ci.org/JoshuaWise/better-sqlite3)

| |select 1 row `get()`|select 1000 rows `all()`|select 1000 rows `each()`|insert 1 row|insert 5000 rows in a transaction|
| |select 1 row `get()`|select 100 rows `all()`|select 100 rows `each()`|insert 1 row `run()`|insert 100 rows in a transaction|
|---|---|---|---|---|---|
|better-sqlite3|1x|1x|1x|1x|1x|
|[sqlite](https://www.npmjs.com/package/sqlite) and [sqlite3](https://www.npmjs.com/package/sqlite3)|2.2x slower|2.9x slower|45x slower|1.4x slower|5.5x slower|
|[sqlite](https://www.npmjs.com/package/sqlite) and [sqlite3](https://www.npmjs.com/package/sqlite3)|7.6x slower|2.9x slower|3.2x slower|1.6x slower|7.2x slower|

@@ -18,0 +18,0 @@ > You can verify these results by [running the benchmark yourself](https://github.com/JoshuaWise/better-sqlite3/wiki/Benchmark).

@@ -35,3 +35,3 @@ var expect = require('chai').expect;

var rows = db.prepare('SELECT * FROM entries').all();
var rows = db.prepare('SELECT * FROM entries ORDER BY rowid').all();
expect(rows.length).to.equal(2);

@@ -38,0 +38,0 @@ expect(rows[0].a).to.equal('foobar');

@@ -29,11 +29,11 @@ 'use strict';

var stmt = db.prepare("SELECT * FROM entries");
var stmt = db.prepare("SELECT * FROM entries ORDER BY rowid");
expect(stmt.returnsData).to.be.true;
expect(stmt.get()).to.deep.equal({a: 'foo', b: 1, c: 3.14, d: bufferOfSize(4).fill(0xdd), e: null});
stmt = db.prepare("SELECT * FROM entries WHERE b > 5");
stmt = db.prepare("SELECT * FROM entries WHERE b > 5 ORDER BY rowid");
expect(stmt.get()).to.deep.equal({a: 'foo', b: 6, c: 3.14, d: bufferOfSize(4).fill(0xdd), e: null});
});
it('should obey the current pluck setting', function () {
var stmt = db.prepare("SELECT * FROM entries");
var stmt = db.prepare("SELECT * FROM entries ORDER BY rowid");
var row = {a: 'foo', b: 1, c: 3.14, d: bufferOfSize(4).fill(0xdd), e: null};

@@ -40,0 +40,0 @@ expect(stmt.get()).to.deep.equal(row);

@@ -30,7 +30,7 @@ 'use strict';

var stmt = db.prepare("SELECT * FROM entries");
var stmt = db.prepare("SELECT * FROM entries ORDER BY rowid");
expect(stmt.returnsData).to.be.true;
matchesFrom(stmt.all(), 1);
stmt = db.prepare("SELECT * FROM entries WHERE b > 5");
stmt = db.prepare("SELECT * FROM entries WHERE b > 5 ORDER BY rowid");
matchesFrom(stmt.all(), 6);

@@ -37,0 +37,0 @@

@@ -39,3 +39,3 @@ 'use strict';

var count = 0;
var stmt = db.prepare("SELECT * FROM entries");
var stmt = db.prepare("SELECT * FROM entries ORDER BY rowid");
expect(stmt.returnsData).to.be.true;

@@ -50,3 +50,3 @@ var ret = stmt.each(function (data) {

count = 0;
stmt = db.prepare("SELECT * FROM entries WHERE b > 5");
stmt = db.prepare("SELECT * FROM entries WHERE b > 5 ORDER BY rowid");
ret = stmt.each(function (data) {

@@ -61,3 +61,3 @@ row.b = ++count + 5;

var row = {a: 'foo', b: 1, c: 3.14, d: bufferOfSize(4).fill(0xdd), e: null};
var stmt = db.prepare("SELECT * FROM entries");
var stmt = db.prepare("SELECT * FROM entries ORDER BY rowid");
shouldHave(row);

@@ -86,12 +86,12 @@ stmt.pluck(true);

});
it('should obey the pluck setting even if it changed inside the callback', function () {
it('should not be able to invoke .pluck() while the database is busy', function () {
var stmt1 = db.prepare("SELECT * FROM entries");
var stmt2 = db.prepare("SELECT * FROM entries LIMIT 2");
var i = 0;
var stmt = db.prepare("SELECT * FROM entries");
stmt.each(function (data) {
if (++i % 2) {
expect(data).to.be.an('object');
} else {
expect(data).to.be.a('string');
}
stmt.pluck(i % 2 ? true : false);
stmt1.each(function () {
++i;
expect(function () {stmt1.pluck();}).to.throw(TypeError);
expect(function () {stmt2.pluck();}).to.throw(TypeError);
expect(function () {stmt1.pluck(false);}).to.throw(TypeError);
expect(function () {stmt2.pluck(false);}).to.throw(TypeError);
});

@@ -98,0 +98,0 @@ expect(i).to.equal(10);

@@ -88,2 +88,6 @@ var expect = require('chai').expect;

});
it('should be allowed as a return value in registered functions', function () {
db.register(function returnsInt64(a) {return new Int64(a + a);});
expect(db.prepare('SELECT returnsInt64(?)').pluck().get(42)).to.equal(84);
});
it('should get returned by operations after setting .safeIntegers()', function () {

@@ -107,41 +111,30 @@ var int = new Int64(4243423, 234234234);

expect(stmt.safeIntegers().get()).to.equal('1006028374637854687');
var lastRowid = db.prepare('SELECT rowid FROM entries ORDER BY rowid DESC').pluck().get();
stmt = db.prepare('INSERT INTO entries VALUES (?, ?, ?)');
expect(stmt.run(int, int, int).lastInsertROWID).to.equal(++lastRowid);
expect(stmt.safeIntegers().run(int, int, int).lastInsertROWID).to.deep.equal(new Int64(++lastRowid));
expect(stmt.run(int, int, int).lastInsertROWID).to.deep.equal(new Int64(++lastRowid));
expect(stmt.safeIntegers(false).run(int, int, int).lastInsertROWID).to.equal(++lastRowid);
var trans = db.transaction(['INSERT INTO entries VALUES (?, ?, ?)']);
expect(trans.run(int, int, int).lastInsertROWID).to.equal(++lastRowid);
expect(trans.safeIntegers().run(int, int, int).lastInsertROWID).to.deep.equal(new Int64(++lastRowid));
expect(trans.run(int, int, int).lastInsertROWID).to.deep.equal(new Int64(++lastRowid));
expect(trans.safeIntegers(false).run(int, int, int).lastInsertROWID).to.equal(++lastRowid);
});
it('should react to changing settings inside an .each() callback', function () {
var int = new Int64(4243423, 234234234);
var stmt = db.prepare('SELECT * FROM entries');
var count = 0;
stmt.each(function (row) {
expect(row.b).to.equal(1006028374637854700);
expect(row.c).to.equal('1006028374637854687');
if (++count % 2) {
expect(row.a).to.equal(1006028374637854700);
} else {
expect(row.a).to.deep.equal(int);
}
stmt.safeIntegers(count % 2 ? true : false);
});
expect(count).to.equal(4);
it('should get passed to functions registered with the "safeIntegers" option', function () {
db.register({safeIntegers: true}, function customfunc(a) {return a.low;});
expect(db.prepare('SELECT customfunc(?)').pluck().get(2)).to.equal(null);
expect(db.prepare('SELECT customfunc(?)').pluck().get(new Int64(2, 2))).to.equal(2);
});
it('should be safe from other databases inside an .each() callback', function () {
it('should be able to change the default setting on the database', function () {
var arg;
var int = new Int64(4243423, 234234234);
var stmt = db.prepare('SELECT a FROM entries').safeIntegers();
var stmt2 = db2.prepare('SELECT a FROM entries');
var count = 0;
stmt.each(function (row) {
++count;
expect(row.a).to.deep.equal(int);
var subcount = 0;
stmt2.safeIntegers(false).each(function (row) {
++subcount;
expect(row.a).to.equal(1006028374637854700);
});
expect(subcount).to.equal(4);
});
expect(count).to.equal(4);
});
it('should be able to change the default setting on the database', function () {
function customFunctionArg(options, dontRegister) {
dontRegister || db.register(options, function (a) {arg = a;});
db.prepare('SELECT ' + options.name + '(?)').get(int);
return arg;
}
db.defaultSafeIntegers(true);
var int = new Int64(4243423, 234234234);

@@ -151,2 +144,4 @@ var stmt = db.prepare('SELECT a FROM entries').pluck();

expect(stmt.safeIntegers(false).get()).to.equal(1006028374637854700);
expect(customFunctionArg({name: 'a1'})).to.deep.equal(int);
expect(customFunctionArg({name: 'a2', safeIntegers: false})).to.equal(1006028374637854700);

@@ -158,2 +153,4 @@ db.defaultSafeIntegers(false);

expect(stmt2.safeIntegers().get()).to.deep.equal(int);
expect(customFunctionArg({name: 'a3'})).to.equal(1006028374637854700);
expect(customFunctionArg({name: 'a4', safeIntegers: true})).to.deep.equal(int);

@@ -164,2 +161,6 @@ db.defaultSafeIntegers();

expect(stmt2.get()).to.deep.equal(int);
expect(customFunctionArg({name: 'a1'}, true)).to.deep.equal(int);
expect(customFunctionArg({name: 'a2'}, true)).to.equal(1006028374637854700);
expect(customFunctionArg({name: 'a3'}, true)).to.equal(1006028374637854700);
expect(customFunctionArg({name: 'a4'}, true)).to.deep.equal(int);

@@ -169,3 +170,18 @@ var stmt3 = db.prepare('SELECT a FROM entries').pluck();

expect(stmt3.safeIntegers(false).get()).to.equal(1006028374637854700);
expect(customFunctionArg({name: 'a5'})).to.deep.equal(int);
expect(customFunctionArg({name: 'a6', safeIntegers: false})).to.equal(1006028374637854700);
});
it('should not be able to invoke .safeIntegers() while the database is busy', function () {
var ranOnce = false;
var stmt1 = db.prepare('SELECT * FROM entries LIMIT 10');
var stmt2 = db.prepare('INSERT INTO entries VALUES (?, ?, ?)');
stmt1.each(function () {
ranOnce = true;
expect(function () {stmt1.safeIntegers();}).to.throw(TypeError);
expect(function () {stmt2.safeIntegers();}).to.throw(TypeError);
expect(function () {stmt1.safeIntegers(false);}).to.throw(TypeError);
expect(function () {stmt2.safeIntegers(false);}).to.throw(TypeError);
});
expect(ranOnce).to.be.true;
});
});

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 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 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 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 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 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 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 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 not supported yet

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