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

benchmark/trials/0.prepare.js

38

benchmark/fill-table.js
'use strict';
var OurDatabase = require('../.');
module.exports = function (db, count, SQL, values, callback) {
if (db.pragma) {
var run = function (values, cb) {
cb(null, db.prepare(SQL).run(values));
};
} else {
var run = function (values, cb) {
db.run(SQL, values, cb);
};
if (db instanceof OurDatabase) {
db.transaction(new Array(count).fill(SQL)).run(values);
callback();
return;
}
var ranCount = 0;
for (var i=0; i<count; ++i) {
run(values, ran);
// node-sqlite3 requires the "@" character for named parameters.
var obj = {};
for (var key in values) {
obj['@' + key] = values[key];
}
function ran(err) {
if (err) {
console.log('Error: Failed to fill table.');
var checkForError = function (err) {
if (err) {throw err;}
};
db.serialize(function () {
db.run('BEGIN TRANSACTION;', checkForError);
for (var i=0; i<count; ++i) {
db.run(SQL, obj, checkForError);
}
if (++ranCount === count) {
db.run('COMMIT TRANSACTION;', function (err) {
checkForError(err);
callback();
}
}
});
});
};

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

function created() {
if (++createdCount === 2) {
if (++createdCount === 8) {
console.log(clc.magenta('--- Benchmarks ---'));

@@ -33,27 +33,37 @@ next();

require('./create-table')('CREATE TABLE entries (aaaa TEXT, bbbb INTEGER, cccc FLOAT, dddd TEXT, eeee INTEGER, ffff BLOB)', 'select-db', function (ourDb, theirDb) {
var values = [
'John Smith',
524,
0.324176234,
'New York City',
20,
Buffer.alloc(1024 * 1024).fill(0xdd)
];
require('./create-table')('CREATE TABLE entries (text TEXT, integer INTEGER, real REAL, blob BLOB, nul)', 'select-small', fillSmallDataTable);
require('./create-table')('CREATE TABLE entries (text TEXT, blob BLOB)', 'select-large', function (ourDb, theirDb) {
var bigString = '';
while (bigString.length < 1024 * 1024) {
bigString += 'John Peter Smith';
}
var values = {
a: bigString,
b: Buffer.alloc(1024 * 1024).fill(0xdd)
};
var filledCount = 0;
function filled() {++filledCount === 2 && created();}
require('./fill-table')(ourDb, 1000, 'INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?)', values, filled);
require('./fill-table')(theirDb, 1000, 'INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?)', values, filled);
require('./fill-table')(ourDb, 1000, 'INSERT INTO entries VALUES (@a, @b)', values, filled);
require('./fill-table')(theirDb, 1000, 'INSERT INTO entries VALUES (@a, @b)', values, filled);
});
require('./create-table')('CREATE TABLE entries (name TEXT, number INTEGER, data BLOB)', 'insert-db', function (ourDb, theirDb) {
var values = [
'John Smith',
524,
null
];
require('./create-table')('CREATE TABLE entries (data TEXT)', 'insert-text', created);
require('./create-table')('CREATE TABLE entries (data INTEGER)', 'insert-integer', created);
require('./create-table')('CREATE TABLE entries (data REAL)', 'insert-real', created);
require('./create-table')('CREATE TABLE entries (data BLOB)', 'insert-blob', created);
require('./create-table')('CREATE TABLE entries (data)', 'insert-null', created);
require('./create-table')('CREATE TABLE entries (text TEXT, integer INTEGER, real REAL, blob BLOB, nul)', 'real-world', fillSmallDataTable);
function fillSmallDataTable(ourDb, theirDb) {
var values = {
a: 'John Peter Smith',
b: 12345,
c: 0.12345,
d: Buffer.alloc(16).fill(0xdd),
e: null
};
var filledCount = 0;
function filled() {++filledCount === 2 && created();}
require('./fill-table')(ourDb, 1000, 'INSERT INTO entries VALUES (?, ?, ?)', values, filled);
require('./fill-table')(theirDb, 1000, 'INSERT INTO entries VALUES (?, ?, ?)', values, filled);
});
require('./fill-table')(ourDb, 1000, 'INSERT INTO entries VALUES (@a, @b, @c, @d, @e)', values, filled);
require('./fill-table')(theirDb, 1000, 'INSERT INTO entries VALUES (@a, @b, @c, @d, @e)', values, filled);
}

@@ -71,3 +81,8 @@ function next() {

var child = spawn('node', ['--expose-gc', path.join(__dirname, 'trials', trialName)], {stdio: 'inherit'});
child.on('exit', function () {setTimeout(next, 100);});
child.on('exit', function (code) {
if (code !== 0) {
console.log(clc.red('ERROR (probably out of memory)'));
}
setTimeout(next, 100);
});
}
{
"name": "better-sqlite3",
"version": "1.2.0",
"version": "1.2.1",
"description": "The fastest and simplest library for SQLite3 in Node.js.",

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

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

- `node-sqlite3` uses asynchronous APIs for tasks that don't involve I/O. That's not only bad design, but it wastes tons of resources.
- `node-sqlite3` uses asynchronous APIs for tasks that don't wait for I/O. That's not only bad design, but it wastes tons of resources.
- `node-sqlite3` exposes low-level (C language) memory management functions. `better-sqlite3` does it the JavaScript way, allowing the garbage collector to worry about memory management.

@@ -33,0 +33,0 @@ - `better-sqlite3` is simpler to use, and it provides nice utilities for some operations that are very difficult or impossible in `node-sqlite3`.

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

while (row = db.prepare('SELECT * FROM entries WHERE rowid=' + ++i).get()) {
expect(row).to.deep.equal({a: 'foo', b: 25, c: 25, d: Buffer.alloc(8).fill(0xdd)})
expect(row).to.deep.equal({a: 'foo', b: 25, c: 25, d: Buffer.alloc(8).fill(0xdd)});
}

@@ -135,0 +135,0 @@ expect(i).to.equal(9);

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

while (row = db.prepare('SELECT * FROM entries WHERE rowid=' + ++i).get()) {
expect(row).to.deep.equal({a: 'foo', b: 25, c: 25, d: Buffer.alloc(8).fill(0xdd)})
expect(row).to.deep.equal({a: 'foo', b: 25, c: 25, d: Buffer.alloc(8).fill(0xdd)});
}

@@ -191,0 +191,0 @@ expect(i).to.equal(17);

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