@rocicorp/zero-sqlite3 1.0.9 → 1.0.10
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 +1 -0
- package/binding.gyp +1 -1
- package/deps/download.sh +4 -4
- package/deps/sqlite3.gyp +1 -1
- package/deps/test_extension.c +1 -1
- package/lib/database.js +1 -1
- package/lib/methods/transaction.js +3 -0
- package/package.json +9 -8
- package/src/addon.cpp +47 -0
- package/src/better_sqlite3.cpp +44 -2166
- package/src/objects/backup.cpp +120 -0
- package/src/objects/backup.hpp +36 -0
- package/src/objects/database.cpp +392 -0
- package/src/objects/database.hpp +102 -0
- package/src/objects/statement-iterator.cpp +113 -0
- package/src/objects/statement-iterator.hpp +50 -0
- package/src/objects/statement.cpp +446 -0
- package/src/objects/statement.hpp +59 -0
- package/src/util/bind-map.cpp +73 -0
- package/src/util/binder.cpp +193 -0
- package/src/util/constants.cpp +172 -0
- package/src/util/custom-aggregate.cpp +121 -0
- package/src/util/custom-function.cpp +59 -0
- package/src/util/custom-table.cpp +409 -0
- package/src/util/data-converter.cpp +17 -0
- package/src/util/data.cpp +194 -0
- package/src/util/helpers.cpp +109 -0
- package/src/util/macros.cpp +63 -0
- package/src/util/query-macros.cpp +71 -0
- package/src/util/row-builder.cpp +49 -0
- package/src/better_sqlite3.hpp +0 -1036
package/README.md
CHANGED
|
@@ -4,5 +4,6 @@ So far the changes are:
|
|
|
4
4
|
|
|
5
5
|
* Build the [bedrock](https://sqlite.org/src/timeline?r=bedrock) branch of SQLite to enable [`begin concurrent`](https://www.sqlite.org/src/doc/begin-concurrent/doc/begin_concurrent.md).
|
|
6
6
|
* Create a shell too, so we can debug db files created
|
|
7
|
+
* Supports both Node.js (20.x, 22.x, 23.x, 24.x) and Bun (>=1.1.0) runtimes
|
|
7
8
|
|
|
8
9
|
Other changes will be likely be made over time.
|
package/binding.gyp
CHANGED
package/deps/download.sh
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
|
|
3
3
|
# ===
|
|
4
|
-
# This script defines and generates the bundled
|
|
4
|
+
# This script defines and generates the bundled SQLite unit (sqlite3.c).
|
|
5
5
|
#
|
|
6
6
|
# The following steps are taken:
|
|
7
7
|
# 1. populate the shell environment with the defined compile-time options.
|
|
8
|
-
# 2. download and extract the
|
|
8
|
+
# 2. download and extract the SQLite source code into a temporary directory.
|
|
9
9
|
# 3. run "sh configure" and "make sqlite3.c" within the source directory.
|
|
10
10
|
# 4. copy the generated amalgamation into the output directory (./sqlite3).
|
|
11
11
|
# 5. export the defined compile-time options to a gyp file (./defines.gypi).
|
|
@@ -74,7 +74,7 @@ mkdir -p "$OUTPUT"
|
|
|
74
74
|
export CFLAGS=`echo $(echo "$DEFINES" | sed -e "/^\s*$/d" -e "s/^/-D/")`
|
|
75
75
|
|
|
76
76
|
echo "downloading source..."
|
|
77
|
-
curl -#f "https://sqlite.org/src/zip/$CHECKIN/SQLite-$CHECKIN.zip" > "$TEMP/source.zip" || exit 1
|
|
77
|
+
curl -#f "https://www.sqlite.org/src/zip/$CHECKIN/SQLite-$CHECKIN.zip" > "$TEMP/source.zip" || exit 1
|
|
78
78
|
|
|
79
79
|
echo "extracting source..."
|
|
80
80
|
unzip "$TEMP/source.zip" -d "$TEMP" > /dev/null || exit 1
|
|
@@ -84,7 +84,7 @@ echo "configuring amalgamation..."
|
|
|
84
84
|
sh configure > /dev/null || exit 1
|
|
85
85
|
|
|
86
86
|
echo "building amalgamation..."
|
|
87
|
-
make sqlite3.c > /dev/null || exit 1
|
|
87
|
+
make OPTIONS="$CFLAGS" sqlite3.c > /dev/null || exit 1
|
|
88
88
|
|
|
89
89
|
echo "copying amalgamation..."
|
|
90
90
|
cp sqlite3.c sqlite3.h sqlite3ext.h shell.c "$OUTPUT/" || exit 1
|
package/deps/sqlite3.gyp
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# ===
|
|
2
|
-
# This configuration defines options specific to compiling
|
|
2
|
+
# This configuration defines options specific to compiling SQLite itself.
|
|
3
3
|
# Compile-time options are loaded by the auto-generated file "defines.gypi".
|
|
4
4
|
# The --sqlite3 option can be provided to use a custom amalgamation instead.
|
|
5
5
|
# ===
|
package/deps/test_extension.c
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
SQLITE_EXTENSION_INIT1
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
|
-
This
|
|
5
|
+
This SQLite extension is used only for testing purposes (npm test).
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
static void TestExtensionFunction(sqlite3_context* pCtx, int nVal, sqlite3_value** _) {
|
package/lib/database.js
CHANGED
|
@@ -61,7 +61,7 @@ function Database(filenameGiven, options) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// Make sure the specified directory exists
|
|
64
|
-
if (!anonymous && !fs.existsSync(path.dirname(filename))) {
|
|
64
|
+
if (!anonymous && !filename.startsWith('file:') && !fs.existsSync(path.dirname(filename))) {
|
|
65
65
|
throw new TypeError('Cannot open database because the directory does not exist');
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -63,6 +63,9 @@ const wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, re
|
|
|
63
63
|
before.run();
|
|
64
64
|
try {
|
|
65
65
|
const result = apply.call(fn, this, arguments);
|
|
66
|
+
if (result && typeof result.then === 'function') {
|
|
67
|
+
throw new TypeError('Transaction function cannot return a promise');
|
|
68
|
+
}
|
|
66
69
|
after.run();
|
|
67
70
|
return result;
|
|
68
71
|
} catch (ex) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocicorp/zero-sqlite3",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "better-sqlite3 on bedrock",
|
|
5
5
|
"homepage": "https://github.com/rocicorp/zero-sqlite3",
|
|
6
6
|
"author": "Rocicorp",
|
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"binding.gyp",
|
|
17
|
-
"src
|
|
17
|
+
"src/**/*.[ch]pp",
|
|
18
18
|
"lib/**",
|
|
19
19
|
"deps/**",
|
|
20
20
|
"shell.sh"
|
|
21
21
|
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": "20.x || 22.x || 23.x || 24.x",
|
|
24
|
+
"bun": ">=1.1.0"
|
|
25
|
+
},
|
|
22
26
|
"types": "lib/index.d.ts",
|
|
23
27
|
"dependencies": {
|
|
24
28
|
"bindings": "^1.5.0",
|
|
@@ -26,7 +30,7 @@
|
|
|
26
30
|
},
|
|
27
31
|
"overrides": {
|
|
28
32
|
"prebuild": {
|
|
29
|
-
"node-abi": "4.
|
|
33
|
+
"node-abi": "4.13.1"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
@@ -35,7 +39,7 @@
|
|
|
35
39
|
"fs-extra": "^11.1.1",
|
|
36
40
|
"mocha": "^10.2.0",
|
|
37
41
|
"nodemark": "^0.3.0",
|
|
38
|
-
"prebuild": "^13.0.
|
|
42
|
+
"prebuild": "^13.0.1",
|
|
39
43
|
"sqlite": "^5.0.1",
|
|
40
44
|
"sqlite3": "^5.1.6"
|
|
41
45
|
},
|
|
@@ -43,12 +47,9 @@
|
|
|
43
47
|
"install": "prebuild-install || node-gyp rebuild --release",
|
|
44
48
|
"build-release": "node-gyp rebuild --release",
|
|
45
49
|
"build-debug": "node-gyp rebuild --debug",
|
|
46
|
-
"rebuild-release": "npm run lzz && npm run build-release",
|
|
47
|
-
"rebuild-debug": "npm run lzz && npm run build-debug",
|
|
48
50
|
"test": "mocha --exit --slow=75 --timeout=5000",
|
|
49
51
|
"benchmark": "node benchmark",
|
|
50
|
-
"download": "bash ./deps/download.sh"
|
|
51
|
-
"lzz": "lzz -hx hpp -sx cpp -k BETTER_SQLITE3 -d -hl -sl -e ./src/better_sqlite3.lzz"
|
|
52
|
+
"download": "bash ./deps/download.sh"
|
|
52
53
|
},
|
|
53
54
|
"license": "MIT",
|
|
54
55
|
"keywords": [
|
package/src/addon.cpp
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
struct Addon {
|
|
2
|
+
explicit Addon(v8::Isolate* isolate) :
|
|
3
|
+
privileged_info(NULL),
|
|
4
|
+
next_id(0),
|
|
5
|
+
cs(isolate) {}
|
|
6
|
+
|
|
7
|
+
static void Cleanup(void* ptr) {
|
|
8
|
+
Addon* addon = static_cast<Addon*>(ptr);
|
|
9
|
+
for (Database* db : addon->dbs) db->CloseHandles();
|
|
10
|
+
addon->dbs.clear();
|
|
11
|
+
delete addon;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
inline sqlite3_uint64 NextId() {
|
|
15
|
+
return next_id++;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static void ConfigureURI() {
|
|
19
|
+
static std::once_flag init_flag;
|
|
20
|
+
std::call_once(init_flag, [](){
|
|
21
|
+
const char* env = getenv("SQLITE_USE_URI");
|
|
22
|
+
if (env != NULL) {
|
|
23
|
+
if (strcmp(env, "1") == 0) {
|
|
24
|
+
int status = sqlite3_config(SQLITE_CONFIG_URI, 1);
|
|
25
|
+
assert(status == SQLITE_OK); ((void)status);
|
|
26
|
+
} else if (strcmp(env, "0") == 0) {
|
|
27
|
+
int status = sqlite3_config(SQLITE_CONFIG_URI, 0);
|
|
28
|
+
assert(status == SQLITE_OK); ((void)status);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static NODE_METHOD(JS_setErrorConstructor) {
|
|
35
|
+
REQUIRE_ARGUMENT_FUNCTION(first, v8::Local<v8::Function> SqliteError);
|
|
36
|
+
OnlyAddon->SqliteError.Reset(OnlyIsolate, SqliteError);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
v8::Global<v8::Function> Statement;
|
|
40
|
+
v8::Global<v8::Function> StatementIterator;
|
|
41
|
+
v8::Global<v8::Function> Backup;
|
|
42
|
+
v8::Global<v8::Function> SqliteError;
|
|
43
|
+
NODE_ARGUMENTS_POINTER privileged_info;
|
|
44
|
+
sqlite3_uint64 next_id;
|
|
45
|
+
CS cs;
|
|
46
|
+
std::set<Database*, Database::CompareDatabase> dbs;
|
|
47
|
+
};
|