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.0.1 to 2.1.0

11

lib/database.js
'use strict';
var fs = require('fs');
var path = require('path');

@@ -39,6 +40,14 @@ var toDescriptor = require('to-descriptor');

+ '?mode=memory&cache=shared';
} else if (!pathExists(path.dirname(filename))) {
throw new TypeError('Cannot open database because the directory does not exist.');
}
return new CPPDatabase(filename, filenameGiven, !!options.memory);
return new CPPDatabase(filename, filenameGiven, !!options.memory, !!options.readonly);
}
function pathExists(path) {
try {fs.accessSync(path); return true;}
catch (ex) {return false;}
}
CPPDatabase.prototype.constructor = Database;

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

2

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

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

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

expect(db.memory).to.be.false;
expect(db.readonly).to.be.false;
expect(db.open).to.be.true;

@@ -50,5 +51,24 @@ fs.accessSync(util.current());

expect(db.memory).to.be.true;
expect(db.readonly).to.be.false;
expect(db.open).to.be.true;
expect(function () {fs.accessSync(util.current());}).to.throw(Error);
});
it('should allow readonly database connections to be created', function () {
expect(function () {fs.accessSync(util.next());}).to.throw(Error);
var db = new Database(util.current(), {readonly: true});
expect(db.name).to.equal(util.current());
expect(db.memory).to.be.false;
expect(db.readonly).to.be.true;
expect(db.open).to.be.true;
fs.accessSync(util.current());
});
it('should allow the "readonly" and "memory" options on the same connection', function () {
expect(function () {fs.accessSync(util.next());}).to.throw(Error);
var db = new Database(util.current(), {memory: true, readonly: true});
expect(db.name).to.equal(util.current());
expect(db.memory).to.be.true;
expect(db.readonly).to.be.true;
expect(db.open).to.be.true;
expect(function () {fs.accessSync(util.current());}).to.throw(Error);
});
it('should throw an Error if opening the database failed', function () {

@@ -55,0 +75,0 @@ expect(function () {fs.accessSync(util.next());}).to.throw(Error);

@@ -53,2 +53,8 @@ var expect = require('chai').expect;

});
it('should be available to readonly connections', function () {
var db = new Database(util.next(), {readonly: true});
expect(db.pragma('cache_size', true)).to.equal('-16000');
db.pragma('cache_size = -8000');
expect(db.pragma('cache_size', true)).to.equal('-8000');
});
it('should return undefined if no rows exist and simpler results are desired', function () {

@@ -55,0 +61,0 @@ var db = new Database(util.next());

@@ -16,2 +16,11 @@ var expect = require('chai').expect;

describe('Database#prepare()', function () {
function assertStmt(stmt, source, db, returnsData) {
expect(stmt.source).to.equal(source);
expect(stmt.constructor.name).to.equal('Statement');
expect(stmt.database).to.equal(db);
expect(stmt.returnsData).to.equal(returnsData);
expect(function () {
new stmt.constructor(source);
}).to.throw(TypeError);
}
it('should throw an exception if a string is not provided', function () {

@@ -42,16 +51,7 @@ var db = new Database(util.next());

it('should create a prepared Statement object', function () {
function assertStmt(stmt, source) {
expect(stmt.source).to.equal(source);
expect(stmt.constructor.name).to.equal('Statement');
expect(stmt.database).to.equal(db);
expect(stmt.returnsData).to.equal(false);
expect(function () {
new stmt.constructor(source);
}).to.throw(TypeError);
}
var db = new Database(util.next());
var stmt1 = db.prepare('CREATE TABLE people (name TEXT)');
var stmt2 = db.prepare('CREATE TABLE people (name TEXT);');
assertStmt(stmt1, 'CREATE TABLE people (name TEXT)');
assertStmt(stmt2, 'CREATE TABLE people (name TEXT);');
assertStmt(stmt1, 'CREATE TABLE people (name TEXT)', db, false);
assertStmt(stmt2, 'CREATE TABLE people (name TEXT);', db, false);
expect(stmt1).to.not.equal(stmt2);

@@ -63,10 +63,10 @@ expect(stmt1).to.not.equal(db.prepare('CREATE TABLE people (name TEXT)'));

var stmt = db.prepare('SELECT 555');
expect(stmt.source).to.equal('SELECT 555');
expect(stmt.constructor.name).to.equal('Statement');
expect(stmt.database).to.equal(db);
expect(stmt.returnsData).to.equal(true);
expect(function () {
new stmt.constructor('SELECT 555');
}).to.throw(TypeError);
assertStmt(stmt, 'SELECT 555', db, true);
});
it('should obey the restrictions of readonly mode', function () {
var db = new Database(util.next(), {readonly: true});
expect(function () {db.prepare('CREATE TABLE people (name TEXT)');}).to.throw(TypeError);
var stmt = db.prepare('SELECT 555');
assertStmt(stmt, 'SELECT 555', db, true);
});
});

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

});
it('should throw an exception if used on a readonly database connection', function () {
var db = new Database(util.next(), {readonly: true});
expect(function () {db.transaction(['CREATE TABLE people (name TEXT)']);}).to.throw(TypeError);
});
it('should create a prepared Transaction object', function () {

@@ -72,0 +76,0 @@ var db = new Database(util.next());

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

});
it('should throw an exception if used on a readonly database connection', function () {
var readonly = new Database(db.name, {readonly: true});
expect(function () {readonly.exec('CREATE TABLE entries (a TEXT, b INTEGER)');}).to.throw(TypeError);
});
it('should execute the SQL, returning the database object itself', function () {

@@ -22,0 +26,0 @@ var returnValues = [];

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