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 0.7.0 to 0.8.0

src/objects/database/checkpoint.cc

10

lib/database.js

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

if (typeof filename !== 'string') {
throw new TypeError('Argument 0 must be a string filename.');
throw new TypeError('Expected argument 0 to be a string filename.');
}

@@ -16,6 +16,6 @@

}
if (options.wal == null) {
options.wal = true;
if (!filename) {
throw new TypeError('A database filename cannot be an empty string.');
}
if (/^file:/i.test(filename)) {

@@ -40,3 +40,3 @@ throw new TypeError('URI filenames are reserved for internal use only.');

return new CPPDatabase(filename, !!options.wal, NullFactory);
return new CPPDatabase(filename, NullFactory);
}

@@ -43,0 +43,0 @@ CPPDatabase.prototype.constructor = Database;

{
"name": "better-sqlite3",
"version": "0.7.0",
"version": "0.8.0",
"description": "The fastest and most carefully designed library for SQLite3 in Node.js.",

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

"install": "node-gyp rebuild",
"test": "$(npm bin)/mocha --timeout 5000 --slow 5000"
"test": "$(npm bin)/mocha --timeout 5000 --slow 5000",
"pretest": "rm -r ./temp/ || true && mkdir ./temp/",
"posttest": "rm -r ./temp/"
},

@@ -26,0 +28,0 @@ "license": "MIT",

@@ -47,14 +47,4 @@ # better-sqlite3

#### *options.memory*
If `options.memory` is `true`, an in-memory database will be created, rather than a disk-bound one. Default is `false`.
If this option is `true`, an in-memory database will be created, rather than a disk-bound one. Default is `false`.
#### *options.wal*
If this option is `true` (the default), the following PRAGMA are applied:
- `PRAGMA journal_mode = WAL;`
- `PRAGMA synchronous = 1;`
This means the database will be opened in [Write Ahead Logging](https://www.sqlite.org/wal.html) mode. If you set `options.wal` to `false`, the old [Rollback Journal](https://www.sqlite.org/lockingv3.html#rollback) mode will be used, as well as the default `synchronous` setting.
### .statement(string) -> Statement

@@ -81,2 +71,10 @@

### .checkpoint([force], callback) -> this
This method is provided because [.pragma()](#pragmastring-simplify---results)'s synchronous nature makes it unsuitable for running [WAL mode checkpoints](https://www.sqlite.org/wal.html).
By default, this method will execute a checkpoint in "PASSIVE" mode, which means it might not perform a *complete* checkpoint if there are pending reads or write on the database. If the first argument is `true`, it will execute the checkpoint in "RESTART" mode, which ensures a complete checkpoint operation.
When the operation is complete, the callback is invoked with an `Error` or `null` as its first parameter, depending on if the operation was successful. If successful, the callback's second parameter will be a number between `0` and `1`, indicating the fraction of the WAL file that was checkpointed. For forceful checkpoints ("RESTART" mode), this number will always be `1`.
#### WARNING: You should NOT use prepared [statements](#statementstring---statement) or [transactions](#transactionarrayofstrings---transaction) to run PRAGMA statements. Doing so could result in database corruption.

@@ -194,2 +192,3 @@

# Binding Parameters

@@ -232,4 +231,45 @@

# Performance
By default, SQLite3 databases are not well suited for some write-heavy applications. If your application reads frequently, but writes to the database very infrequently, you'll probably be fine. But if this is not the case, it's recommended to turn on [WAL mode](https://www.sqlite.org/wal.html):
```js
db.pragma('journal_mode = WAL');
```
WAL mode has a few *disadvantages* to consider:
- Transactions that involve ATTACHed databases are atomic for each individual database, but are not atomic across all databases as a set.
- Under rare circumstances, the [WAL file](https://www.sqlite.org/wal.html) may experience "checkpoint starvation" (see below).
- Some hardware/system limitations that may affect some users, [listed here](https://www.sqlite.org/wal.html).
However, you trade those disadvantages for greatly improved performance in most web applications.
If you want to *massively* improve write performance and you're willing to sacrifice a tiny bit of [durability](https://en.wikipedia.org/wiki/Durability_(database_systems)), you can use this:
```js
db.pragma('journal_mode = WAL');
db.pragma('synchronous = 1');
```
Normally, setting `synchronous = 1` would introduce the risk of database corruption following a power loss or hard reboot. But in [WAL mode](https://www.sqlite.org/wal.html), you do not introduce this risk.
### Defending against "checkpoint starvation"
Checkpoint starvation is when SQLite3 is unable to recycle the [WAL file](https://www.sqlite.org/wal.html) due to everlasting concurrent reads to the database. If this happens, the WAL file will grow without bound, leading to unacceptable amounts of disk usage and deteriorating performance.
To prevent this, you can optionally use the [db.checkpoint()](#checkpointforce-callback---this) method to force checkpointing whenever you deem appropriate.
# SQLite3 compilation options
The following [compilation options](https://www.sqlite.org/compile.html) are used:
- SQLITE_THREADSAFE=1
- SQLITE_ENABLE_FTS5
- SQLITE_ENABLE_JSON1
- SQLITE_ENABLE_RTREE
- SQLITE_DEFAULT_CACHE_SIZE=-16000
- SQLITE_DEFAULT_FOREIGN_KEYS=1
- SQLITE_USE_URI=1
# License
[MIT](https://github.com/JoshuaWise/better-sqlite3/blob/master/LICENSE)

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