Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@journeyapps/sqlcipher

journeyapps7.1kBSD-3-Clause5.3.1TypeScript support: included

Asynchronous, non-blocking SQLCipher bindings

sql, sqlite, sqlite3, database

readme

Fork of node-sqlite3, modified to use SQLCipher.

While the node-sqlite3 project does include support for compiling against sqlcipher, it requires manual work, and does not work out-of-the-box on Electron on Windows. This fork changes the default configuration to bundle SQLCipher directly, as well as OpenSSL where required.

Supported platforms

Binaries are built against N-API 3 and 6, on MacOS, Windows (ia32 and x64) and Linux (x64).

Node 10+ and Electron 6+ is supported.

Other platforms/architectures may work by building from source - see the section below.

Installation

yarn add "@journeyapps/sqlcipher"
# Or: npm install --save "@journeyapps/sqlcipher"

Usage

var sqlite3 = require('@journeyapps/sqlcipher').verbose();
var db = new sqlite3.Database('test.db');

db.serialize(function() {
  // This is the default, but it is good to specify explicitly:
  db.run("PRAGMA cipher_compatibility = 4");

  // To open a database created with SQLCipher 3.x, use this:
  // db.run("PRAGMA cipher_compatibility = 3");

  db.run("PRAGMA key = 'mysecret'");
  db.run("CREATE TABLE lorem (info TEXT)");

  var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
  for (var i = 0; i < 10; i++) {
      stmt.run("Ipsum " + i);
  }
  stmt.finalize();

  db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
      console.log(row.id + ": " + row.info);
  });
});

db.close();

SQLCipher

A copy of the source for SQLCipher 4.4.2 is bundled, which is based on SQLite 3.33.0.

Building from source.

Building from source when installing the package is only supported up to version 5.2.0.

The two pre-built versions (N-API 3 and N-API 6) cover all electron and node versions, so building from source should not be required.

Usage with electron-forge / electron-rebuild

electron-forge uses electron-rebuild and attempts to rebuild this library from source by default, in a way that is not compatible with the way node-pre-gyp is used here.

The workaround is to disable the rebuilding:

  1. If using Electron 11+, use a node version that supports N-API 6+ (v10.20.0+ / v12.17.0+ / v14.0.0).
  2. After npm install / yarn install, make sure that the folder node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-linux-x64 exists. If not, check the previous step again, remove the node_modules folder, and try again.
  3. Disable rebuilding of this library using the onlyModules option of electron-rebuild in your package.json:

     "config": {
         "forge": {
             "electronRebuildConfig": {
                 "onlyModules": []  // Specify other native modules here if required
             }
         }
     }

Note: electron-builder does not appear to have this issue, and should work directly. Similarly, using electron directly should just work, but do check that a compatible node version is used (see above).

OpenSSL

SQLCipher depends on OpenSSL.

For Windows, we bundle OpenSSL 1.1.1i. Binaries are generated using vckpg (e.g., .\vcpkg\vcpkg install openssl:x64-windows-static).

On Mac we bundle OpenSSL 1.1.1l.

On Linux we dynamically link against the system OpenSSL.

API

See the API documentation in the wiki.

Documentation for the SQLCipher extension is available here.

Acknowledgments

Most of the work in this library is from the node-sqlite3 library by MapBox.

Additionally, some of the SQLCipher-related changes are based on a fork by liubiggun.

License

node-sqlcipher is BSD licensed.

SQLCipher is Copyright (c) 2016, ZETETIC LLC under the BSD license.

SQLite is Public Domain

changelog

Changelog

5.3.1

  • Linux: Downgrade glibc requirement to 2.24, supporting Ubuntu 16.10+ and Debian 9 (Stretch)+ again.

5.3.0

  • Pre-built binaries for macos/darwin arm64.
  • Add typescript types.
  • Don't fallback to building from source.
  • Smaller NPM package (build dependencies not included anymore).
  • Linux: Requires glibc 2.28+ (Ubuntu 18.10+).

5.2.0

  • Statically link OpenSSL on Linux and Windows, in addition to MacOS. No more DLLs distributed.
  • Upgrade to OpenSSL 1.1.1i.
  • Provide pre-built binaries for ARM64 on Windows (not regularly tested, but should work).

5.1.0

  • Update to SQLCipher 4.4.2 / SQLite 3.33.0.
  • Fix crash on Electron on Windows.
  • Always use system or bundled OpenSSL, not OpenSSL bundled with Node.

5.0.0

  • Major change: Use N-API instead of NAN. This removes the need to have separate Node binaries for each Node and Electron version, which was the most common cause of reported issues.
  • Update to SQLCipher 4.4.0 / SQLite 3.31.0.
  • Drop support for Node < 10, and Electron < 6.

Includes these upstream changes from mapbox/node-sqlite3:

5.0.1

  • dep: node-addon-api to ^3.0.0 #1367
  • bug: bad comparison of c string #1347
  • bug: worker threads crash #1367
  • bug: segfaults #1368
  • typo: broken link to MapBox site #1369

5.0.0

  • prebuilt: Node 14 support, dropped support for all version of Node < 10 #1304
  • napi: refactor codebase to use N-API instead of NAN (+ various improvements) #1304
  • trace: don't require throw to add trace info for verbose #1317

4.2.0

  • webpack: split sqlite3-binding.js out so that it could be override by webpack #1268
  • sqlite3: enable 'SQLITE_ENABLE_DBSTAT_VTAB=1' #1281
  • deps: remove request #1287
  • electron: fix dist url #1282

4.1.0

4.1.0

  • Update to SQLCipher 4.3.0 / SQLite 3.30.1.

4.0.0

  • Update to SQLCipher 4.2.0 / SQLite 3.28.0.

3.2.1

  • Publish more prebuilt binaries.

3.2.0

  • Update to SQLCipher 3.4.1 / SQLite 3.20.1.
  • Also bundle msvcr120.dll

3.1.16

  • First release of the fork, based on SQLCipher 3.4.1 / SQLite 3.15.2.