Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
93affa4
Update microsoft/setup-msbuild action to v1.3
renovate[bot] Feb 4, 2023
c1440bd
Fixed rpath linker option when using a custom sqlite (#1654)
jeromew Feb 4, 2023
3a48888
Updated bundled SQLite to v3.41.1
daniellockyer Mar 13, 2023
edb1934
Fixed code execution vulnerability due to Object coercion
daniellockyer Dec 12, 2022
6a806f8
v5.1.5
daniellockyer Mar 13, 2023
46da1ab
Added generic type annotations for Statement and Database get/all/eac…
stevescruz Mar 13, 2023
776fc55
Updated README.md
daniellockyer Mar 13, 2023
1a206df
Fixed glibc compatibility by hardcoding lower version for `log2`
daniellockyer Mar 14, 2023
d915c0c
Fixed using Bash in shell command
daniellockyer Mar 14, 2023
8598a9d
v5.1.6
daniellockyer Mar 14, 2023
22ac6cc
Updated bundled SQLite to v3.42.0
daniellockyer May 29, 2023
cdf78bf
- Extensively utilized automatic type deduction for improved code rea…
zenon8adams May 14, 2023
dfbe3ba
Removed unused variable
daniellockyer May 29, 2023
44e570a
Update actions/checkout action to v4
renovate[bot] Sep 4, 2023
7552aa0
Update actions/setup-node action to v4
renovate[bot] Oct 23, 2023
3aeb548
Revert "Update actions/setup-node action to v4"
daniellockyer Dec 22, 2023
8d78ce7
Updated bundled SQLite to v3.44.2
daniellockyer Dec 22, 2023
56ad63c
Added myself to contributors list
daniellockyer Dec 22, 2023
10f38fe
Removed useless try-catch
daniellockyer Dec 22, 2023
080c0d1
Installed setuptools in CI workflow
daniellockyer Dec 23, 2023
93ed997
Condensed npm scripts
daniellockyer Dec 23, 2023
cff38a3
Added CI step to check semver compatibility
daniellockyer Dec 23, 2023
9e8b2ee
Reworked CI versions
daniellockyer Dec 23, 2023
c74f267
Update docker/setup-qemu-action action to v3
renovate[bot] Sep 12, 2023
8482aaf
Update docker/setup-buildx-action action to v3
renovate[bot] Sep 12, 2023
83e282d
Update actions/checkout digest to b4ffde6
renovate[bot] Dec 24, 2023
7674271
Update dependency eslint to v8
renovate[bot] Dec 24, 2023
a2cee71
Update dependency mocha to v10
renovate[bot] Dec 24, 2023
605c7f9
Replaced `@mapbox/node-pre-gyp` in favor of `prebuild` + `prebuild-in…
daniellockyer Dec 23, 2023
2595304
Updated list of supported targets
daniellockyer Dec 24, 2023
c775b81
Extracted common Node-API queuing code into macro
daniellockyer May 28, 2022
aabd297
Update actions/setup-node action to v4
renovate[bot] Dec 24, 2023
5809f62
Fixed uploading prebuilt binaries from Docker
daniellockyer Dec 24, 2023
8bda876
Refactored Database to use macros for method definitions
daniellockyer Dec 27, 2023
603e468
Fixed minor linting warning
daniellockyer Dec 27, 2023
77b327c
Increased number of rows inserted into benchmark database
daniellockyer Dec 27, 2023
3372130
Improved `RowToJS` performance by removing `Napi::String::New` instan…
daniellockyer Dec 27, 2023
e99160a
Inlined `init()` functions into class header files
daniellockyer Dec 27, 2023
4ef11bf
Removed extraneous parameter to event emit function
daniellockyer Dec 27, 2023
f792f69
Update dependency node-addon-api to v7
renovate[bot] Dec 29, 2023
83c8c0a
Configured releases to be created as prereleases
daniellockyer Dec 29, 2023
8b86e41
Fixed uploading release assets on Windows
daniellockyer Dec 29, 2023
8398daa
Fixed uploading assets from Docker
daniellockyer Dec 29, 2023
03d6e75
v5.1.7-rc.0
daniellockyer Dec 29, 2023
d04c1fb
Removed Node version from matrix title
daniellockyer Dec 30, 2023
ba4ba07
v5.1.7
daniellockyer Jan 5, 2024
1609684
Updated bundled SQLite to v3.45.0
daniellockyer Jan 16, 2024
2f0c799
Updated `actions/upload-artifact` to v4
daniellockyer Nov 6, 2024
528e15a
2025
JohnONolan Jan 20, 2025
2a0c05a
Upgrade: Bump node-sqlite3 to 5.1.7
hexaltation Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
node: 22
host: arm64
target: arm64
name: ${{ matrix.os }} (node=${{ matrix.node }}, host=${{ matrix.host }}, target=${{ matrix.target }})
name: ${{ matrix.os }} (host=${{ matrix.host }}, target=${{ matrix.target }})
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
architecture: ${{ matrix.host }}
Expand All @@ -52,15 +52,22 @@ jobs:
if: matrix.os == 'macos-m1'
run: npm install -g yarn

- name: Add setuptools for Python 3.12 (temp)
if: matrix.os != 'macos-m1'
run: pip install setuptools

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v1.3
if: contains(matrix.os, 'windows')
with:
msbuild-architecture: ${{ matrix.target }}

- name: Install dependencies
run: yarn install --ignore-scripts

- name: Check Node compatibility
run: node tools/semver-check.js

- name: Add env vars
shell: bash
run: |
Expand All @@ -78,20 +85,17 @@ jobs:
echo "CFLAGS=${CFLAGS:-} -include ../src/gcc-preinclude.h" >> $GITHUB_ENV
echo "CXXFLAGS=${CXXFLAGS:-} -include ../src/gcc-preinclude.h" >> $GITHUB_ENV

- name: Configure build
run: yarn node-pre-gyp configure --target_arch=${{ env.TARGET }}

- name: Build binaries
run: yarn node-pre-gyp build --target_arch=${{ env.TARGET }}
run: yarn prebuild -a ${{ env.TARGET }}

- name: Print binary info
if: contains(matrix.os, 'ubuntu')
run: |
ldd lib/binding/*/node_sqlite3.node
ldd build/**/node_sqlite3.node
echo "---"
nm lib/binding/*/node_sqlite3.node | grep "GLIBC_" | c++filt || true
nm build/**/node_sqlite3.node | grep "GLIBC_" | c++filt || true
echo "---"
file lib/binding/napi-v*/*
file build/**/node_sqlite3.node

- name: Run tests
run: yarn test
Expand Down Expand Up @@ -134,13 +138,13 @@ jobs:
- alpine
name: ${{ matrix.variant }} (node=${{ matrix.node }}, target=${{ matrix.target }})
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Build binaries and test
run: |
Expand All @@ -154,7 +158,7 @@ jobs:
--build-arg NODE_VERSION=${{ matrix.node }} \
.
CONTAINER_ID=$(docker create -it sqlite-builder)
docker cp $CONTAINER_ID:/usr/src/build/build/ ./build
docker cp $CONTAINER_ID:/usr/src/build/prebuilds/ ./prebuilds
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal from this file does not seem to appear in your diff, any reason for that?
TryGhost@605c7f9#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fL85-L87

       - name: Run tests
         run: yarn test
 
-      - name: Package prebuilt binaries
-        run: yarn node-pre-gyp package --target_arch=${{ env.TARGET }}
-
       - name: Upload binaries to commit artifacts
         uses: actions/upload-artifact@v3
         if: matrix.node == 18
         with:


- name: Prepare for saving artifact
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ setup.sh
*.tgz
package-lock.json
yarn.lock
prebuilds
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) MapBox
Copyright (c) 2013-2025 Mapbox & Ghost Foundation
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Asynchronous, non-blocking [SQLite3](https://sqlite.org/) bindings for [Node.js]
- [Extension support](https://github.com/TryGhost/node-sqlite3/wiki/API#databaseloadextensionpath-callback), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html)
- Big test suite
- Written in modern C++ and tested for memory leaks
- Bundles SQLite v3.40.0, or you can build using a local SQLite
- Bundles SQLite v3.45.0, or you can build using a local SQLite

# Installing

Expand All @@ -35,32 +35,22 @@ yarn add sqlite3

`sqlite3` v5+ was rewritten to use [Node-API](https://nodejs.org/api/n-api.html) 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](https://nodejs.org/api/n-api.html#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](https://github.com/mapbox/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-arm64`
* `napi-v3-darwin-unknown-x64`
* `napi-v3-linux-glibc-arm64`
* `napi-v3-linux-glibc-x64`
* `napi-v3-linux-musl-arm64`
* `napi-v3-linux-musl-x64`
* `napi-v3-win32-unknown-ia32`
* `napi-v3-win32-unknown-x64`
* `napi-v6-darwin-unknown-arm64`
* `napi-v6-darwin-unknown-x64`
* `napi-v6-linux-glibc-arm64`
* `napi-v6-linux-glibc-x64`
* `napi-v6-linux-musl-arm64`
* `napi-v6-linux-musl-x64`
* `napi-v6-win32-unknown-ia32`
* `napi-v6-win32-unknown-x64`

Unfortunately, [node-pre-gyp](https://github.com/mapbox/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).
The module uses [`prebuild-install`](https://github.com/prebuild/prebuild-install) 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:

* `darwin-arm64`
* `darwin-x64`
* `linux-arm64`
* `linux-x64`
* `linuxmusl-arm64`
* `linuxmusl-x64`
* `win32-ia32`
* `win32-x64`

Unfortunately, [prebuild](https://github.com/prebuild/prebuild/issues/174) 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.
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

Expand Down Expand Up @@ -148,8 +138,6 @@ NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang
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`](https://github.com/mapbox/node-pre-gyp) which itself calls out to [`nw-gyp`](https://github.com/rogerwang/nw-gyp) when the `--runtime=node-webkit` option is passed.

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

```bash
Expand Down Expand Up @@ -227,6 +215,7 @@ npm test

# Contributors

* [Daniel Lockyer](https://github.com/daniellockyer)
* [Konstantin Käfer](https://github.com/kkaefer)
* [Dane Springmeyer](https://github.com/springmeyer)
* [Will White](https://github.com/willwhite)
Expand Down Expand Up @@ -254,7 +243,9 @@ This module was originally created by [Mapbox](https://mapbox.com/) & is now mai

We use [GitHub releases](https://github.com/TryGhost/node-sqlite3/releases) for notes on the latest versions. See [CHANGELOG.md](https://github.com/TryGhost/node-sqlite3/blob/b05f4594cf8b0de64743561fcd2cfe6f4571754d/CHANGELOG.md) in git history for details on older versions.

# License
# Copyright & license

Copyright (c) 2013-2025 Mapbox & Ghost Foundation

`node-sqlite3` is [BSD licensed](https://github.com/tryghost/node-sqlite3/raw/master/LICENSE).

Expand Down
20 changes: 6 additions & 14 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"includes": [ "deps/common-sqlite.gypi" ],
"variables": {
"sqlite%":"internal",
"sqlite_libname%":"sqlite3"
"sqlite_libname%":"sqlite3",
"module_name": "node_sqlite3",
},
"targets": [
{
Expand All @@ -25,8 +26,10 @@
"libraries": [
"-l<(sqlite_libname)"
],
"conditions": [ [ "OS=='linux'", {"libraries+":["-Wl,-rpath=<@(sqlite)/lib"]} ] ],
"conditions": [ [ "OS!='win'", {"libraries+":["-L<@(sqlite)/lib"]} ] ],
"conditions": [
[ "OS=='linux'", {"libraries+":["-Wl,-rpath=<@(sqlite)/lib"]} ],
[ "OS!='win'", {"libraries+":["-L<@(sqlite)/lib"]} ]
],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalLibraryDirectories': [
Expand All @@ -51,17 +54,6 @@
"src/statement.cc"
],
"defines": [ "NAPI_VERSION=<(napi_build_version)", "NAPI_DISABLE_CPP_EXCEPTIONS=1" ]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
]
}
2 changes: 1 addition & 1 deletion deps/common-sqlite.gypi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'variables': {
'sqlite_version%':'3400000',
'sqlite_version%':'3450000',
"toolset%":'',
},
'target_defaults': {
Expand Down
Binary file removed deps/sqlite-autoconf-3400000.tar.gz
Binary file not shown.
Binary file added deps/sqlite-autoconf-3450000.tar.gz
Binary file not shown.
6 changes: 1 addition & 5 deletions lib/sqlite3-binding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
const binary = require('@mapbox/node-pre-gyp');
const path = require('path');
const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
const binding = require(binding_path);
module.exports = exports = binding;
module.exports = require('bindings')('node_sqlite3.node');
24 changes: 12 additions & 12 deletions lib/sqlite3.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ export class Statement extends events.EventEmitter {
run(params: any, callback?: (this: RunResult, err: Error | null) => void): this;
run(...params: any[]): this;

get(callback?: (err: Error | null, row?: any) => void): this;
get(params: any, callback?: (this: RunResult, err: Error | null, row?: any) => void): this;
get<T>(callback?: (err: Error | null, row?: T) => void): this;
get<T>(params: any, callback?: (this: RunResult, err: Error | null, row?: T) => void): this;
get(...params: any[]): this;

all(callback?: (err: Error | null, rows: any[]) => void): this;
all(params: any, callback?: (this: RunResult, err: Error | null, rows: any[]) => void): this;
all<T>(callback?: (err: Error | null, rows: T[]) => void): this;
all<T>(params: any, callback?: (this: RunResult, err: Error | null, rows: T[]) => void): this;
all(...params: any[]): this;

each(callback?: (err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each(params: any, callback?: (this: RunResult, err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(callback?: (err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(params: any, callback?: (this: RunResult, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each(...params: any[]): this;
}

Expand All @@ -103,16 +103,16 @@ export class Database extends events.EventEmitter {
run(sql: string, params: any, callback?: (this: RunResult, err: Error | null) => void): this;
run(sql: string, ...params: any[]): this;

get(sql: string, callback?: (this: Statement, err: Error | null, row: any) => void): this;
get(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: any) => void): this;
get<T>(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void): this;
get<T>(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void): this;
get(sql: string, ...params: any[]): this;

all(sql: string, callback?: (this: Statement, err: Error | null, rows: any[]) => void): this;
all(sql: string, params: any, callback?: (this: Statement, err: Error | null, rows: any[]) => void): this;
all<T>(sql: string, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this;
all<T>(sql: string, params: any, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this;
all(sql: string, ...params: any[]): this;

each(sql: string, callback?: (this: Statement, err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each(sql: string, ...params: any[]): this;

exec(sql: string, callback?: (this: Statement, err: Error | null) => void): this;
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gristlabs/sqlite3",
"description": "Asynchronous, non-blocking SQLite3 bindings",
"version": "5.1.4-grist.8",
"version": "5.1.7-grist.1",
"homepage": "https://github.com/gristlabs/node-sqlite3",
"author": {
"name": "Mapbox",
Expand All @@ -19,6 +19,7 @@
]
},
"contributors": [
"Daniel Lockyer <hi@daniellockyer.com>",
"Konstantin Käfer <mail@kkaefer.com>",
"Dane Springmeyer <dane@mapbox.com>",
"Will White <will@mapbox.com>",
Expand Down Expand Up @@ -48,14 +49,15 @@
"url": "https://github.com/gristlabs/node-sqlite3.git"
},
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.0",
"node-addon-api": "^4.2.0",
"bindings": "^1.5.0",
"node-addon-api": "^7.0.0",
"prebuild-install": "^7.1.1",
"tar": "^6.1.11"
},
"devDependencies": {
"eslint": "6.8.0",
"mocha": "7.2.0",
"node-pre-gyp-github": "1.4.4"
"eslint": "8.56.0",
"mocha": "10.2.0",
"prebuild": "12.1.0"
},
"peerDependencies": {
"node-gyp": "11.x"
Expand All @@ -69,13 +71,11 @@
"node-gyp": "11.x"
},
"scripts": {
"build": "node-pre-gyp build",
"build:debug": "node-pre-gyp build --debug",
"install": "node-pre-gyp install --fallback-to-build",
"pretest": "node test/support/createdb.js",
"test": "mocha -R spec --timeout 480000",
"test:memory": "node test/support/memory_check.js",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this?

"pack": "node-pre-gyp package"
"install": "prebuild-install -r napi || node-gyp rebuild",
"prebuild": "prebuild --runtime napi --all --verbose",
"rebuild": "node-gyp rebuild",
"upload": "prebuild --verbose --prerelease",
"test": "node test/support/createdb.js && mocha -R spec --timeout 480000"
},
"license": "BSD-3-Clause",
"keywords": [
Expand Down
11 changes: 5 additions & 6 deletions src/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ template <class Item, class Parent> class Async {
}

static void listener(uv_async_t* handle) {
Async* async = static_cast<Async*>(handle->data);
auto* async = static_cast<Async*>(handle->data);
std::vector<Item*> rows;
NODE_SQLITE3_MUTEX_LOCK(&async->mutex)
rows.swap(async->data);
NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex)
for (unsigned int i = 0, size = rows.size(); i < size; i++) {
async->callback(async->parent, rows[i]);
}
for(auto row : rows)
async->callback(async->parent, row);
}

static void close(uv_handle_t* handle) {
assert(handle != NULL);
assert(handle->data != NULL);
Async* async = static_cast<Async*>(handle->data);
auto* async = static_cast<Async*>(handle->data);
delete async;
}

Expand All @@ -56,7 +55,7 @@ template <class Item, class Parent> class Async {

void add(Item* item) {
NODE_SQLITE3_MUTEX_LOCK(&mutex);
data.push_back(item);
data.emplace_back(item);
NODE_SQLITE3_MUTEX_UNLOCK(&mutex)
}

Expand Down
Loading