Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-sqlite3

Package Overview
Dependencies
Maintainers
1
Versions
131
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 7.2.0 to 7.3.0

lib/methods/serialize.js

31

docs/api.md

@@ -13,2 +13,3 @@ # API

- [Database#backup()](#backupdestination-options---promise)
- [Database#serialize()](#serializeoptions---buffer)
- [Database#function()](#functionname-options-function---this)

@@ -122,3 +123,3 @@ - [Database#aggregate()](#aggregatename-options---this)

Initiates a [backup](https://www.sqlite.org/backup.html) of the database, returning a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) for when the backup is complete. If the backup fails, the promise will be rejected with an `Error`. You can optionally backup an attached database by setting the `attached` option to the name of the desired attached database.
Initiates a [backup](https://www.sqlite.org/backup.html) of the database, returning a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) for when the backup is complete. If the backup fails, the promise will be rejected with an `Error`. You can optionally backup an attached database instead by setting the `attached` option to the name of the desired attached database. A backup file is just a regular SQLite3 database file. It can be opened by [`new Database()`](#new-databasepath-options) just like any SQLite3 database.

@@ -156,2 +157,14 @@ ```js

### .serialize([*options*]) -> *Buffer*
Returns a [buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer) containing the serialized contents of the database. You can optionally serialize an attached database instead by setting the `attached` option to the name of the desired attached database.
The returned buffer can be written to disk to create a regular SQLite3 database file, or it can be opened directly as an in-memory database by passing it to [`new Database()`](#new-databasepath-options).
```js
const buffer = db.serialize();
db.close();
db = new Database(buffer);
```
### .function(*name*, [*options*], *function*) -> *this*

@@ -173,2 +186,4 @@

If `options.directOnly` is `true`, the registered function can only be invoked from top-level SQL, and cannot be used in [VIEWs](https://sqlite.org/lang_createview.html), [TRIGGERs](https://sqlite.org/lang_createtrigger.html), or schema structures such as [CHECK constraints](https://www.sqlite.org/lang_createtable.html#ckconst), [DEFAULT clauses](https://www.sqlite.org/lang_createtable.html#dfltval), etc.
If your function is [deterministic](https://en.wikipedia.org/wiki/Deterministic_algorithm), you can set `options.deterministic` to `true`, which may improve performance under some circumstances.

@@ -216,3 +231,3 @@

Just like regular [user-defined functions](#functionname-options-function---this), user-defined aggregates can accept multiple arguments. Furthermore, `options.varargs` and `options.deterministic` [are also](#functionname-options-function---this) accepted.
Just like regular [user-defined functions](#functionname-options-function---this), user-defined aggregates can accept multiple arguments. Furthermore, `options.varargs`, `options.directOnly`, and `options.deterministic` [are also](#functionname-options-function---this) accepted.

@@ -473,2 +488,4 @@ If you provide an `inverse()` function, the aggregate can be used as a [window function](https://www.sqlite.org/windowfunctions.html). Where `step()` is used to add a row to the current window, `inverse()` is used to remove a row from the current window. When using window functions, `result()` may be invoked multiple times.

**.readonly -> _boolean_** - Whether the prepared statement is readonly, meaning it does not mutate the database (note that [SQL functions might still change the database indirectly](https://www.sqlite.org/c3ref/stmt_readonly.html) as a side effect, even if the `.readonly` property is `true`).
# Binding Parameters

@@ -511,1 +528,11 @@

```
Here is how `better-sqlite3` converts values between SQLite3 and JavaScript:
|SQLite3|JavaScript|
|---|---|
|`NULL`|`null`|
|`REAL`|`number`|
|`INTEGER`|`number` [or `BigInt`](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/integer.md#the-bigint-primitive-type)|
|`TEXT`|`string`|
|`BLOB`|[`Buffer`](https://nodejs.org/api/buffer.html#buffer_class_buffer)|

@@ -54,2 +54,3 @@ # Custom configuration

SQLITE_DEFAULT_WAL_SYNCHRONOUS=1
SQLITE_ENABLE_DESERIALIZE
SQLITE_ENABLE_COLUMN_METADATA

@@ -67,2 +68,9 @@ SQLITE_ENABLE_UPDATE_DELETE_LIMIT

SQLITE_SOUNDEX
HAVE_STDINT_H=1
HAVE_INT8_T=1
HAVE_INT16_T=1
HAVE_INT32_T=1
HAVE_UINT8_T=1
HAVE_UINT16_T=1
HAVE_UINT32_T=1
```

10

lib/database.js

@@ -17,2 +17,7 @@ 'use strict';

// Apply defaults
let buffer;
if (Buffer.isBuffer(filenameGiven)) {
buffer = filenameGiven;
filenameGiven = ':memory:';
}
if (filenameGiven == null) filenameGiven = '';

@@ -36,3 +41,3 @@ if (options == null) options = {};

// Validate interpreted options
if (readonly && anonymous) throw new TypeError('In-memory/temporary databases cannot be readonly');
if (readonly && anonymous && !buffer) throw new TypeError('In-memory/temporary databases cannot be readonly');
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');

@@ -48,3 +53,3 @@ if (timeout > 0x7fffffff) throw new RangeError('Option "timeout" cannot be greater than 2147483647');

Object.defineProperties(this, {
[util.cppdb]: { value: new CPPDatabase(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null) },
[util.cppdb]: { value: new CPPDatabase(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
...wrappers.getters,

@@ -59,2 +64,3 @@ });

Database.prototype.backup = require('./methods/backup');
Database.prototype.serialize = require('./methods/serialize');
Database.prototype.function = require('./methods/function');

@@ -61,0 +67,0 @@ Database.prototype.aggregate = require('./methods/aggregate');

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

const deterministic = getBooleanOption(options, 'deterministic');
const directOnly = getBooleanOption(options, 'directOnly');
const varargs = getBooleanOption(options, 'varargs');

@@ -28,3 +29,3 @@ let argCount = -1;

this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic);
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
return this;

@@ -31,0 +32,0 @@ };

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

const deterministic = getBooleanOption(options, 'deterministic');
const directOnly = getBooleanOption(options, 'directOnly');
const varargs = getBooleanOption(options, 'varargs');

@@ -29,4 +30,4 @@ let argCount = -1;

this[cppdb].function(fn, name, argCount, safeIntegers, deterministic);
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
return this;
};
{
"name": "better-sqlite3",
"version": "7.2.0",
"version": "7.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,3 +12,3 @@ 'use strict';

function assertStmt(stmt, source, db, reader) {
function assertStmt(stmt, source, db, reader, readonly) {
expect(stmt.source).to.equal(source);

@@ -18,2 +18,3 @@ expect(stmt.constructor.name).to.equal('Statement');

expect(stmt.reader).to.equal(reader);
expect(stmt.readonly).to.equal(readonly);
expect(() => new stmt.constructor(source)).to.throw(TypeError);

@@ -45,4 +46,4 @@ }

const stmt2 = this.db.prepare('CREATE TABLE people (name TEXT); ');
assertStmt(stmt1, 'CREATE TABLE people (name TEXT) ', this.db, false);
assertStmt(stmt2, 'CREATE TABLE people (name TEXT); ', this.db, false);
assertStmt(stmt1, 'CREATE TABLE people (name TEXT) ', this.db, false, false);
assertStmt(stmt2, 'CREATE TABLE people (name TEXT); ', this.db, false, false);
expect(stmt1).to.not.equal(stmt2);

@@ -53,4 +54,11 @@ expect(stmt1).to.not.equal(this.db.prepare('CREATE TABLE people (name TEXT) '));

const stmt = this.db.prepare('SELECT 555');
assertStmt(stmt, 'SELECT 555', this.db, true);
assertStmt(stmt, 'SELECT 555', this.db, true, true);
});
it('should set the correct values for "reader" and "readonly"', function () {
this.db.exec('CREATE TABLE data (value)');
assertStmt(this.db.prepare('SELECT 555'), 'SELECT 555', this.db, true, true);
assertStmt(this.db.prepare('BEGIN'), 'BEGIN', this.db, false, true);
assertStmt(this.db.prepare('BEGIN EXCLUSIVE'), 'BEGIN EXCLUSIVE', this.db, false, false);
assertStmt(this.db.prepare('DELETE FROM data RETURNING *'), 'DELETE FROM data RETURNING *', this.db, true, false);
});
});

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

expect(() => this.db.function('b', { deterministic: undefined }, () => {})).to.throw(TypeError);
expect(() => this.db.function('b', { directOnly: undefined }, () => {})).to.throw(TypeError);
expect(() => this.db.function('c', { safeIntegers: undefined }, () => {})).to.throw(TypeError);

@@ -32,0 +33,0 @@ });

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

expect(() => this.db.aggregate('b', { step: () => {}, deterministic: undefined })).to.throw(TypeError);
expect(() => this.db.aggregate('b', { step: () => {}, directOnly: undefined })).to.throw(TypeError);
expect(() => this.db.aggregate('c', { step: () => {}, safeIntegers: undefined })).to.throw(TypeError);

@@ -45,0 +46,0 @@ });

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