@homeofthings/sqlite3 6.4.0 → 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 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
  [![npm version](https://badge.fury.io/js/%40homeofthings%2Fsqlite3.svg)](https://badge.fury.io/js/%40homeofthings%2Fsqlite3)
13
+ ![NPM Downloads](https://img.shields.io/npm/dm/%40homeofthings%2Fsqlite3)
9
14
  [![Build Status](https://github.com/gms1/node-sqlite3/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gms1/node-sqlite3/actions/workflows/ci.yml)
15
+ [![codecov](https://codecov.io/gh/gms1/node-sqlite3/graph/badge.svg?token=6H0X94BL3X)](https://codecov.io/gh/gms1/node-sqlite3)
10
16
  [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3?ref=badge_shield)
11
- [![N-API v3 Badge](https://img.shields.io/badge/N--API-v3-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api)
12
- [![N-API v6 Badge](https://img.shields.io/badge/N--API-v6-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api)
17
+ ![Node-API v9 Badge](https://raw.githubusercontent.com/nodejs/abi-stable-node/doc/assets/Node-API%20v9%20Badge.svg)
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 [debugging support](https://github.com/gms1/node-sqlite3/wiki/Debugging)
19
- - [Query serialization](https://github.com/gms1/node-sqlite3/wiki/Control-Flow) API
20
- - [Extension support](https://github.com/gms1/node-sqlite3/wiki/API#databaseloadextensionpath-callback), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html)
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++ and tested for memory leaks
23
- - Bundles SQLite v3.53.0, or you can build using a local SQLite
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 available for 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. Requires Node.js v20.17.0 or later.
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
- 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. The following targets are currently provided:
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
- * `linuxmusl-arm64`
48
- * `linuxmusl-x64`
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 environment isn't supported, it'll use `node-gyp` to build SQLite, but you will need to install a C++ compiler and linker.
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 skip searching for pre-compiled binaries, and force a build from source, use
171
+ To build from source, use
136
172
 
137
173
  ```bash
138
- npm install --build-from-source --sqlite=/usr/local
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
- npm install --build-from-source --sqlite=/usr/local/opt/sqlite/
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
- npm install --build-from-source --sqlite_magic="MyCustomMagic15"
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
- npm install @homeofthings/sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
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
- npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
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
- npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/
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
- npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`
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
- npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose
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. Your `npm install @homeofthings/sqlite3 --build-from-source` command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):
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
- npm install @homeofthings/sqlite3 --build-from-source --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
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
- npm install @homeofthings/sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers
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
@@ -299,8 +345,6 @@ Thanks to [Orlando Vazquez](https://github.com/orlandov),
299
345
 
300
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)
301
347
 
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
348
  # Changelog
305
349
 
306
350
  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
+ }