microsoft/vscode-node-sqlite3
forked from TryGhost/node-sqlite3
Captured source
source ↗microsoft/vscode-node-sqlite3
Description: Asynchronous, non-blocking SQLite3 bindings for Node.js
Language: PLpgSQL
License: BSD-3-Clause
Stars: 49
Forks: 17
Open issues: 7
Created: 2018-10-15T19:28:33Z
Pushed: 2026-09-13T04:59:09Z
Default branch: release/vscode
Fork: yes
Parent repository: TryGhost/node-sqlite3
Archived: no
README:
⚙️ node-sqlite3
Asynchronous, non-blocking SQLite3 bindings for Node.js.
!Build Status 
Features
- Straightforward query and parameter binding interface
- Full Buffer/Blob support
- Extensive debugging support
- Query serialization API
- Extension support, including bundled support for the json1 extension
- Big test suite
- Written in modern C++ and tested for memory leaks
- Bundles SQLite v3.39.4, or you can build using a local SQLite
Installing
You can use `npm` or `yarn` to install sqlite3:
- (recommended) Latest published package:
npm install sqlite3 # or yarn add sqlite3
- GitHub's
masterbranch:npm install https://github.com/tryghost/node-sqlite3/tarball/master
Prebuilt binaries
sqlite3 v5+ was rewritten to use Node-API so prebuilt binaries do not need to be built for specific Node versions. sqlite3 currently builds for both Node-API v3 and v6. Check the Node-API version matrix to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+.
The module uses node-pre-gyp to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for sqlite3 versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided:
Format: napi-v{napi_build_version}-{platform}-{libc}-{arch}
napi-v3-darwin-unknown-arm64napi-v3-darwin-unknown-x64napi-v3-linux-glibc-arm64napi-v3-linux-glibc-x64napi-v3-linux-musl-arm64napi-v3-linux-musl-x64napi-v3-win32-unknown-ia32napi-v3-win32-unknown-x64napi-v6-darwin-unknown-arm64napi-v6-darwin-unknown-x64napi-v6-linux-glibc-arm64napi-v6-linux-glibc-x64napi-v6-linux-musl-arm64napi-v6-linux-musl-x64napi-v6-win32-unknown-ia32napi-v6-win32-unknown-x64
Unfortunately, node-pre-gyp cannot differentiate between armv6 and armv7, and instead uses arm as the {arch}. Until that is fixed, you will still need to install sqlite3 from [source](#source-install).
Support for other platforms and architectures may be added in the future if CI supports building on them.
If your environment isn't supported, it'll use node-gyp to build SQLite but you will need to install a C++ compiler and linker.
Other ways to install
It is also possible to make your own build of sqlite3 from its source instead of its npm package ([See below.](#source-install)).
The sqlite3 module also works with node-webkit if node-webkit contains a supported version of Node.js engine. [(See below.)](#building-for-node-webkit)
SQLite's SQLCipher extension is also supported. [(See below.)](#building-for-sqlcipher)
API
See the API documentation in the wiki.
Usage
Note: the module must be [installed](#installing) before use.
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database(':memory:');
db.serialize(() => {
db.run("CREATE TABLE lorem (info TEXT)");
const stmt = db.prepare("INSERT INTO lorem VALUES (?)");
for (let i = 0; i {
console.log(row.id + ": " + row.info);
});
});
db.close();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/
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 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...
Excerpt shown — open the source for the full document.