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 5.4.1 to 5.4.2

appveyor.yml

4

docs/api.md

@@ -91,3 +91,3 @@ # API

It's important to know that SQLite3 may sometimes rollback a transaction without us asking it to. This can happen either because of an [`ON CONFLICT`](https://sqlite.org/lang_conflict.html) clause, the [`RAISE()`](https://www.sqlite.org/lang_createtrigger.html) trigger function, or certain errors such as `SQLITE_FULL` or `SQLITE_BUSY`. When this occurs, transaction functions will automatically detect the situation and handle it appropriately. However, if you catch one of these errors with a try-catch statement, you become responsible for handling the case. In other words, all catch statements within transaction functions should look like this:
It's important to know that SQLite3 may sometimes rollback a transaction without us asking it to. This can happen either because of an [`ON CONFLICT`](https://sqlite.org/lang_conflict.html) clause, the [`RAISE()`](https://www.sqlite.org/lang_createtrigger.html) trigger function, or certain errors such as `SQLITE_FULL` or `SQLITE_BUSY`. In other words, if you catch an SQLite3 error *within* a transaction, you must be aware that any futher SQL that you execute might not be within the same transaction. Usually, the best course of action for such cases is to simply re-throw the error, exiting the transaction function.

@@ -103,4 +103,2 @@ ```js

> This situation generally only arises when checking for partial failures inside a nesting transaction.
### .pragma(*string*, [*options*]) -> *results*

@@ -107,0 +105,0 @@

@@ -11,4 +11,22 @@ # Troubleshooting installation

4. If you're using Windows, try running `npm install --global --production windows-build-tools --vs2015`. If that doesn't work, try assigning different versions of Visual Studio (e.g., `--vs2017, --vs2013`, etc.) until it works.
4. If you're using Windows, follow these steps. Do them **in this order**, and **don't skip steps**.
1. Install the **latest** of node 8, node 10, or node 12. Earlier versions of node (like 10.2.x) will not compile.
1. Start an Admin PowerShell: Right-click the start icon, then pick `Windows PowerShell (Admin)`
1. Install *both* vs2015 and vs2017 libraries. Each line will take ~5-10 minutes.
```sh
npm install --global --production --vs2015 --add-python-to-path windows-build-tools
npm install --global --production --add-python-to-path windows-build-tools node-gyp
```
1. In your project, make sure you're not fighting with old build configurations. Delete **both**
* your `%USERPROFILE%/.node-gyp` and
* your project's `node_modules` directories.
1. Set up `%USERPROFILE%/.npmrc` correctly:
```sh
msvs_version=2015
python=python2.7
```
(where `%USERPROFILE%` is your home directory).
1. Run `npm install` or `yarn install`
If none of these solved your problem, try browsing [previous issues](https://github.com/JoshuaWise/better-sqlite3/issues?q=is%3Aissue) or open a [new issue](https://github.com/JoshuaWise/better-sqlite3/issues/new).
{
"name": "better-sqlite3",
"version": "5.4.1",
"version": "5.4.2",
"description": "The fastest and simplest library for SQLite3 in Node.js.",

@@ -14,11 +14,11 @@ "homepage": "http://github.com/JoshuaWise/better-sqlite3",

"integer": "^2.1.0",
"tar": "^4.4.6"
"tar": "^4.4.10"
},
"devDependencies": {
"chai": "^4.2.0",
"cli-color": "^1.3.0",
"fs-extra": "^5.0.0",
"mocha": "^5.2.0",
"cli-color": "^1.4.0",
"fs-extra": "^8.1.0",
"mocha": "^6.2.0",
"nodemark": "^0.3.0",
"sqlite": "^2.9.3"
"sqlite": "^3.0.3"
},

@@ -32,3 +32,3 @@ "scripts": {

"rebuild-debug": "npm run lzz && node-gyp rebuild --debug",
"test": "$(npm bin)/mocha --exit --slow=75 --timeout=2000",
"test": "mocha --exit --slow=75 --timeout=5000",
"benchmark": "node benchmark"

@@ -35,0 +35,0 @@ },

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

# better-sqlite3 [![Build Status](https://travis-ci.org/JoshuaWise/better-sqlite3.svg?branch=master)](https://travis-ci.org/JoshuaWise/better-sqlite3)
# better-sqlite3 [![Build Status](https://travis-ci.org/JoshuaWise/better-sqlite3.svg?branch=master)](https://travis-ci.org/JoshuaWise/better-sqlite3) [![Build status](https://ci.appveyor.com/api/projects/status/ilk8hb8v95m54v6f/branch/master?svg=true)](https://ci.appveyor.com/project/JoshuaWise/better-sqlite3/branch/master)
The fastest and simplest library for SQLite3 in Node.js.

@@ -4,0 +5,0 @@

'use strict';
const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const chai = require('chai');
const isWindows = os.platform().startsWith('win');
const tempDir = path.join(__dirname, '..', 'temp');

@@ -13,2 +15,4 @@ let dbId = 0;

next: () => (++dbId, global.util.current()),
describeUnix: isWindows ? describe.skip : describe,
itUnix: isWindows ? it.skip : it,
};

@@ -15,0 +19,0 @@

@@ -6,27 +6,31 @@ 'use strict';

describe('new Database()', function () {
afterEach(function () {
if (this.db) this.db.close();
});
it('should throw when given invalid argument types', function () {
expect(() => new Database('', '')).to.throw(TypeError);
expect(() => new Database({}, '')).to.throw(TypeError);
expect(() => new Database({}, {})).to.throw(TypeError);
expect(() => new Database({})).to.throw(TypeError);
expect(() => new Database(0)).to.throw(TypeError);
expect(() => new Database(123)).to.throw(TypeError);
expect(() => new Database(new String(util.next()))).to.throw(TypeError);
expect(() => new Database(() => util.next())).to.throw(TypeError);
expect(() => new Database([util.next()])).to.throw(TypeError);
expect(() => (this.db = new Database('', ''))).to.throw(TypeError);
expect(() => (this.db = new Database({}, ''))).to.throw(TypeError);
expect(() => (this.db = new Database({}, {}))).to.throw(TypeError);
expect(() => (this.db = new Database({}))).to.throw(TypeError);
expect(() => (this.db = new Database(0))).to.throw(TypeError);
expect(() => (this.db = new Database(123))).to.throw(TypeError);
expect(() => (this.db = new Database(new String(util.next())))).to.throw(TypeError);
expect(() => (this.db = new Database(() => util.next()))).to.throw(TypeError);
expect(() => (this.db = new Database([util.next()]))).to.throw(TypeError);
});
it('should throw when boolean options are provided as non-booleans', function () {
expect(() => new Database(util.next(), { readOnly: false })).to.throw(TypeError);
expect(() => new Database(util.next(), { readonly: undefined })).to.throw(TypeError);
expect(() => new Database(util.next(), { memory: undefined })).to.throw(TypeError);
expect(() => new Database(util.next(), { fileMustExist: undefined })).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { readOnly: false }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { readonly: undefined }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { memory: undefined }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { fileMustExist: undefined }))).to.throw(TypeError);
});
it('should not allow URI file paths', function () {
expect(() => new Database(`FILE:${util.next()}`)).to.throw(TypeError);
expect(() => new Database(`file:${util.next()}`)).to.throw(TypeError);
expect(() => new Database(`file:${util.next()}?mode=memory&cache=shared`)).to.throw(TypeError);
expect(() => (this.db = new Database(`FILE:${util.next()}`))).to.throw(TypeError);
expect(() => (this.db = new Database(`file:${util.next()}`))).to.throw(TypeError);
expect(() => (this.db = new Database(`file:${util.next()}?mode=memory&cache=shared`))).to.throw(TypeError);
});
it('should allow anonymous temporary databases to be created', function () {
for (const args of [[''], [], [null], [undefined], ['', { timeout: 2000 }]]) {
const db = new Database(...args);
const db = this.db = new Database(...args);
expect(db.name).to.equal('');

@@ -45,3 +49,3 @@ expect(db.memory).to.be.true;

it('should allow anonymous in-memory databases to be created', function () {
const db = new Database(':memory:');
const db = this.db = new Database(':memory:');
expect(db.name).to.equal(':memory:');

@@ -53,7 +57,6 @@ expect(db.memory).to.be.true;

expect(existsSync(':memory:')).to.be.false;
db.close();
});
it('should allow named in-memory databases to be created', function () {
expect(existsSync(util.next())).to.be.false;
const db = new Database(util.current(), { memory: true });
const db = this.db = new Database(util.current(), { memory: true });
expect(db.name).to.equal(util.current());

@@ -65,7 +68,6 @@ expect(db.memory).to.be.true;

expect(existsSync(util.current())).to.be.false;
db.close();
});
it('should allow disk-bound databases to be created', function () {
expect(existsSync(util.next())).to.be.false;
const db = Database(util.current());
const db = this.db = Database(util.current());
expect(db.name).to.equal(util.current());

@@ -77,7 +79,6 @@ expect(db.memory).to.be.false;

expect(existsSync(util.current())).to.be.true;
db.close();
});
it('should not allow conflicting in-memory options', function () {
expect(() => new Database(':memory:', { memory: false })).to.throw(TypeError);
expect(() => new Database('', { memory: false })).to.throw(TypeError);
expect(() => (this.db = new Database(':memory:', { memory: false }))).to.throw(TypeError);
expect(() => (this.db = new Database('', { memory: false }))).to.throw(TypeError);
(new Database(':memory:', { memory: true })).close();

@@ -88,6 +89,6 @@ (new Database('', { memory: true })).close();

expect(existsSync(util.next())).to.be.false;
expect(() => new Database(util.current(), { readonly: true })).to.throw(Database.SqliteError).with.property('code', 'SQLITE_CANTOPEN');
expect(() => (this.db = new Database(util.current(), { readonly: true }))).to.throw(Database.SqliteError).with.property('code', 'SQLITE_CANTOPEN');
(new Database(util.current())).close();
expect(existsSync(util.current())).to.be.true;
const db = new Database(util.current(), { readonly: true });
const db = this.db = new Database(util.current(), { readonly: true });
expect(db.name).to.equal(util.current());

@@ -99,9 +100,8 @@ expect(db.memory).to.be.false;

expect(existsSync(util.current())).to.be.true;
db.close();
});
it('should not allow the "readonly" option for in-memory databases', function () {
expect(existsSync(util.next())).to.be.false;
expect(() => new Database(util.current(), { memory: true, readonly: true })).to.throw(TypeError);
expect(() => new Database(':memory:', { readonly: true })).to.throw(TypeError);
expect(() => new Database('', { readonly: true })).to.throw(TypeError);
expect(() => (this.db = new Database(util.current(), { memory: true, readonly: true }))).to.throw(TypeError);
expect(() => (this.db = new Database(':memory:', { readonly: true }))).to.throw(TypeError);
expect(() => (this.db = new Database('', { readonly: true }))).to.throw(TypeError);
expect(existsSync(util.current())).to.be.false;

@@ -111,6 +111,6 @@ });

expect(existsSync(util.next())).to.be.false;
expect(() => new Database(util.current(), { fileMustExist: true })).to.throw(Database.SqliteError).with.property('code', 'SQLITE_CANTOPEN');
expect(() => (this.db = new Database(util.current(), { fileMustExist: true }))).to.throw(Database.SqliteError).with.property('code', 'SQLITE_CANTOPEN');
(new Database(util.current())).close();
expect(existsSync(util.current())).to.be.true;
const db = new Database(util.current(), { fileMustExist: true });
const db = this.db = new Database(util.current(), { fileMustExist: true });
expect(db.name).to.equal(util.current());

@@ -122,15 +122,17 @@ expect(db.memory).to.be.false;

expect(existsSync(util.current())).to.be.true;
db.close();
});
it('should accept the "timeout" option', function () {
this.slow(2500);
util.itUnix('should accept the "timeout" option', function () {
this.slow(4000);
const testTimeout = (timeout) => {
const db = new Database(util.current(), { timeout });
const start = Date.now();
expect(() => db.exec('BEGIN EXCLUSIVE')).to.throw(Database.SqliteError).with.property('code', 'SQLITE_BUSY');
const end = Date.now();
expect(end - start).to.be.within(timeout - 100, timeout + 100);
db.close();
try {
const start = Date.now();
expect(() => db.exec('BEGIN EXCLUSIVE')).to.throw(Database.SqliteError).with.property('code', 'SQLITE_BUSY');
const end = Date.now();
expect(end - start).to.be.closeTo(timeout, 100);
} finally {
db.close();
}
};
const blocker = new Database(util.next(), { timeout: 0x7fffffff });
const blocker = this.db = new Database(util.next(), { timeout: 0x7fffffff });
blocker.exec('BEGIN EXCLUSIVE');

@@ -140,10 +142,9 @@ testTimeout(0);

blocker.close();
expect(() => new Database(util.current(), { timeout: undefined })).to.throw(TypeError);
expect(() => new Database(util.current(), { timeout: null })).to.throw(TypeError);
expect(() => new Database(util.current(), { timeout: NaN })).to.throw(TypeError);
expect(() => new Database(util.current(), { timeout: '75' })).to.throw(TypeError);
expect(() => new Database(util.current(), { timeout: -1 })).to.throw(TypeError);
expect(() => new Database(util.current(), { timeout: 75.01 })).to.throw(TypeError);
expect(() => new Database(util.current(), { timeout: 0x80000000 })).to.throw(RangeError);
blocker.close();
expect(() => (this.db = new Database(util.current(), { timeout: undefined }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.current(), { timeout: null }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.current(), { timeout: NaN }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.current(), { timeout: '75' }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.current(), { timeout: -1 }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.current(), { timeout: 75.01 }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.current(), { timeout: 0x80000000 }))).to.throw(RangeError);
});

@@ -153,3 +154,3 @@ it('should throw an Error if the directory does not exist', function () {

const filepath = `temp/nonexistent/abcfoobar123/${util.current()}`;
expect(() => new Database(filepath)).to.throw(TypeError);
expect(() => (this.db = new Database(filepath))).to.throw(TypeError);
expect(existsSync(filepath)).to.be.false;

@@ -159,3 +160,3 @@ expect(existsSync(util.current())).to.be.false;

it('should have a proper prototype chain', function () {
const db = new Database(util.next());
const db = this.db = new Database(util.next());
expect(db).to.be.an.instanceof(Database);

@@ -167,4 +168,3 @@ expect(db.constructor).to.equal(Database);

expect(Database.prototype).to.equal(Object.getPrototypeOf(db));
db.close();
});
});

@@ -52,26 +52,29 @@ 'use strict';

const other = new Database(util.current());
expect(this.db.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(this.db.inTransaction).to.be.false;
let ranOnce = false;
const trx = this.db.transaction((arg) => {
expect(this.db.inTransaction).to.be.true;
expect(arg).to.equal('foo');
this.db.prepare('INSERT INTO data VALUES (100)').run();
try {
expect(this.db.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(this.db.inTransaction).to.be.false;
let ranOnce = false;
const trx = this.db.transaction((arg) => {
expect(this.db.inTransaction).to.be.true;
expect(arg).to.equal('foo');
this.db.prepare('INSERT INTO data VALUES (100)').run();
expect(this.db.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3, 100]);
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
ranOnce = true;
expect(this.db.inTransaction).to.be.true;
return 'bar';
});
expect(ranOnce).to.be.false;
expect(this.db.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(this.db.inTransaction).to.be.false;
expect(trx('foo')).to.equal('bar');
expect(this.db.inTransaction).to.be.false;
expect(ranOnce).to.be.true;
expect(this.db.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3, 100]);
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
ranOnce = true;
expect(this.db.inTransaction).to.be.true;
return 'bar';
});
expect(ranOnce).to.be.false;
expect(this.db.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3]);
expect(this.db.inTransaction).to.be.false;
expect(trx('foo')).to.equal('bar');
expect(this.db.inTransaction).to.be.false;
expect(ranOnce).to.be.true;
expect(this.db.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3, 100]);
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3, 100]);
other.close();
expect(other.prepare('SELECT x FROM data').pluck().all()).to.deep.equal([1, 2, 3, 100]);
} finally {
other.close();
}
});

@@ -78,0 +81,0 @@ it('should rollback the transaction if an exception is thrown', function () {

'use strict';
const Database = require('../.');
describe('Database#loadExtension()', function () {
util.describeUnix('Database#loadExtension()', function () {
const filepath = require('path').join(__dirname, '../build/test_extension.node');

@@ -6,0 +6,0 @@ beforeEach(function () {

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

expect(existsSync(util.current())).to.be.true;
this.db.close();
this.db = new Database(util.current());

@@ -190,0 +191,0 @@ expect(this.db.prepare('SELECT bar FROM foo').pluck().all()).to.deep.equal([2, 8]);

@@ -20,6 +20,9 @@ 'use strict';

const db2 = new Database(util.next());
db2.prepare('CREATE TABLE entries (a INTEGER, b REAL, c TEXT)').run();
db2.prepare('INSERT INTO entries VALUES (?, ?, ?)').run(int, int, int);
db2.prepare('INSERT INTO entries VALUES (?, ?, ?)').bind(int, int, int).run();
db2.close();
try {
db2.prepare('CREATE TABLE entries (a INTEGER, b REAL, c TEXT)').run();
db2.prepare('INSERT INTO entries VALUES (?, ?, ?)').run(int, int, int);
db2.prepare('INSERT INTO entries VALUES (?, ?, ?)').bind(int, int, int).run();
} finally {
db2.close();
}
});

@@ -26,0 +29,0 @@ it('should be allowed as a return value in user-defined functions', function () {

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

describe('Database#loadExtension()', function () {
util.describeUnix('Database#loadExtension()', function () {
const filepath = require('path').join(__dirname, '../build/test_extension.node');

@@ -171,0 +171,0 @@ specify('while iterating (blocked)', function () {

@@ -6,13 +6,17 @@ 'use strict';

describe('verbose mode', function () {
afterEach(function () {
if (this.db) this.db.close();
});
it('should throw when not given a function or null/undefined', function () {
expect(() => new Database(util.next(), { verbose: false })).to.throw(TypeError);
expect(() => new Database(util.next(), { verbose: true })).to.throw(TypeError);
expect(() => new Database(util.next(), { verbose: 123 })).to.throw(TypeError);
expect(() => new Database(util.next(), { verbose: 'null' })).to.throw(TypeError);
expect(() => new Database(util.next(), { verbose: {} })).to.throw(TypeError);
expect(() => new Database(util.next(), { verbose: [] })).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { verbose: false }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { verbose: true }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { verbose: 123 }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { verbose: 'null' }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { verbose: {} }))).to.throw(TypeError);
expect(() => (this.db = new Database(util.next(), { verbose: [] }))).to.throw(TypeError);
});
it('should allow explicit null or undefined as a no-op', function () {
for (const verbose of [undefined, null]) {
const db = new Database(util.next(), { verbose });
const db = this.db = new Database(util.next(), { verbose });
db.exec('select 5');

@@ -27,3 +31,3 @@ db.close();

}
const db = new Database(util.next(), { verbose });
const db = this.db = new Database(util.next(), { verbose });
const stmt = db.prepare('select ?');

@@ -52,3 +56,2 @@ db.exec('select 5');

]);
db.close();
});

@@ -60,3 +63,3 @@ it('should not fully expand very long bound parameter', function () {

}
const db = new Database(util.next(), { verbose });
const db = this.db = new Database(util.next(), { verbose });
const stmt = db.prepare('select ?');

@@ -71,3 +74,2 @@ stmt.get('this is a fairly short parameter');

]);
db.close();
});

@@ -78,3 +80,3 @@ it('should abort the execution if the logger function throws', function () {

const err = new Error('foo');
const db = new Database(util.next(), { verbose: () => { if (fail) throw err; } });
const db = this.db = new Database(util.next(), { verbose: () => { if (fail) throw err; } });
db.prepare('create table data (x)').run();

@@ -81,0 +83,0 @@ db.function('fn', (value) => {

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