potluckdb 0.0.0-reserved.0 → 0.8.0-dev.3
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/LICENSE +201 -0
- package/README.md +86 -2
- package/THIRD_PARTY_NOTICES.md +73 -0
- package/index.d.mts +6 -0
- package/index.d.ts +165 -0
- package/index.mjs +5 -0
- package/lib/binding.js +55 -0
- package/lib/darwin-arm64.js +3 -0
- package/lib/darwin-x64.js +3 -0
- package/lib/database.js +117 -0
- package/lib/index.js +3 -0
- package/lib/linux-arm64.js +3 -0
- package/lib/linux-x64.js +3 -0
- package/lib/linuxmusl-arm64.js +4 -0
- package/lib/linuxmusl-x64.js +4 -0
- package/lib/methods/aggregate.js +43 -0
- package/lib/methods/backup.js +67 -0
- package/lib/methods/explain.js +9 -0
- package/lib/methods/function.js +31 -0
- package/lib/methods/inspect.js +7 -0
- package/lib/methods/pragma.js +12 -0
- package/lib/methods/serialize.js +16 -0
- package/lib/methods/table.js +195 -0
- package/lib/methods/transaction.js +78 -0
- package/lib/methods/wrappers.js +54 -0
- package/lib/sqlite-error.js +25 -0
- package/lib/targets.js +46 -0
- package/lib/util.js +12 -0
- package/lib/win32-arm64.js +3 -0
- package/lib/win32-x64.js +3 -0
- package/package.json +86 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PotluckDB for Node.js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`potluckdb` is a drop-in replacement for
|
|
4
|
+
[better-sqlite3](https://github.com/WiseLibs/better-sqlite3) that runs on
|
|
5
|
+
PotluckDB's own build of SQLite. Your code stays the same; only the `require`
|
|
6
|
+
changes.
|
|
7
|
+
|
|
8
|
+
> **Status: pre-release.** It does not sync yet; that comes in later releases.
|
|
9
|
+
|
|
10
|
+
## Quickstart
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install potluckdb
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const Database = require('potluckdb'); // was: require('better-sqlite3')
|
|
18
|
+
const db = new Database('app.db');
|
|
19
|
+
db.prepare('select potluckdb_version() as p, sqlite_version() as s').get(); // { p: '0.8.0-dev.1', s: '3.54.1' }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
ES modules work too (`import Database from 'potluckdb'`), and TypeScript types
|
|
23
|
+
are included. They match `@types/better-sqlite3`, so code typed against
|
|
24
|
+
better-sqlite3 compiles unchanged.
|
|
25
|
+
|
|
26
|
+
## API
|
|
27
|
+
|
|
28
|
+
The same as better-sqlite3 13: see its
|
|
29
|
+
[API documentation](https://github.com/WiseLibs/better-sqlite3/blob/v13.0.3/docs/api.md).
|
|
30
|
+
PotluckDB adds one property:
|
|
31
|
+
|
|
32
|
+
- `Database.coreVersion`: the PotluckDB build in use, for example `'0.8.0-dev.1'`
|
|
33
|
+
(the same as `select potluckdb_version()`).
|
|
34
|
+
|
|
35
|
+
## Platforms
|
|
36
|
+
|
|
37
|
+
Node.js 20 or later. `npm install` picks a ready-made binary for your platform;
|
|
38
|
+
nothing is compiled.
|
|
39
|
+
|
|
40
|
+
| Platform | Package | Needs |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| Linux x64, arm64 | `@potluckdb/linux-x64-gnu`, `@potluckdb/linux-arm64-gnu` | glibc 2.28 or later |
|
|
43
|
+
| Linux x64, arm64 (Alpine) | `@potluckdb/linux-x64-musl`, `@potluckdb/linux-arm64-musl` | musl |
|
|
44
|
+
| macOS Apple silicon, Intel | `@potluckdb/macos-arm64`, `@potluckdb/macos-x64` | macOS 11 or later |
|
|
45
|
+
| Windows x64 | `@potluckdb/windows-x64` | Windows 10 or later |
|
|
46
|
+
| Windows ARM64 | `@potluckdb/windows-arm64` | Windows 11 |
|
|
47
|
+
|
|
48
|
+
If you install with optional dependencies turned off (`--omit=optional`), the
|
|
49
|
+
platform package is missing and `potluckdb` says so when it loads.
|
|
50
|
+
|
|
51
|
+
## Differences from better-sqlite3
|
|
52
|
+
|
|
53
|
+
better-sqlite3 compiles SQLite with its own build options; PotluckDB's library
|
|
54
|
+
has its own. Foreign keys are on and double-quoted string literals are off, as in
|
|
55
|
+
better-sqlite3. What differs:
|
|
56
|
+
|
|
57
|
+
- `DELETE ... LIMIT` and `UPDATE ... LIMIT` are not available.
|
|
58
|
+
- The page cache is SQLite's default, 2 MB, not 16 MB. For 16 MB:
|
|
59
|
+
`db.pragma('cache_size = -16000')`.
|
|
60
|
+
- In WAL mode, `synchronous` stays `FULL` (better-sqlite3: `NORMAL`). For
|
|
61
|
+
better-sqlite3's behaviour: `db.pragma('synchronous = NORMAL')`.
|
|
62
|
+
- File names starting with `file:` are [URIs](https://sqlite.org/uri.html).
|
|
63
|
+
- The `verbose` logger receives bound values in full, not cut at 32 bytes.
|
|
64
|
+
- FTS3 and FTS4 queries use SQLite's standard syntax, without `AND`, `NOT`
|
|
65
|
+
and parentheses (FTS5 is the same in both).
|
|
66
|
+
- `LIKE` matches BLOBs, and `soundex()` is not available.
|
|
67
|
+
|
|
68
|
+
## Licence
|
|
69
|
+
|
|
70
|
+
Apache-2.0. Parts come from better-sqlite3 and @types/better-sqlite3 (both MIT);
|
|
71
|
+
see `THIRD_PARTY_NOTICES.md`. The platform packages contain the PotluckDB
|
|
72
|
+
library, which has its own licence (`LICENSE.txt` in each).
|
|
73
|
+
|
|
74
|
+
## Developing
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
cd node
|
|
78
|
+
npm ci
|
|
79
|
+
POTLUCKDB_CORE_DIR=/path/to/core-archives npm run build # or omit it to download the release for package.json's version
|
|
80
|
+
npm test
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`npm run build` builds `build/Release/potluckdb.node` against a PotluckDB core
|
|
84
|
+
archive and copies it to `prebuilds/<platform>/`; `node scripts/package.js`
|
|
85
|
+
makes the npm packages from there. `npm test` runs better-sqlite3's own test
|
|
86
|
+
suite (with the failures listed in `test/known-failures.json`) and the tests in
|
|
87
|
+
`test/`.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
PotluckDB for Node.js is licensed under Apache-2.0 (see `LICENSE`). Parts of it
|
|
4
|
+
come from the projects below, under their own licences.
|
|
5
|
+
|
|
6
|
+
## better-sqlite3 13.0.3
|
|
7
|
+
|
|
8
|
+
https://github.com/WiseLibs/better-sqlite3, commit
|
|
9
|
+
`dbc2ea1165fef1f599b9be12faea33fa5e9d7ffb`.
|
|
10
|
+
|
|
11
|
+
Taken from it, with changes: the JavaScript layer (`lib/`), the Node-API
|
|
12
|
+
addon source (`src/`), the test extension (`deps/test_extension.c`) and the
|
|
13
|
+
test suite (`test/better-sqlite3/test/`, unmodified).
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
The MIT License (MIT)
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2017 Joshua Wise
|
|
19
|
+
|
|
20
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
22
|
+
in the Software without restriction, including without limitation the rights
|
|
23
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
25
|
+
furnished to do so, subject to the following conditions:
|
|
26
|
+
|
|
27
|
+
The above copyright notice and this permission notice shall be included in all
|
|
28
|
+
copies or substantial portions of the Software.
|
|
29
|
+
|
|
30
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
31
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
32
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
33
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
34
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
35
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
36
|
+
SOFTWARE.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## @types/better-sqlite3 9.6.0
|
|
40
|
+
|
|
41
|
+
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/better-sqlite3
|
|
42
|
+
|
|
43
|
+
Taken from it, with changes: the TypeScript declarations (`index.d.ts`).
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
MIT License
|
|
47
|
+
|
|
48
|
+
Copyright (c) Microsoft Corporation.
|
|
49
|
+
|
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
51
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
52
|
+
in the Software without restriction, including without limitation the rights
|
|
53
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
54
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
55
|
+
furnished to do so, subject to the following conditions:
|
|
56
|
+
|
|
57
|
+
The above copyright notice and this permission notice shall be included in all
|
|
58
|
+
copies or substantial portions of the Software.
|
|
59
|
+
|
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
61
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
62
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
63
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
64
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
65
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
66
|
+
SOFTWARE.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## SQLite
|
|
70
|
+
|
|
71
|
+
The platform packages (`@potluckdb/<platform>`) contain PotluckDB's build of
|
|
72
|
+
SQLite, which is in the public domain. Their `THIRD_PARTY_NOTICES.txt` has the
|
|
73
|
+
notice, and their `LICENSE.txt` has the licence of the PotluckDB library.
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Type declarations for the ES module entry point (index.mjs): the same
|
|
2
|
+
// Database as require('potluckdb'), plus SqliteError as a named export.
|
|
3
|
+
import Database = require('./index.js');
|
|
4
|
+
|
|
5
|
+
export default Database;
|
|
6
|
+
export declare const SqliteError: Database.SqliteError;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Type declarations for potluckdb, from @types/better-sqlite3 9.6.0 (MIT,
|
|
2
|
+
// Copyright (c) Microsoft Corporation; see THIRD_PARTY_NOTICES.md), with
|
|
3
|
+
// better-sqlite3 13's newer methods and potluckdb's additions.
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
|
|
6
|
+
// FIXME: Is this `any` really necessary?
|
|
7
|
+
type VariableArgFunction = (...params: any[]) => unknown;
|
|
8
|
+
type ArgumentTypes<F extends VariableArgFunction> = F extends (...args: infer A) => unknown ? A : never;
|
|
9
|
+
type ElementOf<T> = T extends Array<infer E> ? E : T;
|
|
10
|
+
|
|
11
|
+
declare namespace BetterSqlite3 {
|
|
12
|
+
interface Statement<BindParameters extends unknown[], Result = unknown> {
|
|
13
|
+
database: Database;
|
|
14
|
+
source: string;
|
|
15
|
+
reader: boolean;
|
|
16
|
+
readonly: boolean;
|
|
17
|
+
busy: boolean;
|
|
18
|
+
|
|
19
|
+
run(...params: BindParameters): Database.RunResult;
|
|
20
|
+
get(...params: BindParameters): Result | undefined;
|
|
21
|
+
all(...params: BindParameters): Result[];
|
|
22
|
+
iterate(...params: BindParameters): IterableIterator<Result>;
|
|
23
|
+
pluck(toggleState?: boolean): this;
|
|
24
|
+
expand(toggleState?: boolean): this;
|
|
25
|
+
raw(toggleState?: boolean): this;
|
|
26
|
+
bind(...params: BindParameters): this;
|
|
27
|
+
columns(): ColumnDefinition[];
|
|
28
|
+
safeIntegers(toggleState?: boolean): this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ColumnDefinition {
|
|
32
|
+
name: string;
|
|
33
|
+
column: string | null;
|
|
34
|
+
table: string | null;
|
|
35
|
+
database: string | null;
|
|
36
|
+
type: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface Transaction<F extends VariableArgFunction> {
|
|
40
|
+
(...params: ArgumentTypes<F>): ReturnType<F>;
|
|
41
|
+
default(...params: ArgumentTypes<F>): ReturnType<F>;
|
|
42
|
+
deferred(...params: ArgumentTypes<F>): ReturnType<F>;
|
|
43
|
+
immediate(...params: ArgumentTypes<F>): ReturnType<F>;
|
|
44
|
+
exclusive(...params: ArgumentTypes<F>): ReturnType<F>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface VirtualTableOptions {
|
|
48
|
+
rows: (...params: unknown[]) => Generator;
|
|
49
|
+
columns: string[];
|
|
50
|
+
parameters?: string[] | undefined;
|
|
51
|
+
safeIntegers?: boolean | undefined;
|
|
52
|
+
directOnly?: boolean | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface Database {
|
|
56
|
+
memory: boolean;
|
|
57
|
+
readonly: boolean;
|
|
58
|
+
name: string;
|
|
59
|
+
open: boolean;
|
|
60
|
+
inTransaction: boolean;
|
|
61
|
+
|
|
62
|
+
prepare<BindParameters extends unknown[] | {} = unknown[], Result = unknown>(
|
|
63
|
+
source: string,
|
|
64
|
+
): BindParameters extends unknown[] ? Statement<BindParameters, Result> : Statement<[BindParameters], Result>;
|
|
65
|
+
transaction<F extends VariableArgFunction>(fn: F): Transaction<F>;
|
|
66
|
+
exec(source: string): this;
|
|
67
|
+
pragma(source: string, options?: Database.PragmaOptions): unknown;
|
|
68
|
+
explain(source: string): unknown[];
|
|
69
|
+
function(
|
|
70
|
+
name: string,
|
|
71
|
+
cb: (...params: any[]) => any,
|
|
72
|
+
): this;
|
|
73
|
+
function(
|
|
74
|
+
name: string,
|
|
75
|
+
options: Database.RegistrationOptions,
|
|
76
|
+
cb: (...params: any[]) => any,
|
|
77
|
+
): this;
|
|
78
|
+
aggregate<T>(
|
|
79
|
+
name: string,
|
|
80
|
+
options: Database.RegistrationOptions & {
|
|
81
|
+
start?: T | (() => T);
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
83
|
+
step: (total: T, next: ElementOf<T>) => T | void;
|
|
84
|
+
inverse?: ((total: T, dropped: T) => T) | undefined;
|
|
85
|
+
result?: ((total: T) => unknown) | undefined;
|
|
86
|
+
},
|
|
87
|
+
): this;
|
|
88
|
+
loadExtension(path: string, entryPoint?: string): this;
|
|
89
|
+
close(): this;
|
|
90
|
+
defaultSafeIntegers(toggleState?: boolean): this;
|
|
91
|
+
backup(destinationFile: string, options?: Database.BackupOptions): Promise<Database.BackupMetadata>;
|
|
92
|
+
table(name: string, options: VirtualTableOptions): this;
|
|
93
|
+
unsafeMode(unsafe?: boolean): this;
|
|
94
|
+
serialize(options?: Database.SerializeOptions): Buffer;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface DatabaseConstructor {
|
|
98
|
+
new(filename?: string | Buffer, options?: Database.Options): Database;
|
|
99
|
+
(filename?: string, options?: Database.Options): Database;
|
|
100
|
+
prototype: Database;
|
|
101
|
+
SqliteError: SqliteErrorType;
|
|
102
|
+
/** The PotluckDB build in use, e.g. "0.8.0-dev.1" (the same as SQL's potluckdb_version()). */
|
|
103
|
+
readonly coreVersion: string;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare class SqliteErrorClass extends Error {
|
|
108
|
+
name: string;
|
|
109
|
+
message: string;
|
|
110
|
+
code: string;
|
|
111
|
+
constructor(message: string, code: string);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type SqliteErrorType = typeof SqliteErrorClass;
|
|
115
|
+
|
|
116
|
+
declare namespace Database {
|
|
117
|
+
interface RunResult {
|
|
118
|
+
changes: number;
|
|
119
|
+
lastInsertRowid: number | bigint;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface Options {
|
|
123
|
+
readonly?: boolean | undefined;
|
|
124
|
+
fileMustExist?: boolean | undefined;
|
|
125
|
+
timeout?: number | undefined;
|
|
126
|
+
verbose?: ((message?: unknown, ...additionalArgs: unknown[]) => void) | undefined;
|
|
127
|
+
nativeBinding?: string | undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
interface SerializeOptions {
|
|
131
|
+
attached?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface PragmaOptions {
|
|
135
|
+
simple?: boolean | undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface RegistrationOptions {
|
|
139
|
+
varargs?: boolean | undefined;
|
|
140
|
+
deterministic?: boolean | undefined;
|
|
141
|
+
safeIntegers?: boolean | undefined;
|
|
142
|
+
directOnly?: boolean | undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
type AggregateOptions = Parameters<BetterSqlite3.Database["aggregate"]>[1];
|
|
146
|
+
|
|
147
|
+
interface BackupMetadata {
|
|
148
|
+
totalPages: number;
|
|
149
|
+
remainingPages: number;
|
|
150
|
+
}
|
|
151
|
+
interface BackupOptions {
|
|
152
|
+
progress: (info: BackupMetadata) => number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type SqliteError = SqliteErrorType;
|
|
156
|
+
type Statement<BindParameters extends unknown[] | {} = unknown[], Result = unknown> = BindParameters extends
|
|
157
|
+
unknown[] ? BetterSqlite3.Statement<BindParameters, Result>
|
|
158
|
+
: BetterSqlite3.Statement<[BindParameters], Result>;
|
|
159
|
+
type ColumnDefinition = BetterSqlite3.ColumnDefinition;
|
|
160
|
+
type Transaction<T extends VariableArgFunction = VariableArgFunction> = BetterSqlite3.Transaction<T>;
|
|
161
|
+
type Database = BetterSqlite3.Database;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare const Database: BetterSqlite3.DatabaseConstructor;
|
|
165
|
+
export = Database;
|
package/index.mjs
ADDED
package/lib/binding.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { TARGETS, currentTarget } = require('./targets');
|
|
5
|
+
|
|
6
|
+
let DEFAULT_ADDON;
|
|
7
|
+
|
|
8
|
+
function getBinding(nativeBinding) {
|
|
9
|
+
// If a path was provided, load the binding from the filesystem.
|
|
10
|
+
if (typeof nativeBinding === 'string') {
|
|
11
|
+
// See <https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific>
|
|
12
|
+
const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;
|
|
13
|
+
return requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, '.node'));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// If an object was provided, use it as the binding directly.
|
|
17
|
+
if (typeof nativeBinding === 'object' && nativeBinding !== null) {
|
|
18
|
+
return nativeBinding;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// If we're using the default binding and it already exists, just return it.
|
|
22
|
+
if (DEFAULT_ADDON) {
|
|
23
|
+
return DEFAULT_ADDON;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// A local build (a development checkout; the published package has none).
|
|
27
|
+
for (const configuration of ['Debug', 'Release']) {
|
|
28
|
+
const filename = path.join(__dirname, '..', 'build', configuration, 'potluckdb.node');
|
|
29
|
+
if (fs.existsSync(filename)) return DEFAULT_ADDON = require(filename);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Otherwise, the platform package that npm installed with potluckdb.
|
|
33
|
+
return DEFAULT_ADDON = require(getPlatformPackagePath());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getPlatformPackagePath() {
|
|
37
|
+
const target = currentTarget();
|
|
38
|
+
if (!target) {
|
|
39
|
+
throw new Error(`potluckdb has no build for ${process.platform}-${process.arch}. `
|
|
40
|
+
+ `It runs on: ${Object.keys(TARGETS).join(', ')}.`);
|
|
41
|
+
}
|
|
42
|
+
const request = `@potluckdb/${target}/potluckdb.node`;
|
|
43
|
+
try {
|
|
44
|
+
return require.resolve(request);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
|
47
|
+
throw new Error(`potluckdb could not find its native library: the package @potluckdb/${target} is not installed. `
|
|
48
|
+
+ 'npm installs it together with potluckdb unless optional dependencies are turned off '
|
|
49
|
+
+ '(--omit=optional, --no-optional or a lockfile made on another platform). '
|
|
50
|
+
+ 'Reinstall potluckdb with optional dependencies included.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.getBinding = getBinding;
|
|
55
|
+
exports.getPlatformPackagePath = getPlatformPackagePath;
|