@homeofthings/sqlite3 6.4.0 → 7.0.1
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 +76 -31
- package/binding.gyp +4 -3
- 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 +1 -1
- package/lib/promise/index.d.ts +1 -0
- package/lib/promise/index.mjs +9 -0
- package/lib/sqlite3-binding.js +1 -1
- package/lib/sqlite3-callback.js +207 -0
- package/lib/sqlite3.d.ts +5 -0
- package/lib/sqlite3.js +6 -206
- package/lib/sqlite3.mjs +78 -0
- package/package.json +26 -17
- 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-arm64/@homeofthings+sqlite3.glibc.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-3530000.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,25 @@ 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
|
-
|
|
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).
|
|
57
|
+
* `win32-arm64`
|
|
52
58
|
|
|
53
59
|
Support for other platforms and architectures may be added in the future if CI supports building on them.
|
|
54
60
|
|
|
55
|
-
If your
|
|
61
|
+
If your platform isn't supported, `node-gyp-build` automatically falls back to building from source using `node-gyp`.
|
|
56
62
|
|
|
57
63
|
### Other ways to install
|
|
58
64
|
|
|
@@ -105,6 +111,37 @@ async function main() {
|
|
|
105
111
|
main().catch(console.error);
|
|
106
112
|
```
|
|
107
113
|
|
|
114
|
+
## ESM and CJS Support
|
|
115
|
+
|
|
116
|
+
This package supports both CommonJS (CJS) and ECMAScript Modules (ESM):
|
|
117
|
+
|
|
118
|
+
### CJS (CommonJS)
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
// Default import
|
|
122
|
+
const sqlite3 = require('@homeofthings/sqlite3');
|
|
123
|
+
|
|
124
|
+
// Destructured import
|
|
125
|
+
const { Database, SqliteDatabase } = require('@homeofthings/sqlite3');
|
|
126
|
+
|
|
127
|
+
// Promise subpath import
|
|
128
|
+
const { SqliteDatabase } = require('@homeofthings/sqlite3/promise');
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### ESM (ECMAScript Modules)
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
// Default import
|
|
135
|
+
import sqlite3 from '@homeofthings/sqlite3';
|
|
136
|
+
|
|
137
|
+
// Named imports
|
|
138
|
+
import { Database, OPEN_CREATE, SqliteDatabase } from '@homeofthings/sqlite3';
|
|
139
|
+
|
|
140
|
+
// Promise subpath import
|
|
141
|
+
import { SqliteDatabase } from '@homeofthings/sqlite3/promise';
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
|
|
108
145
|
# Usage
|
|
109
146
|
|
|
110
147
|
**Note:** the module must be [installed](#installing) before use.
|
|
@@ -132,10 +169,11 @@ db.close();
|
|
|
132
169
|
|
|
133
170
|
## Source install
|
|
134
171
|
|
|
135
|
-
To
|
|
172
|
+
To build from source, use
|
|
136
173
|
|
|
137
174
|
```bash
|
|
138
|
-
|
|
175
|
+
cd node_modules/@homeofthings/sqlite3
|
|
176
|
+
npx node-gyp rebuild --sqlite=/usr/local
|
|
139
177
|
```
|
|
140
178
|
|
|
141
179
|
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 +181,8 @@ If building against an external sqlite3 make sure to have the development header
|
|
|
143
181
|
Note, if building against homebrew-installed sqlite on OS X you can do:
|
|
144
182
|
|
|
145
183
|
```bash
|
|
146
|
-
|
|
184
|
+
cd node_modules/@homeofthings/sqlite3
|
|
185
|
+
npx node-gyp rebuild --sqlite=/usr/local/opt/sqlite/
|
|
147
186
|
```
|
|
148
187
|
|
|
149
188
|
## Custom file header (magic)
|
|
@@ -151,7 +190,8 @@ npm install --build-from-source --sqlite=/usr/local/opt/sqlite/
|
|
|
151
190
|
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
191
|
|
|
153
192
|
```bash
|
|
154
|
-
|
|
193
|
+
cd node_modules/@homeofthings/sqlite3
|
|
194
|
+
npx node-gyp rebuild --sqlite_magic="MyCustomMagic15"
|
|
155
195
|
```
|
|
156
196
|
|
|
157
197
|
Note that the magic *must* be exactly 15 characters long (16 bytes including null terminator).
|
|
@@ -168,13 +208,15 @@ To build `sqlite3` for node-webkit:
|
|
|
168
208
|
|
|
169
209
|
```bash
|
|
170
210
|
NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
|
|
171
|
-
|
|
211
|
+
cd node_modules/@homeofthings/sqlite3
|
|
212
|
+
npx node-gyp rebuild --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
|
|
172
213
|
```
|
|
173
214
|
|
|
174
215
|
You can also run this command from within a `@homeofthings/sqlite3` checkout:
|
|
175
216
|
|
|
176
217
|
```bash
|
|
177
|
-
|
|
218
|
+
cd node_modules/@homeofthings/sqlite3
|
|
219
|
+
npx node-gyp rebuild --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
|
|
178
220
|
```
|
|
179
221
|
|
|
180
222
|
Remember the following:
|
|
@@ -193,7 +235,8 @@ For instructions on building SQLCipher, see [Building SQLCipher for Node.js](htt
|
|
|
193
235
|
To run against SQLCipher, you need to compile `sqlite3` from source by passing build options like:
|
|
194
236
|
|
|
195
237
|
```bash
|
|
196
|
-
|
|
238
|
+
cd node_modules/@homeofthings/sqlite3
|
|
239
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=/usr/
|
|
197
240
|
|
|
198
241
|
node -e 'require("@homeofthings/sqlite3")'
|
|
199
242
|
```
|
|
@@ -207,7 +250,8 @@ Set the location where `brew` installed it:
|
|
|
207
250
|
```bash
|
|
208
251
|
export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
|
|
209
252
|
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher"
|
|
210
|
-
|
|
253
|
+
cd node_modules/@homeofthings/sqlite3
|
|
254
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=`brew --prefix`
|
|
211
255
|
|
|
212
256
|
node -e 'require("@homeofthings/sqlite3")'
|
|
213
257
|
```
|
|
@@ -220,23 +264,26 @@ Set the location where `make` installed it:
|
|
|
220
264
|
export LDFLAGS="-L/usr/local/lib"
|
|
221
265
|
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
|
|
222
266
|
export CXXFLAGS="$CPPFLAGS"
|
|
223
|
-
|
|
267
|
+
cd node_modules/@homeofthings/sqlite3
|
|
268
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose
|
|
224
269
|
|
|
225
270
|
node -e 'require("@homeofthings/sqlite3")'
|
|
226
271
|
```
|
|
227
272
|
|
|
228
273
|
### Custom builds and Electron
|
|
229
274
|
|
|
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.
|
|
275
|
+
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
276
|
|
|
232
277
|
```bash
|
|
233
|
-
|
|
278
|
+
cd node_modules/@homeofthings/sqlite3
|
|
279
|
+
npx node-gyp rebuild --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
|
|
234
280
|
```
|
|
235
281
|
|
|
236
282
|
In the case of MacOS with Homebrew, the command should look like the following:
|
|
237
283
|
|
|
238
284
|
```bash
|
|
239
|
-
|
|
285
|
+
cd node_modules/@homeofthings/sqlite3
|
|
286
|
+
npx node-gyp rebuild --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
|
|
240
287
|
```
|
|
241
288
|
|
|
242
289
|
# Testing
|
|
@@ -299,8 +346,6 @@ Thanks to [Orlando Vazquez](https://github.com/orlandov),
|
|
|
299
346
|
|
|
300
347
|
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)
|
|
301
348
|
|
|
302
|
-
I still hope that it will eventually be taken over by a larger organization, but in the meantime, I'm trying to maintain this fork here.
|
|
303
|
-
|
|
304
349
|
# Changelog
|
|
305
350
|
|
|
306
351
|
We use [GitHub releases](https://github.com/gms1/node-sqlite3/releases) for notes on the latest versions. See [CHANGELOG.md](https://github.com/gms1/node-sqlite3/blob/main/CHANGELOG.md) in git history for details on older versions.
|
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
|
+
}
|