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

Package detail

sqlite3-rebuilt

mapbox18BSD-3-Clause4.1.3

Asynchronous, non-blocking SQLite3 bindings

sql, sqlite, sqlite3, database

readme

Asynchronous, non-blocking SQLite3 bindings for Node.js.

NPM

Build Status Build status Coverage Status Dependencies FOSSA Status

Supported platforms

The sqlite3 module works with Node.js v4.x, v6.x, v8.x, v10.x, v11.x and v12.x.

Binaries for most Node versions and platforms are provided by default via node-pre-gyp.

The sqlite3 module also works with node-webkit if node-webkit contains a supported version of Node.js engine. (See below.)

SQLite's SQLCipher extension is also supported. (See below.)

Usage

Note: the module must be installed before use.

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');

db.serialize(function() {
  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();

Features

  • Straightforward query and parameter binding interface
  • Full Buffer/Blob support
  • Extensive debugging support
  • Query serialization API
  • Extension support
  • Big test suite
  • Written in modern C++ and tested for memory leaks
  • Bundles Sqlite3 3.26.0 as a fallback if the installing system doesn't include SQLite

API

See the API documentation in the wiki.

Installing

You can use npm to download and install:

  • The latest sqlite3 package: npm install sqlite3

  • GitHub's master branch: npm install https://github.com/mapbox/node-sqlite3/tarball/master

The module uses node-pre-gyp to download a pre-compiled binary for your platform, if it exists. Otherwise, it uses node-gyp to build the extension.

It is also possible to make your own build of sqlite3 from its source instead of its npm package (see below).

It is possible to use the installed package in node-webkit instead of the vanilla Node.js. See Building for node-webkit for details.

Source install

To skip searching for pre-compiled binaries, and force a build from source, use

npm install --build-from-source

The sqlite3 module depends only on libsqlite3. However, by default, an internal/bundled copy of sqlite will be built and statically linked, so an externally installed sqlite3 is not required.

If you wish to install against an external sqlite then you need to pass the --sqlite argument to npm wrapper:

npm install --build-from-source --sqlite=/usr/local

If building against an external sqlite3 make sure to have the development headers available. Mac OS X ships with these by default. If you don't have them installed, install the -dev package with your package manager, e.g. apt-get install libsqlite3-dev for Debian/Ubuntu. Make sure that you have at least libsqlite3 >= 3.6.

Note, if building against homebrew-installed sqlite on OS X you can do:

npm install --build-from-source --sqlite=/usr/local/opt/sqlite/

By default the node-gyp install will use python as part of the installation. A different python executable can be specified on the command line.

npm install --build-from-source --python=/usr/bin/python2

This uses the npm_config_python config, so values in .npmrc will be honoured:

python=/usr/bin/python2

Custom file header (magic)

The default sqlite file header is "SQLite format 3".
You can specify a different magic, though this will make standard tools and libraries unable to work with your files.

npm install --build-from-source --sqlite_magic="MyCustomMagic15"

Note that the magic must be exactly 15 characters long (16 bytes including null terminator).

Building for node-webkit

Because of ABI differences, sqlite3 must be built in a custom to be used with node-webkit.

To build node-sqlite3 for node-webkit:

  1. Install nw-gyp globally: npm install nw-gyp -g (unless already installed)

  2. Build the module with the custom flags of --runtime, --target_arch, and --target:

NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

This command internally calls out to node-pre-gyp which itself calls out to nw-gyp when the --runtime=node-webkit option is passed.

You can also run this command from within a node-sqlite3 checkout:

npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

Remember the following:

  • You must provide the right --target_arch flag. ia32 is needed to target 32bit node-webkit builds, while x64 will target 64bit node-webkit builds (if available for your platform).

  • After the sqlite3 package is built for node-webkit it cannot run in the vanilla Node.js (and vice versa).

    • For example, npm test of the node-webkit's package would fail.

Visit the “Using Node modules” article in the node-webkit's wiki for more details.

Building for sqlcipher

For instructions for building sqlcipher see Building SQLCipher for node.js

To run node-sqlite3 against sqlcipher you need to compile from source by passing build options like:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/

node -e 'require("sqlite3")'

If your sqlcipher is installed in a custom location (if you compiled and installed it yourself), you'll also need to to set some environment variables:

On OS X with Homebrew

Set the location where brew installed it:

export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`

node -e 'require("sqlite3")'

On most Linuxes (including Raspberry Pi)

Set the location where make installed it:

export LDFLAGS="-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
export CXXFLAGS="$CPPFLAGS"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose

node -e 'require("sqlite3")'

Custom builds and Electron

Running sqlite3 through electron-rebuild does not preserve the sqlcipher extension, so some additional flags are needed to make this build Electron compatible. Your npm install sqlite3 --build-from-source command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):

--runtime=electron --target=1.7.6 --dist-url=https://atom.io/download/electron

In the case of MacOS with Homebrew, the command should look like the following:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=1.7.6 --dist-url=https://atom.io/download/electron

Testing

mocha is required to run unit tests.

In sqlite3's directory (where its package.json resides) run the following:

npm install mocha
npm test

Contributors

Acknowledgments

Thanks to Orlando Vazquez, Eric Fredricksen and Ryan Dahl for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions.

Development of this module is sponsored by MapBox.

License

node-sqlite3 is BSD licensed.

FOSSA Status

changelog

Changelog

4.1.1

  • Electron v6.1 and v7 support #1237
  • Electron v7.1 support #1254
  • SQLite3 update to 3.30.1 #1238
  • Overwrite 'msbuild_toolset' only if 'toolset' is defined #1242
  • Upgrade CI to node-gyp 6.x for Windows Electron v5 & v6 builds #1245
  • Node v13 support #1247
  • Use minimum supported node version for Electron 7 #1255

4.1.0

  • Electron v6 support #1195
  • Electron v4.1 and v4.2 support #1180
  • Custom file header with --sqlite_magic #1144
  • https everywhere #1177

4.0.9

  • Use trusty as the base for prebuilts #1167

4.0.8

  • Rerelease of 4.0.7 but removed excess .vscode files 0df90c7

4.0.7

  • Node v12 support
  • Electron v5 support
  • Fix backup API tests
  • HAVE_USLEEP=1 for all platforms
  • docker suport

4.0.6

  • Release of 4.0.5 (again due CI)

4.0.5

  • SECURITY: Upgrade SQLite to 3.26.0 #1088
  • add constants for file open (shared databases) #1078
  • Allow specifying the python to use #1089

4.0.4

  • Add NodeJS 11 support #1072
  • Add electron osx 3.0.0 support #1071

4.0.3

  • Increase electron/osx binary coverage #1041 (@kewde)

4.0.2

  • Fixed HTTP proxy support by using request over needle in node-pre-gyp

4.0.1

  • Node v10 support
  • Upgrade to node-pre-gyp@0.10.1
  • Upgrade to nan@2.10.0
  • Upgrade to sqlite v3.24.0
  • Stopped bundling node-pre-gyp
  • Upgrade to mocha@5
  • Now building electron binaries (@kewde)
  • Add OPEN_FULLMUTEX constant

4.0.0

3.1.13

  • Attempt to fix regression of #866

3.1.12

  • Fixed to ensure the binaries do not rely on GLIBC_2.14 and only GLIBC_2.2.5. This regressed in v3.1.11.

3.1.11

  • Fixed building from source on alpine linux

3.1.10

  • Removed npm ls from prepublish hook per mapbox/node-pre-gyp#291
  • Upgraded node-pre-gyp to v0.6.37
  • Removed accidentally committed large file

3.1.9

  • Added support for node v8 and upgraded nan, node-pre-gyp deps.

3.1.8

  • Added support for node v7 (pre-compiled binaries available)

3.1.7

3.1.6

  • Starts bundling node-pre-gyp again to avoid #720

3.1.5

3.1.4

  • Added support for node v6

3.1.3

3.1.2

3.1.1

3.1.0

  • Support for node 3.x and 4.x
  • Stopped producing binaries for node-webkit and 32 bit linux

3.0.11

  • Support for io.js 3.x (upgrade to Nan 2.x) @kkoopa

3.0.10

3.0.9

3.0.8

3.0.7

  • Fixed build regression against ARM and i386 linux
  • Upgraded node-pre-gyp@0.6.6
  • Added support for io.js 2.0.0

3.0.6

3.0.5

3.0.4

3.0.3

3.0.2

  • Republish for possibly busted npm package.

3.0.1

  • Use ~ in node-pre-gyp semver for more flexible dep management.

3.0.0

Released September 20nd, 2014

  • Backwards-incompatible change: node versions 0.8.x are no longer supported.
  • Updated to node-pre-gyp@0.5.27
  • Updated NAN to 1.3.0
  • Updated internal libsqlite3 to v3.8.6

2.2.7

Released August 6th, 2014

  • Removed usage of npm ls with prepublish target (which breaks node v0.8.x)

2.2.6

Released August 6th, 2014

  • Fix bundled version of node-pre-gyp

2.2.5

Released August 5th, 2014

  • Fix leak in complete() callback of Database.each() (#307)
  • Started using engineStrict and improved engines declaration to make clear only >= 0.11.13 is supported for the 0.11.x series.

2.2.4

Released July 14th, 2014

2.2.3

  • Fixed regression in v2.2.2 for installing from binaries on windows.

2.2.2

  • Fixed packaging problem whereby a config.gypi was unintentially packaged and could cause breakages for OS X builds.

2.2.1

  • Now shipping with 64bit FreeBSD binaries against both node v0.10.x and node v0.8.x.
  • Fixed solaris/smartos source compile by passing -std=c99 when building internally bundled libsqlite3 (#201)
  • Reduced size of npm package by ignoring tests and examples.
  • Various fixes and improvements for building against node-webkit
  • Upgraded to node-pre-gyp@0.5.x from node-pre-gyp@0.2.5
  • Improved ability to build from source against sqlcipher by passing custom library name: --sqlite_libname=sqlcipher
  • No changes to C++ Core / Existing binaries are exactly the same

2.2.0

Released Jan 13th, 2014

2.1.19

Released October 31st, 2013

  • Started respecting process.env.npm_config_tmp as location to download binaries
  • Removed uneeded progress dependency

2.1.18

Released October 22nd, 2013

  • node-sqlite3 moved to mapbox github group
  • Fixed reporting of node-gyp errors
  • Fixed support for node v0.6.x

2.1.17

  • Minor fixes to binary deployment

2.1.16

  • Support for binary deployment

2.1.15

Released August 7th, 2013

  • Minor readme additions and code optimizations