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.1.1 to 1.1.2

test/13.database.prepare.js

4

package.json
{
"name": "better-sqlite3",
"version": "1.1.1",
"version": "1.1.2",
"description": "The fastest and simplest library for SQLite3 in Node.js.",

@@ -26,3 +26,3 @@ "homepage": "http://github.com/JoshuaWise/better-sqlite3",

"install": "if [ \"$CI\" = \"true\" ]; then node-gyp rebuild --debug; else node-gyp rebuild; fi;",
"test": "$(npm bin)/mocha --timeout 5000 --slow 5000",
"test": "$(npm bin)/mocha --bail --timeout 5000 --slow 5000",
"pretest": "rm -r ./temp/ || true && mkdir ./temp/",

@@ -29,0 +29,0 @@ "posttest": "rm -r ./temp/",

var expect = require('chai').expect;
var fs = require('fs');
var Database = require('../.');
var util = require('../tools/test-util.js');

@@ -11,5 +12,5 @@ describe('new Database()', function () {

expect(function () {new Database(123);}).to.throw(TypeError);
expect(function () {new Database(new String('temp/10.1.db'));}).to.throw(TypeError);
expect(function () {new Database(new String(util.next()));}).to.throw(TypeError);
expect(function () {new Database(function () {});}).to.throw(TypeError);
expect(function () {new Database(['temp/10.2.db']);}).to.throw(TypeError);
expect(function () {new Database([util.next()]);}).to.throw(TypeError);
});

@@ -20,4 +21,4 @@ it('should throw an exception when file path is empty', function () {

it('should not allow URI file paths', function () {
expect(function () {new Database('file:temp/10.3.db');}).to.throw(TypeError);
expect(function () {new Database('file:temp/10.4.db?mode=memory');}).to.throw(TypeError);
expect(function () {new Database('file:' + util.next());}).to.throw(TypeError);
expect(function () {new Database('file:' + util.next() + '?mode=memory&cache=shared');}).to.throw(TypeError);
});

@@ -28,7 +29,9 @@ it('should not allow ":memory:" databases', function () {

it('should allow disk-based databases to be created', function (done) {
expect(function () {fs.accessSync('temp/10.5.db');}).to.throw(Error);
var db = new Database('temp/10.5.db');
expect(function () {fs.accessSync(util.next());}).to.throw(Error);
var db = new Database(util.current());
expect(db.name).to.equal(util.current());
expect(db.memory).to.be.false;
expect(db.open).to.be.false;
db.on('open', function () {
fs.accessSync('temp/10.5.db');
fs.accessSync(util.current());
expect(db.open).to.be.true;

@@ -39,7 +42,9 @@ done();

it('should allow in-memory databases to be created', function (done) {
expect(function () {fs.accessSync('temp/10.6.db');}).to.throw(Error);
var db = new Database('temp/10.6.db', {memory: true});
expect(function () {fs.accessSync(util.next());}).to.throw(Error);
var db = new Database(util.current(), {memory: true});
expect(db.name).to.equal(util.current());
expect(db.memory).to.be.true;
expect(db.open).to.be.false;
db.on('open', function () {
expect(function () {fs.accessSync('temp/10.6.db');}).to.throw(Error);
expect(function () {fs.accessSync(util.current());}).to.throw(Error);
expect(db.open).to.be.true;

@@ -49,4 +54,16 @@ done();

});
it('should not allow the database to be used before it opens', function (done) {
var db = new Database(util.next());
expect(db.open).to.be.false;
expect(function () {db.prepare('CREATE TABLE people (name TEXT)');}).to.throw(Error);
expect(function () {db.transaction(['CREATE TABLE people (name TEXT)']);}).to.throw(Error);
expect(function () {db.pragma('cache_size');}).to.throw(Error);
expect(function () {db.checkpoint();}).to.throw(Error);
db.on('open', function () {
expect(db.open).to.be.true;
done();
});
});
it('should have a proper prototype chain', function () {
var db = new Database('temp/10.7.db');
var db = new Database(util.next());
expect(db).to.be.an.instanceof(Database);

@@ -53,0 +70,0 @@ expect(db.constructor).to.equal(Database);

var expect = require('chai').expect;
var Database = require('../.');
var util = require('../tools/test-util.js');

@@ -7,3 +8,3 @@ describe('Database#close()', function () {

it('should never emit the "open" event', function (done) {
var db = new Database('temp/11.1.db');
var db = new Database(util.next());
expect(db.open).to.be.false;

@@ -24,3 +25,4 @@ db.on('open', function () {

it('should have an Error object as its first parameter', function (done) {
var db = new Database('temp/nonexistent/abcfoobar123/11.2.db');
var db = new Database('temp/nonexistent/abcfoobar123/' + util.next());
expect(db.open).to.be.false;
db.on('open', function () {

@@ -38,3 +40,3 @@ done(new Error('This event should not have been fired.'));

it('should emit the close event as normal', function (done) {
var db = new Database('temp/11.3.db');
var db = new Database(util.next());
expect(db.open).to.be.false;

@@ -52,3 +54,19 @@ db.on('open', function () {

});
it('should prevent any further database operations', function (done) {
var db = new Database(util.next());
db.on('open', function () {
expect(db.open).to.be.true;
db.close();
db.on('close', function (err) {
expect(err).to.be.null;
expect(db.open).to.be.false;
expect(function () {db.prepare('CREATE TABLE people (name TEXT)');}).to.throw(Error);
expect(function () {db.transaction(['CREATE TABLE people (name TEXT)']);}).to.throw(Error);
expect(function () {db.pragma('cache_size');}).to.throw(Error);
expect(function () {db.checkpoint();}).to.throw(Error);
done();
});
});
});
});
});
var expect = require('chai').expect;
var Database = require('../.');
var util = require('../tools/test-util.js');
describe('Database#pragma()', function () {
it('should throw an exception if used before the database is open', function () {
var db = new Database('temp/12.1.db');
expect(function () {db.pragma('cache_size');}).to.throw(Error);
});
it('should throw an exception if a string is not provided', function (done) {
var db = new Database('temp/12.2.db');
var db = new Database(util.next());
db.on('open', function () {

@@ -21,3 +18,3 @@ expect(function () {db.pragma(123);}).to.throw(TypeError);

it('should throw an exception if invalid/redundant SQL is provided', function (done) {
var db = new Database('temp/12.3.db');
var db = new Database(util.next());
db.on('open', function () {

@@ -29,7 +26,7 @@ expect(function () {db.pragma('PRAGMA cache_size');}).to.throw(Error);

it('should execute the pragma, returning rows of strings', function (done) {
var db = new Database('temp/12.4.db');
var db = new Database(util.next());
db.on('open', function () {
var rows = db.pragma('cache_size');
expect(rows[0].cache_size).to.be.a('string');
expect(+rows[0].cache_size).to.equal(-16000);
expect(rows[0].cache_size).to.equal('-16000');
done();

@@ -39,3 +36,3 @@ });

it('should optionally return simpler results', function (done) {
var db = new Database('temp/12.5.db');
var db = new Database(util.next());
db.on('open', function () {

@@ -48,4 +45,14 @@ var cache_size = db.pragma('cache_size', true);

});
it('should accept any truthy value to simplify results', function (done) {
var db = new Database(util.next());
db.on('open', function () {
expect(db.pragma('cache_size', {})).to.equal('-16000');
expect(db.pragma('cache_size', 123)).to.equal('-16000');
expect(db.pragma('cache_size', function () {})).to.equal('-16000');
expect(db.pragma('cache_size', NaN)).to.deep.equal([{cache_size: '-16000'}]);
done();
});
});
it('should obey PRAGMA changes', function (done) {
var db = new Database('temp/12.6.db');
var db = new Database(util.next());
db.on('open', function () {

@@ -58,4 +65,4 @@ expect(db.pragma('cache_size', true)).to.equal('-16000');

});
it('should return undefined when no rows exist and simpler results are desired', function (done) {
var db = new Database('temp/12.7.db');
it('should return undefined if no rows exist and simpler results are desired', function (done) {
var db = new Database(util.next());
db.on('open', function () {

@@ -62,0 +69,0 @@ expect(db.pragma('table_info', true)).to.be.undefined;

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