@homeofthings/sqlite3 6.3.1 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -30
- package/binding.gyp +4 -3
- package/deps/common-sqlite.gypi +1 -1
- package/deps/sqlite-amalgamation-3530000/shell.c +37279 -0
- package/deps/sqlite-amalgamation-3530000/sqlite3.c +268826 -0
- package/deps/sqlite-amalgamation-3530000/sqlite3.h +14335 -0
- package/deps/sqlite-amalgamation-3530000/sqlite3ext.h +739 -0
- package/deps/sqlite3.gyp +4 -32
- package/lib/promise/database.js +14 -2
- package/lib/promise/index.d.ts +1 -0
- package/lib/promise/index.mjs +9 -0
- package/lib/promise/statement.js +4 -0
- package/lib/sqlite3-binding.js +1 -1
- package/lib/sqlite3-callback.js +207 -0
- package/lib/sqlite3.d.ts +25 -0
- package/lib/sqlite3.js +6 -206
- package/lib/sqlite3.mjs +78 -0
- package/package.json +27 -18
- package/prebuilds/darwin-arm64/@homeofthings+sqlite3.glibc.node +0 -0
- package/prebuilds/darwin-x64/@homeofthings+sqlite3.glibc.node +0 -0
- package/prebuilds/linux-arm64/@homeofthings+sqlite3.glibc.node +0 -0
- package/prebuilds/linux-arm64/@homeofthings+sqlite3.musl.node +0 -0
- package/prebuilds/linux-x64/@homeofthings+sqlite3.glibc.node +0 -0
- package/prebuilds/linux-x64/@homeofthings+sqlite3.musl.node +0 -0
- package/prebuilds/win32-x64/@homeofthings+sqlite3.glibc.node +0 -0
- package/src/backup.cc +8 -0
- package/src/macros.h +2 -19
- package/src/node_sqlite3.cc +0 -11
- package/deps/extract.js +0 -19
- package/deps/sqlite-autoconf-3510300.tar.gz +0 -0
package/README.md
CHANGED
|
@@ -2,25 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
**Note:** This repository is forked from [TryGhost/node-sqlite3](https://github.com/TryGhost/node-sqlite3) which was marked as deprecated/unmaintained.
|
|
4
4
|
|
|
5
|
+
**Note:** Fortunately, there is already another well maintained fork: [AppThreat/node-sqlite3](https://github.com/AppThreat/node-sqlite3). Unfortunately, this fork didn't appear in the list of forks of TryGhost/node-sqlite3, which is why I created this fork here.
|
|
6
|
+
|
|
7
|
+
**So you have the choice**
|
|
8
|
+
|
|
5
9
|
---
|
|
6
10
|
Asynchronous, non-blocking [SQLite3](https://sqlite.org/) bindings for [Node.js](http://nodejs.org/).
|
|
7
11
|
|
|
8
12
|
[](https://badge.fury.io/js/%40homeofthings%2Fsqlite3)
|
|
13
|
+

|
|
9
14
|
[](https://github.com/gms1/node-sqlite3/actions/workflows/ci.yml)
|
|
15
|
+
[](https://codecov.io/gh/gms1/node-sqlite3)
|
|
10
16
|
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3?ref=badge_shield)
|
|
11
|
-
|
|
12
|
-
[](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api)
|
|
17
|
+

|
|
13
18
|
|
|
14
19
|
# Features
|
|
15
20
|
|
|
21
|
+
- Bundles SQLite v3.53.0, or you can build using a local SQLite (or SqlCipher,...)
|
|
16
22
|
- Straightforward query and parameter binding interface
|
|
17
23
|
- Full Buffer/Blob support
|
|
18
|
-
- Extensive
|
|
19
|
-
- [Query serialization](
|
|
20
|
-
- [Extension support](
|
|
24
|
+
- Extensive debugging support via [verbose mode](docs/API.md#verbose-mode)
|
|
25
|
+
- [Query serialization](docs/API.md#databaseserialize) API
|
|
26
|
+
- [Extension support](docs/API.md#databaseloadextension), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html)
|
|
21
27
|
- Big test suite
|
|
22
|
-
- Written in modern C++
|
|
23
|
-
-
|
|
28
|
+
- Written in modern C++
|
|
29
|
+
- Is built using hardening flags
|
|
30
|
+
- Promise-based API
|
|
31
|
+
- supports ESM and CJS
|
|
24
32
|
|
|
25
33
|
# Installing
|
|
26
34
|
|
|
@@ -32,27 +40,24 @@ npm install @homeofthings/sqlite3
|
|
|
32
40
|
# or
|
|
33
41
|
yarn add @homeofthings/sqlite3
|
|
34
42
|
```
|
|
35
|
-
* GitHub's `main` branch: `npm install https://github.com/gms1/node-sqlite3/tarball/main`
|
|
36
43
|
|
|
37
44
|
### Prebuilt binaries
|
|
38
45
|
|
|
39
|
-
`@homeofthings/sqlite3` uses [Node-API](https://nodejs.org/api/n-api.html) so prebuilt binaries do not need to be built for specific Node versions. Prebuilt binaries are
|
|
46
|
+
`@homeofthings/sqlite3` uses [Node-API](https://nodejs.org/api/n-api.html) so prebuilt binaries do not need to be built for specific Node versions. Prebuilt binaries are built as NAPI-version-agnostic (`@homeofthings+sqlite3.*.node`) using the `--napi` flag, and work on any Node.js version that supports the NAPI version used at compile time. Requires Node.js v20.17.0 or later.
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
Prebuilt binaries are bundled inside the npm package using [`prebuildify`](https://github.com/prebuild/prebuildify) and loaded at runtime by [`node-gyp-build`](https://github.com/prebuild/node-gyp-build). No separate download step is needed — `npm install` just works. The following targets are currently provided:
|
|
42
49
|
|
|
43
50
|
* `darwin-arm64`
|
|
44
51
|
* `darwin-x64`
|
|
45
|
-
* `linux-arm64`
|
|
46
|
-
* `linux-x64`
|
|
47
|
-
* `
|
|
48
|
-
* `
|
|
52
|
+
* `linux-arm64` (glibc)
|
|
53
|
+
* `linux-x64` (glibc)
|
|
54
|
+
* `linux-arm64` (musl)
|
|
55
|
+
* `linux-x64` (musl)
|
|
49
56
|
* `win32-x64`
|
|
50
57
|
|
|
51
|
-
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).
|
|
52
|
-
|
|
53
58
|
Support for other platforms and architectures may be added in the future if CI supports building on them.
|
|
54
59
|
|
|
55
|
-
If your
|
|
60
|
+
If your platform isn't supported, `node-gyp-build` automatically falls back to building from source using `node-gyp`.
|
|
56
61
|
|
|
57
62
|
### Other ways to install
|
|
58
63
|
|
|
@@ -105,6 +110,37 @@ async function main() {
|
|
|
105
110
|
main().catch(console.error);
|
|
106
111
|
```
|
|
107
112
|
|
|
113
|
+
## ESM and CJS Support
|
|
114
|
+
|
|
115
|
+
This package supports both CommonJS (CJS) and ECMAScript Modules (ESM):
|
|
116
|
+
|
|
117
|
+
### CJS (CommonJS)
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
// Default import
|
|
121
|
+
const sqlite3 = require('@homeofthings/sqlite3');
|
|
122
|
+
|
|
123
|
+
// Destructured import
|
|
124
|
+
const { Database, SqliteDatabase } = require('@homeofthings/sqlite3');
|
|
125
|
+
|
|
126
|
+
// Promise subpath import
|
|
127
|
+
const { SqliteDatabase } = require('@homeofthings/sqlite3/promise');
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### ESM (ECMAScript Modules)
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
// Default import
|
|
134
|
+
import sqlite3 from '@homeofthings/sqlite3';
|
|
135
|
+
|
|
136
|
+
// Named imports
|
|
137
|
+
import { Database, OPEN_CREATE, SqliteDatabase } from '@homeofthings/sqlite3';
|
|
138
|
+
|
|
139
|
+
// Promise subpath import
|
|
140
|
+
import { SqliteDatabase } from '@homeofthings/sqlite3/promise';
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
|
|
108
144
|
# Usage
|
|
109
145
|
|
|
110
146
|
**Note:** the module must be [installed](#installing) before use.
|
|
@@ -132,10 +168,11 @@ db.close();
|
|
|
132
168
|
|
|
133
169
|
## Source install
|
|
134
170
|
|
|
135
|
-
To
|
|
171
|
+
To build from source, use
|
|
136
172
|
|
|
137
173
|
```bash
|
|
138
|
-
|
|
174
|
+
cd node_modules/@homeofthings/sqlite3
|
|
175
|
+
npx node-gyp rebuild --sqlite=/usr/local
|
|
139
176
|
```
|
|
140
177
|
|
|
141
178
|
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.
|
|
@@ -143,7 +180,8 @@ If building against an external sqlite3 make sure to have the development header
|
|
|
143
180
|
Note, if building against homebrew-installed sqlite on OS X you can do:
|
|
144
181
|
|
|
145
182
|
```bash
|
|
146
|
-
|
|
183
|
+
cd node_modules/@homeofthings/sqlite3
|
|
184
|
+
npx node-gyp rebuild --sqlite=/usr/local/opt/sqlite/
|
|
147
185
|
```
|
|
148
186
|
|
|
149
187
|
## Custom file header (magic)
|
|
@@ -151,7 +189,8 @@ npm install --build-from-source --sqlite=/usr/local/opt/sqlite/
|
|
|
151
189
|
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.
|
|
152
190
|
|
|
153
191
|
```bash
|
|
154
|
-
|
|
192
|
+
cd node_modules/@homeofthings/sqlite3
|
|
193
|
+
npx node-gyp rebuild --sqlite_magic="MyCustomMagic15"
|
|
155
194
|
```
|
|
156
195
|
|
|
157
196
|
Note that the magic *must* be exactly 15 characters long (16 bytes including null terminator).
|
|
@@ -168,13 +207,15 @@ To build `sqlite3` for node-webkit:
|
|
|
168
207
|
|
|
169
208
|
```bash
|
|
170
209
|
NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
|
|
171
|
-
|
|
210
|
+
cd node_modules/@homeofthings/sqlite3
|
|
211
|
+
npx node-gyp rebuild --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
|
|
172
212
|
```
|
|
173
213
|
|
|
174
214
|
You can also run this command from within a `@homeofthings/sqlite3` checkout:
|
|
175
215
|
|
|
176
216
|
```bash
|
|
177
|
-
|
|
217
|
+
cd node_modules/@homeofthings/sqlite3
|
|
218
|
+
npx node-gyp rebuild --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
|
|
178
219
|
```
|
|
179
220
|
|
|
180
221
|
Remember the following:
|
|
@@ -193,7 +234,8 @@ For instructions on building SQLCipher, see [Building SQLCipher for Node.js](htt
|
|
|
193
234
|
To run against SQLCipher, you need to compile `sqlite3` from source by passing build options like:
|
|
194
235
|
|
|
195
236
|
```bash
|
|
196
|
-
|
|
237
|
+
cd node_modules/@homeofthings/sqlite3
|
|
238
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=/usr/
|
|
197
239
|
|
|
198
240
|
node -e 'require("@homeofthings/sqlite3")'
|
|
199
241
|
```
|
|
@@ -207,7 +249,8 @@ Set the location where `brew` installed it:
|
|
|
207
249
|
```bash
|
|
208
250
|
export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
|
|
209
251
|
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher"
|
|
210
|
-
|
|
252
|
+
cd node_modules/@homeofthings/sqlite3
|
|
253
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=`brew --prefix`
|
|
211
254
|
|
|
212
255
|
node -e 'require("@homeofthings/sqlite3")'
|
|
213
256
|
```
|
|
@@ -220,23 +263,26 @@ Set the location where `make` installed it:
|
|
|
220
263
|
export LDFLAGS="-L/usr/local/lib"
|
|
221
264
|
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
|
|
222
265
|
export CXXFLAGS="$CPPFLAGS"
|
|
223
|
-
|
|
266
|
+
cd node_modules/@homeofthings/sqlite3
|
|
267
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose
|
|
224
268
|
|
|
225
269
|
node -e 'require("@homeofthings/sqlite3")'
|
|
226
270
|
```
|
|
227
271
|
|
|
228
272
|
### Custom builds and Electron
|
|
229
273
|
|
|
230
|
-
Running `sqlite3` through [electron-rebuild](https://github.com/electron/electron-rebuild) does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible.
|
|
274
|
+
Running `sqlite3` through [electron-rebuild](https://github.com/electron/electron-rebuild) does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. So your command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):
|
|
231
275
|
|
|
232
276
|
```bash
|
|
233
|
-
|
|
277
|
+
cd node_modules/@homeofthings/sqlite3
|
|
278
|
+
npx node-gyp rebuild --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
|
|
234
279
|
```
|
|
235
280
|
|
|
236
281
|
In the case of MacOS with Homebrew, the command should look like the following:
|
|
237
282
|
|
|
238
283
|
```bash
|
|
239
|
-
|
|
284
|
+
cd node_modules/@homeofthings/sqlite3
|
|
285
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
|
|
240
286
|
```
|
|
241
287
|
|
|
242
288
|
# Testing
|
|
@@ -245,6 +291,34 @@ npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher
|
|
|
245
291
|
npm test
|
|
246
292
|
```
|
|
247
293
|
|
|
294
|
+
# Benchmarks
|
|
295
|
+
|
|
296
|
+
## Driver Comparison
|
|
297
|
+
|
|
298
|
+
The `tools/benchmark-drivers` directory contains a comprehensive benchmark suite comparing different SQLite drivers for Node.js:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
cd tools/benchmark-drivers
|
|
302
|
+
npm install
|
|
303
|
+
node index.js
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
This compares `@homeofthings/sqlite3` against other popular SQLite drivers:
|
|
307
|
+
- `better-sqlite3` - Synchronous, high-performance
|
|
308
|
+
- `node:sqlite` - Built-in Node.js SQLite (v22.6.0+)
|
|
309
|
+
|
|
310
|
+
See [tools/benchmark-drivers/README.md](tools/benchmark-drivers/README.md) for details.
|
|
311
|
+
|
|
312
|
+
**Key insight**: Async drivers like `@homeofthings/sqlite3` show lower raw throughput but provide better event loop availability, allowing other operations to proceed concurrently. Sync drivers block the event loop completely.
|
|
313
|
+
|
|
314
|
+
## Internal Benchmarks
|
|
315
|
+
|
|
316
|
+
Internal performance benchmarks are available in `tools/benchmark-internal`:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
node tools/benchmark-internal/run.js
|
|
320
|
+
```
|
|
321
|
+
|
|
248
322
|
# Contributors
|
|
249
323
|
|
|
250
324
|
* [Daniel Lockyer](https://github.com/daniellockyer)
|
|
@@ -269,7 +343,7 @@ Thanks to [Orlando Vazquez](https://github.com/orlandov),
|
|
|
269
343
|
[Eric Fredricksen](https://github.com/grumdrig) and
|
|
270
344
|
[Ryan Dahl](https://github.com/ry) for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions.
|
|
271
345
|
|
|
272
|
-
This module was originally created by [Mapbox](https://mapbox.com/)
|
|
346
|
+
This module was originally created by [Mapbox](https://mapbox.com/), then it was taken over by [Ghost](https://ghost.org), but was then deprecated without prior notice, so that the original is no longer maintained. See [TryGhost/node-sqlite3](https://github.com/TryGhost/node-sqlite3)
|
|
273
347
|
|
|
274
348
|
# Changelog
|
|
275
349
|
|
package/binding.gyp
CHANGED
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"include_dirs": [
|
|
17
17
|
"<!@(node -p \"require('node-addon-api').include\")"],
|
|
18
|
+
"dependencies": [
|
|
19
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api"
|
|
20
|
+
],
|
|
18
21
|
"conditions": [
|
|
19
22
|
["sqlite != 'internal'", {
|
|
20
23
|
"include_dirs": [
|
|
@@ -36,7 +39,6 @@
|
|
|
36
39
|
},
|
|
37
40
|
{
|
|
38
41
|
"dependencies": [
|
|
39
|
-
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
40
42
|
"deps/sqlite3.gyp:sqlite3"
|
|
41
43
|
]
|
|
42
44
|
}
|
|
@@ -53,7 +55,6 @@
|
|
|
53
55
|
["OS=='win'", {
|
|
54
56
|
"msvs_settings": {
|
|
55
57
|
"VCCLCompilerTool": {
|
|
56
|
-
"ExceptionHandling": 1,
|
|
57
58
|
"BufferSecurityCheck": "true",
|
|
58
59
|
"ControlFlowGuard": "Guard"
|
|
59
60
|
},
|
|
@@ -94,4 +95,4 @@
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
]
|
|
97
|
-
}
|
|
98
|
+
}
|