Skip to content
  • Sponsor TryGhost/node-sqlite3

  • Notifications You must be signed in to change notification settings
  • Fork 832
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TryGhost/node-sqlite3
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.1.6
Choose a base ref
...
head repository: TryGhost/node-sqlite3
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
76 changes: 33 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -27,28 +27,20 @@ jobs:
target:
- x64
node:
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
include:
- os: windows-latest
node: 16
node: 18
host: x86
target: x86
- os: macos-m1
node: 16
node: 18
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 }}
@@ -57,6 +49,10 @@ 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.3
if: contains(matrix.os, 'windows')
@@ -66,6 +62,9 @@ jobs:
- 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: |
@@ -83,48 +82,41 @@ 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

- 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 == 16
uses: actions/upload-artifact@v4
if: matrix.node == 18
with:
name: prebuilt-binaries
path: build/stage/*/*
path: prebuilds/*
retention-days: 7

- name: Upload binaries to GitHub Release
run: yarn node-pre-gyp-github publish
if: matrix.node == 16 && startsWith(github.ref, 'refs/tags/')
env:
NODE_PRE_GYP_GITHUB_TOKEN: ${{ github.token }}
run: yarn upload --upload-all ${{ github.token }}
if: matrix.node == 18 && startsWith(github.ref, 'refs/tags/')

build-qemu:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/')
strategy:
fail-fast: false
matrix:
node:
- 16
- 18
target:
- linux/arm64
variant:
@@ -134,16 +126,16 @@ jobs:
# musl x64 builds
- target: linux/amd64
variant: alpine3.15
node: 16
node: 18
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: |
@@ -157,18 +149,16 @@ 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
- name: Upload binaries to commit artifacts
uses: actions/upload-artifact@v3
if: matrix.node == 16
uses: actions/upload-artifact@v4
if: matrix.node == 18
with:
name: prebuilt-binaries
path: build/stage/*/*
path: prebuilds/*
retention-days: 7

- name: Upload binaries to GitHub Release
run: yarn install --ignore-scripts && yarn node-pre-gyp-github publish
if: matrix.node == 16 && startsWith(github.ref, 'refs/tags/')
env:
NODE_PRE_GYP_GITHUB_TOKEN: ${{ github.token }}
run: yarn install --ignore-scripts && yarn upload --upload-all ${{ github.token }}
if: matrix.node == 18 && startsWith(github.ref, 'refs/tags/')
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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,
44 changes: 17 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.41.1, or you can build using a local SQLite
- Bundles SQLite v3.45.0, or you can build using a local SQLite

# Installing

@@ -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

@@ -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
@@ -254,7 +242,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).

14 changes: 2 additions & 12 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
"includes": [ "deps/common-sqlite.gypi" ],
"variables": {
"sqlite%":"internal",
"sqlite_libname%":"sqlite3"
"sqlite_libname%":"sqlite3",
"module_name": "node_sqlite3",
},
"targets": [
{
@@ -52,17 +53,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%':'3410100',
'sqlite_version%':'3450000',
"toolset%":'',
},
'target_defaults': {
Binary file removed deps/sqlite-autoconf-3410100.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');
30 changes: 13 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
{
"name": "sqlite3",
"description": "Asynchronous, non-blocking SQLite3 bindings",
"version": "5.1.6",
"version": "5.1.7",
"homepage": "https://github.com/TryGhost/node-sqlite3",
"author": {
"name": "Mapbox",
"url": "https://mapbox.com/"
},
"binary": {
"module_name": "node_sqlite3",
"module_path": "./lib/binding/napi-v{napi_build_version}-{platform}-{libc}-{arch}",
"host": "https://github.com/TryGhost/node-sqlite3/releases/download/",
"remote_path": "v{version}",
"package_name": "napi-v{napi_build_version}-{platform}-{libc}-{arch}.tar.gz",
"napi_versions": [
3,
6
]
},
"contributors": [
"Daniel Lockyer <hi@daniellockyer.com>",
"Konstantin Käfer <mail@kkaefer.com>",
"Dane Springmeyer <dane@mapbox.com>",
"Will White <will@mapbox.com>",
@@ -48,14 +44,15 @@
"url": "https://github.com/TryGhost/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": "8.x"
@@ -69,12 +66,11 @@
"node-gyp": "8.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",
"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": [
11 changes: 5 additions & 6 deletions src/async.h
Original file line number Diff line number Diff line change
@@ -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;
}

@@ -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)
}

Loading