@op-engineering/op-sqlite 7.3.0 → 8.0.0-beta0
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 +11 -3
- package/android/CMakeLists.txt +6 -0
- package/android/build.gradle +20 -1
- package/android/cpp-adapter.cpp +1 -1
- package/android/src/main/jniLibs/arm64-v8a/libsqlite_vec.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libsqlite_vec.so +0 -0
- package/android/src/main/jniLibs/x86/libsqlite_vec.so +0 -0
- package/android/src/main/jniLibs/x86_64/libsqlite_vec.so +0 -0
- package/cpp/DBHostObject.cpp +104 -107
- package/cpp/DBHostObject.h +1 -1
- package/cpp/PreparedStatementHostObject.cpp +39 -14
- package/cpp/PreparedStatementHostObject.h +17 -4
- package/cpp/bindings.cpp +12 -9
- package/cpp/bindings.h +2 -1
- package/cpp/bridge.cpp +229 -91
- package/cpp/bridge.h +13 -9
- package/cpp/libsql/bridge.cpp +212 -92
- package/cpp/libsql/bridge.h +7 -3
- package/cpp/macros.h +2 -2
- package/cpp/types.h +11 -8
- package/cpp/utils.cpp +43 -7
- package/cpp/utils.h +2 -0
- package/ios/OPSQLite.mm +15 -5
- package/ios/sqlitevec.xcframework/Info.plist +46 -0
- package/ios/sqlitevec.xcframework/ios-arm64/sqlitevec.framework/Info.plist +24 -0
- package/ios/sqlitevec.xcframework/ios-arm64/sqlitevec.framework/sqlitevec +0 -0
- package/ios/sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/Info.plist +24 -0
- package/ios/sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/sqlitevec +0 -0
- package/lib/commonjs/index.js +53 -30
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/module/NativeOPSQLite.js +2 -0
- package/lib/module/NativeOPSQLite.js.map +1 -1
- package/lib/module/index.js +55 -29
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeOPSQLite.d.ts.map +1 -0
- package/lib/typescript/{src → commonjs/src}/index.d.ts +11 -11
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeOPSQLite.d.ts +15 -0
- package/lib/typescript/module/src/NativeOPSQLite.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +163 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/op-sqlite.podspec +13 -4
- package/package.json +45 -15
- package/src/index.ts +80 -46
- package/android/.project +0 -17
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/lib/typescript/src/NativeOPSQLite.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- /package/lib/typescript/{src → commonjs/src}/NativeOPSQLite.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
**Current SQLite version: 3.45.1**
|
|
4
|
-
|
|
5
3
|
Created by [@ospfranco](https://twitter.com/ospfranco). **Please consider sponsoring!**.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
OP-SQLite has grown large to cover a lot of plugins, sqlite versions and APIs. Please read the full documentation before opening an issue.
|
|
8
6
|
|
|
9
7
|
[See the docs](https://ospfranco.notion.site/OP-SQLite-Documentation-a279a52102464d0cb13c3fa230d2f2dc?pvs=4)
|
|
10
8
|
|
|
9
|
+
Some of the big and external (back-ends, out-of-tree features, plugins) supported features:
|
|
10
|
+
|
|
11
|
+
- Vanilla sqlite ofc
|
|
12
|
+
- Libsql is supported as a sqlite backend
|
|
13
|
+
- SQLCipher is supported as a sqlite backend
|
|
14
|
+
- FTS5 plugin
|
|
15
|
+
- cr-sqlite plugin
|
|
16
|
+
- sqlite-vec plugin
|
|
17
|
+
- Reactive queries (currently with some issues, please donate)
|
|
18
|
+
|
|
11
19
|
# License
|
|
12
20
|
|
|
13
21
|
MIT License.
|
package/android/CMakeLists.txt
CHANGED
package/android/build.gradle
CHANGED
|
@@ -33,6 +33,7 @@ def useCRSQLite = false
|
|
|
33
33
|
def performanceMode = "0"
|
|
34
34
|
def sqliteFlags = ""
|
|
35
35
|
def enableFTS5 = false
|
|
36
|
+
def useSqliteVec = false
|
|
36
37
|
|
|
37
38
|
def packageJsonFile = new File("$rootDir/../package.json")
|
|
38
39
|
def packageJson = new JsonSlurper().parseText(packageJsonFile.text)
|
|
@@ -41,6 +42,7 @@ def opsqliteConfig = packageJson["op-sqlite"]
|
|
|
41
42
|
if(opsqliteConfig) {
|
|
42
43
|
useSQLCipher = opsqliteConfig["sqlcipher"]
|
|
43
44
|
useCRSQLite = opsqliteConfig["crsqlite"]
|
|
45
|
+
useSqliteVec = opsqliteConfig["sqliteVec"]
|
|
44
46
|
performanceMode = opsqliteConfig["performanceMode"] ? opsqliteConfig["performanceMode"] : ""
|
|
45
47
|
sqliteFlags = opsqliteConfig["sqliteFlags"] ? opsqliteConfig["sqliteFlags"] : ""
|
|
46
48
|
enableFTS5 = opsqliteConfig["fts5"]
|
|
@@ -71,6 +73,10 @@ if(enableFTS5) {
|
|
|
71
73
|
println "[OP-SQLITE] FTS5 enabled! 🔎"
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
if(useSqliteVec) {
|
|
77
|
+
println "[OP-SQLITE] Sqlite Vec enabled! ↗️"
|
|
78
|
+
}
|
|
79
|
+
|
|
74
80
|
if (isNewArchitectureEnabled()) {
|
|
75
81
|
apply plugin: "com.facebook.react"
|
|
76
82
|
}
|
|
@@ -138,6 +144,10 @@ android {
|
|
|
138
144
|
if(enableFTS5) {
|
|
139
145
|
cFlags += ["-DSQLITE_ENABLE_FTS4=1", "-DSQLITE_ENABLE_FTS3_PARENTHESIS=1", "-DSQLITE_ENABLE_FTS5=1"]
|
|
140
146
|
}
|
|
147
|
+
if(useSqliteVec) {
|
|
148
|
+
cFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
|
|
149
|
+
cppFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
|
|
150
|
+
}
|
|
141
151
|
|
|
142
152
|
cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
|
|
143
153
|
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
|
@@ -145,7 +155,8 @@ android {
|
|
|
145
155
|
"-DSQLITE_FLAGS='$sqliteFlags'",
|
|
146
156
|
"-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
|
|
147
157
|
"-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}",
|
|
148
|
-
"-DUSE_LIBSQL=${useLibsql ? 1 : 0}"
|
|
158
|
+
"-DUSE_LIBSQL=${useLibsql ? 1 : 0}",
|
|
159
|
+
"-DUSE_SQLITE_VEC=${useSqliteVec ? 1 : 0}"
|
|
149
160
|
abiFilters (*reactNativeArchitectures())
|
|
150
161
|
}
|
|
151
162
|
}
|
|
@@ -214,4 +225,12 @@ tasks.whenTaskAdded { task ->
|
|
|
214
225
|
task.dependsOn(it)
|
|
215
226
|
}
|
|
216
227
|
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (isNewArchitectureEnabled()) {
|
|
231
|
+
react {
|
|
232
|
+
jsRootDir = file("../src/")
|
|
233
|
+
libraryName = "opsqlite"
|
|
234
|
+
codegenJavaPackageName = "com.op.sqlite.example"
|
|
235
|
+
}
|
|
217
236
|
}
|
package/android/cpp-adapter.cpp
CHANGED
|
@@ -33,7 +33,7 @@ private:
|
|
|
33
33
|
std::string dbPathStr = dbPath->toStdString();
|
|
34
34
|
|
|
35
35
|
opsqlite::install(*jsiRuntime, jsCallInvoker, dbPathStr.c_str(),
|
|
36
|
-
"libcrsqlite");
|
|
36
|
+
"libcrsqlite", "libsqlite_vec");
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
static void clearStateNativeJsi(jni::alias_ref<jni::JObject> thiz) {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cpp/DBHostObject.cpp
CHANGED
|
@@ -39,7 +39,7 @@ void DBHostObject::auto_register_update_hook() {
|
|
|
39
39
|
if (operation != "DELETE") {
|
|
40
40
|
std::string query = "SELECT * FROM " + table_name +
|
|
41
41
|
" where rowid = " + std::to_string(rowId) + ";";
|
|
42
|
-
|
|
42
|
+
opsqlite_execute_host_objects(name, query, ¶ms, &results, metadata);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
jsCallInvoker->invokeAsync(
|
|
@@ -57,7 +57,7 @@ void DBHostObject::auto_register_update_hook() {
|
|
|
57
57
|
res.setProperty(
|
|
58
58
|
rt, "row",
|
|
59
59
|
jsi::Object::createFromHostObject(
|
|
60
|
-
rt, std::make_shared<
|
|
60
|
+
rt, std::make_shared<HostObject>(results->at(0))));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
callback->asObject(rt).asFunction(rt).call(rt, res);
|
|
@@ -171,17 +171,19 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
|
|
|
171
171
|
std::shared_ptr<ThreadPool> thread_pool,
|
|
172
172
|
std::string &db_name, std::string &path,
|
|
173
173
|
std::string &crsqlite_path,
|
|
174
|
+
std::string &sqlite_vec_path,
|
|
174
175
|
std::string &encryption_key)
|
|
175
176
|
: base_path(base_path), jsCallInvoker(jsCallInvoker),
|
|
176
177
|
thread_pool(thread_pool), db_name(db_name), rt(rt) {
|
|
177
178
|
|
|
178
179
|
#ifdef OP_SQLITE_USE_SQLCIPHER
|
|
179
|
-
BridgeResult result =
|
|
180
|
-
|
|
180
|
+
BridgeResult result = opsqlite_open(db_name, path, crsqlite_path,
|
|
181
|
+
sqlite_vec_path, encryption_key);
|
|
181
182
|
#elif OP_SQLITE_USE_LIBSQL
|
|
182
183
|
BridgeResult result = opsqlite_libsql_open(db_name, path, crsqlite_path);
|
|
183
184
|
#else
|
|
184
|
-
BridgeResult result =
|
|
185
|
+
BridgeResult result =
|
|
186
|
+
opsqlite_open(db_name, path, crsqlite_path, sqlite_vec_path);
|
|
185
187
|
#endif
|
|
186
188
|
|
|
187
189
|
if (result.type == SQLiteError) {
|
|
@@ -192,7 +194,7 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
|
|
|
192
194
|
};
|
|
193
195
|
|
|
194
196
|
void DBHostObject::create_jsi_functions() {
|
|
195
|
-
auto attach = HOSTFN("attach"
|
|
197
|
+
auto attach = HOSTFN("attach") {
|
|
196
198
|
if (count < 3) {
|
|
197
199
|
throw jsi::JSError(rt,
|
|
198
200
|
"[op-sqlite][attach] Incorrect number of arguments");
|
|
@@ -230,7 +232,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
230
232
|
return {};
|
|
231
233
|
});
|
|
232
234
|
|
|
233
|
-
auto detach = HOSTFN("detach"
|
|
235
|
+
auto detach = HOSTFN("detach") {
|
|
234
236
|
if (count < 2) {
|
|
235
237
|
throw std::runtime_error(
|
|
236
238
|
"[op-sqlite][detach] Incorrect number of arguments");
|
|
@@ -256,7 +258,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
256
258
|
return {};
|
|
257
259
|
});
|
|
258
260
|
|
|
259
|
-
auto close = HOSTFN("close"
|
|
261
|
+
auto close = HOSTFN("close") {
|
|
260
262
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
261
263
|
BridgeResult result = opsqlite_libsql_close(db_name);
|
|
262
264
|
#else
|
|
@@ -270,8 +272,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
270
272
|
return {};
|
|
271
273
|
});
|
|
272
274
|
|
|
273
|
-
auto remove = HOSTFN("delete"
|
|
274
|
-
|
|
275
|
+
auto remove = HOSTFN("delete") {
|
|
275
276
|
std::string path = std::string(base_path);
|
|
276
277
|
|
|
277
278
|
if (count == 1 && !args[0].isUndefined() && !args[0].isNull()) {
|
|
@@ -306,7 +307,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
306
307
|
return {};
|
|
307
308
|
});
|
|
308
309
|
|
|
309
|
-
auto
|
|
310
|
+
auto execute_raw = HOSTFN("executeRaw") {
|
|
310
311
|
const std::string query = args[0].asString(rt).utf8(rt);
|
|
311
312
|
std::vector<JSVariant> params;
|
|
312
313
|
|
|
@@ -315,59 +316,86 @@ void DBHostObject::create_jsi_functions() {
|
|
|
315
316
|
params = to_variant_vec(rt, originalParams);
|
|
316
317
|
}
|
|
317
318
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
319
|
+
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
320
|
+
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
|
|
321
|
+
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
322
|
+
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
323
|
+
|
|
324
|
+
auto task = [&rt, this, query, params = std::move(params), resolve,
|
|
325
|
+
reject, invoker = this->jsCallInvoker]() {
|
|
326
|
+
try {
|
|
327
|
+
std::vector<std::vector<JSVariant>> results;
|
|
321
328
|
|
|
322
329
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
323
|
-
|
|
324
|
-
|
|
330
|
+
auto status =
|
|
331
|
+
opsqlite_libsql_execute_raw(db_name, query, ¶ms, &results);
|
|
325
332
|
#else
|
|
326
|
-
|
|
333
|
+
auto status = opsqlite_execute_raw(db_name, query, ¶ms, &results);
|
|
327
334
|
#endif
|
|
328
335
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
336
|
+
invoker->invokeAsync([&rt, results = std::move(results),
|
|
337
|
+
status = std::move(status), resolve, reject] {
|
|
338
|
+
if (status.type == SQLiteOk) {
|
|
339
|
+
auto jsiResult = create_raw_result(rt, status, &results);
|
|
340
|
+
resolve->asObject(rt).asFunction(rt).call(rt,
|
|
341
|
+
std::move(jsiResult));
|
|
342
|
+
} else {
|
|
343
|
+
auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
|
|
344
|
+
auto error = errorCtr.callAsConstructor(
|
|
345
|
+
rt, jsi::String::createFromUtf8(rt, status.message));
|
|
346
|
+
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
} catch (std::exception &exc) {
|
|
351
|
+
invoker->invokeAsync([&rt, exc = std::move(exc), reject] {
|
|
352
|
+
auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
|
|
353
|
+
auto error = errorCtr.callAsConstructor(
|
|
354
|
+
rt, jsi::String::createFromAscii(rt, exc.what()));
|
|
355
|
+
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
thread_pool->queueWork(task);
|
|
361
|
+
|
|
362
|
+
return {};
|
|
363
|
+
}));
|
|
332
364
|
|
|
333
|
-
|
|
334
|
-
return jsiResult;
|
|
365
|
+
return promise;
|
|
335
366
|
});
|
|
336
367
|
|
|
337
|
-
auto
|
|
368
|
+
auto execute = HOSTFN("execute") {
|
|
338
369
|
const std::string query = args[0].asString(rt).utf8(rt);
|
|
339
370
|
std::vector<JSVariant> params;
|
|
340
371
|
|
|
341
372
|
if (count == 2) {
|
|
342
|
-
|
|
343
|
-
params = to_variant_vec(rt, originalParams);
|
|
373
|
+
params = to_variant_vec(rt, args[1]);
|
|
344
374
|
}
|
|
345
375
|
|
|
346
376
|
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
347
|
-
|
|
377
|
+
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
|
|
348
378
|
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
349
379
|
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
350
380
|
|
|
351
381
|
auto task = [&rt, this, query, params = std::move(params), resolve,
|
|
352
382
|
reject, invoker = this->jsCallInvoker]() {
|
|
353
383
|
try {
|
|
354
|
-
std::vector<std::vector<JSVariant>> results;
|
|
355
384
|
|
|
356
385
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
357
|
-
auto status =
|
|
358
|
-
opsqlite_libsql_execute_raw(db_name, query, ¶ms, &results);
|
|
386
|
+
auto status = opsqlite_libsql_execute(db_name, query, ¶ms);
|
|
359
387
|
#else
|
|
360
|
-
auto status =
|
|
388
|
+
auto status = opsqlite_execute(db_name, query, ¶ms);
|
|
361
389
|
#endif
|
|
362
|
-
|
|
390
|
+
|
|
363
391
|
// if (invalidated) {
|
|
364
392
|
// return;
|
|
365
393
|
// }
|
|
366
394
|
|
|
367
|
-
invoker->invokeAsync([&rt,
|
|
368
|
-
|
|
395
|
+
invoker->invokeAsync([&rt, status = std::move(status), resolve,
|
|
396
|
+
reject] {
|
|
369
397
|
if (status.type == SQLiteOk) {
|
|
370
|
-
auto jsiResult =
|
|
398
|
+
auto jsiResult = create_js_rows(rt, status);
|
|
371
399
|
resolve->asObject(rt).asFunction(rt).call(rt,
|
|
372
400
|
std::move(jsiResult));
|
|
373
401
|
} else {
|
|
@@ -379,8 +407,11 @@ void DBHostObject::create_jsi_functions() {
|
|
|
379
407
|
});
|
|
380
408
|
|
|
381
409
|
} catch (std::exception &exc) {
|
|
410
|
+
std::cout << "Exception executing function" << exc.what()
|
|
411
|
+
<< std::endl;
|
|
382
412
|
invoker->invokeAsync([&rt, exc = std::move(exc), reject] {
|
|
383
413
|
auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
|
|
414
|
+
auto what = exc.what();
|
|
384
415
|
auto error = errorCtr.callAsConstructor(
|
|
385
416
|
rt, jsi::String::createFromAscii(rt, exc.what()));
|
|
386
417
|
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
@@ -391,12 +422,12 @@ void DBHostObject::create_jsi_functions() {
|
|
|
391
422
|
thread_pool->queueWork(task);
|
|
392
423
|
|
|
393
424
|
return {};
|
|
394
|
-
|
|
425
|
+
}));
|
|
395
426
|
|
|
396
|
-
|
|
427
|
+
return promise;
|
|
397
428
|
});
|
|
398
429
|
|
|
399
|
-
auto
|
|
430
|
+
auto execute_with_host_objects = HOSTFN("executeWithHostObjects") {
|
|
400
431
|
const std::string query = args[0].asString(rt).utf8(rt);
|
|
401
432
|
std::vector<JSVariant> params;
|
|
402
433
|
|
|
@@ -406,7 +437,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
406
437
|
}
|
|
407
438
|
|
|
408
439
|
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
409
|
-
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor"
|
|
440
|
+
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
|
|
410
441
|
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
411
442
|
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
412
443
|
|
|
@@ -417,11 +448,11 @@ void DBHostObject::create_jsi_functions() {
|
|
|
417
448
|
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
418
449
|
std::make_shared<std::vector<SmartHostObject>>();
|
|
419
450
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
420
|
-
auto status =
|
|
421
|
-
|
|
451
|
+
auto status = opsqlite_libsql_execute_with_host_objects(
|
|
452
|
+
db_name, query, ¶ms, &results, metadata);
|
|
422
453
|
#else
|
|
423
|
-
auto status =
|
|
424
|
-
|
|
454
|
+
auto status = opsqlite_execute_host_objects(db_name, query, ¶ms,
|
|
455
|
+
&results, metadata);
|
|
425
456
|
#endif
|
|
426
457
|
|
|
427
458
|
// if (invalidated) {
|
|
@@ -464,36 +495,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
464
495
|
return promise;
|
|
465
496
|
});
|
|
466
497
|
|
|
467
|
-
auto execute_batch = HOSTFN("executeBatch"
|
|
468
|
-
if (sizeof(args) < 1) {
|
|
469
|
-
throw std::runtime_error(
|
|
470
|
-
"[op-sqlite][executeBatch] - Incorrect parameter count");
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const jsi::Value ¶ms = args[0];
|
|
474
|
-
if (params.isNull() || params.isUndefined()) {
|
|
475
|
-
throw std::runtime_error("[op-sqlite][executeBatch] - An array of SQL "
|
|
476
|
-
"commands or parameters is needed");
|
|
477
|
-
}
|
|
478
|
-
const jsi::Array &batchParams = params.asObject(rt).asArray(rt);
|
|
479
|
-
std::vector<BatchArguments> commands;
|
|
480
|
-
to_batch_arguments(rt, batchParams, &commands);
|
|
481
|
-
|
|
482
|
-
#ifdef OP_SQLITE_USE_LIBSQL
|
|
483
|
-
auto batchResult = opsqlite_libsql_execute_batch(db_name, &commands);
|
|
484
|
-
#else
|
|
485
|
-
auto batchResult = opsqlite_execute_batch(db_name, &commands);
|
|
486
|
-
#endif
|
|
487
|
-
if (batchResult.type == SQLiteOk) {
|
|
488
|
-
auto res = jsi::Object(rt);
|
|
489
|
-
res.setProperty(rt, "rowsAffected", jsi::Value(batchResult.affectedRows));
|
|
490
|
-
return std::move(res);
|
|
491
|
-
} else {
|
|
492
|
-
throw std::runtime_error(batchResult.message);
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
auto execute_batch_async = HOSTFN("executeBatchAsync", 1) {
|
|
498
|
+
auto execute_batch = HOSTFN("executeBatch") {
|
|
497
499
|
if (sizeof(args) < 1) {
|
|
498
500
|
throw std::runtime_error(
|
|
499
501
|
"[op-sqlite][executeAsyncBatch] Incorrect parameter count");
|
|
@@ -515,7 +517,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
515
517
|
to_batch_arguments(rt, batchParams, &commands);
|
|
516
518
|
|
|
517
519
|
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
518
|
-
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor"
|
|
520
|
+
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
|
|
519
521
|
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
520
522
|
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
521
523
|
|
|
@@ -558,17 +560,15 @@ void DBHostObject::create_jsi_functions() {
|
|
|
558
560
|
});
|
|
559
561
|
|
|
560
562
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
561
|
-
auto sync = HOSTFN("sync"
|
|
563
|
+
auto sync = HOSTFN("sync") {
|
|
562
564
|
BridgeResult result = opsqlite_libsql_sync(db_name);
|
|
563
565
|
if (result.type == SQLiteError) {
|
|
564
566
|
throw std::runtime_error(result.message);
|
|
565
567
|
}
|
|
566
568
|
return {};
|
|
567
569
|
});
|
|
568
|
-
#
|
|
569
|
-
|
|
570
|
-
#ifndef OP_SQLITE_USE_LIBSQL
|
|
571
|
-
auto load_file = HOSTFN("loadFile", 1) {
|
|
570
|
+
#else
|
|
571
|
+
auto load_file = HOSTFN("loadFile") {
|
|
572
572
|
if (sizeof(args) < 1) {
|
|
573
573
|
throw std::runtime_error(
|
|
574
574
|
"[op-sqlite][loadFile] Incorrect parameter count");
|
|
@@ -578,17 +578,17 @@ void DBHostObject::create_jsi_functions() {
|
|
|
578
578
|
const std::string sqlFileName = args[0].asString(rt).utf8(rt);
|
|
579
579
|
|
|
580
580
|
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
581
|
-
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor"
|
|
581
|
+
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor")
|
|
582
582
|
{
|
|
583
583
|
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
584
584
|
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
585
585
|
|
|
586
586
|
auto task = [&rt, this, sqlFileName, resolve, reject]() {
|
|
587
587
|
try {
|
|
588
|
-
const auto
|
|
588
|
+
const auto result = importSQLFile(db_name, sqlFileName);
|
|
589
589
|
|
|
590
|
-
jsCallInvoker->invokeAsync([&rt, result = std::move(
|
|
591
|
-
|
|
590
|
+
jsCallInvoker->invokeAsync([&rt, result = std::move(result), resolve,
|
|
591
|
+
reject] {
|
|
592
592
|
if (result.type == SQLiteOk) {
|
|
593
593
|
auto res = jsi::Object(rt);
|
|
594
594
|
res.setProperty(rt, "rowsAffected",
|
|
@@ -614,7 +614,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
614
614
|
return promise;
|
|
615
615
|
});
|
|
616
616
|
|
|
617
|
-
auto update_hook = HOSTFN("updateHook"
|
|
617
|
+
auto update_hook = HOSTFN("updateHook") {
|
|
618
618
|
auto callback = std::make_shared<jsi::Value>(rt, args[0]);
|
|
619
619
|
|
|
620
620
|
if (callback->isUndefined() || callback->isNull()) {
|
|
@@ -626,7 +626,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
626
626
|
return {};
|
|
627
627
|
});
|
|
628
628
|
|
|
629
|
-
auto commit_hook = HOSTFN("commitHook"
|
|
629
|
+
auto commit_hook = HOSTFN("commitHook") {
|
|
630
630
|
if (sizeof(args) < 1) {
|
|
631
631
|
throw std::runtime_error("[op-sqlite][commitHook] callback needed");
|
|
632
632
|
return {};
|
|
@@ -649,7 +649,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
649
649
|
return {};
|
|
650
650
|
});
|
|
651
651
|
|
|
652
|
-
auto rollback_hook = HOSTFN("rollbackHook"
|
|
652
|
+
auto rollback_hook = HOSTFN("rollbackHook") {
|
|
653
653
|
if (sizeof(args) < 1) {
|
|
654
654
|
throw std::runtime_error("[op-sqlite][rollbackHook] callback needed");
|
|
655
655
|
return {};
|
|
@@ -672,7 +672,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
672
672
|
return {};
|
|
673
673
|
});
|
|
674
674
|
|
|
675
|
-
auto load_extension = HOSTFN("loadExtension"
|
|
675
|
+
auto load_extension = HOSTFN("loadExtension") {
|
|
676
676
|
auto path = args[0].asString(rt).utf8(rt);
|
|
677
677
|
std::string entry_point = "";
|
|
678
678
|
if (count > 1 && args[1].isString()) {
|
|
@@ -686,7 +686,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
686
686
|
return {};
|
|
687
687
|
});
|
|
688
688
|
|
|
689
|
-
auto reactive_execute = HOSTFN("reactiveExecute"
|
|
689
|
+
auto reactive_execute = HOSTFN("reactiveExecute") {
|
|
690
690
|
auto query = args[0].asObject(rt);
|
|
691
691
|
// if (!query.hasProperty(rt, "query") || !query.hasProperty(rt, "args")
|
|
692
692
|
// ||
|
|
@@ -746,7 +746,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
746
746
|
|
|
747
747
|
auto_register_update_hook();
|
|
748
748
|
|
|
749
|
-
auto unsubscribe = HOSTFN("unsubscribe"
|
|
749
|
+
auto unsubscribe = HOSTFN("unsubscribe") {
|
|
750
750
|
auto it = std::find(reactive_queries.begin(), reactive_queries.end(),
|
|
751
751
|
reactiveQuery);
|
|
752
752
|
if (it != reactive_queries.end()) {
|
|
@@ -761,7 +761,7 @@ void DBHostObject::create_jsi_functions() {
|
|
|
761
761
|
|
|
762
762
|
#endif
|
|
763
763
|
|
|
764
|
-
auto prepare_statement = HOSTFN("prepareStatement"
|
|
764
|
+
auto prepare_statement = HOSTFN("prepareStatement") {
|
|
765
765
|
auto query = args[0].asString(rt).utf8(rt);
|
|
766
766
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
767
767
|
libsql_stmt_t statement = opsqlite_libsql_prepare_statement(db_name, query);
|
|
@@ -769,12 +769,13 @@ void DBHostObject::create_jsi_functions() {
|
|
|
769
769
|
sqlite3_stmt *statement = opsqlite_prepare_statement(db_name, query);
|
|
770
770
|
#endif
|
|
771
771
|
auto preparedStatementHostObject =
|
|
772
|
-
std::make_shared<PreparedStatementHostObject>(
|
|
772
|
+
std::make_shared<PreparedStatementHostObject>(
|
|
773
|
+
db_name, statement, jsCallInvoker, thread_pool);
|
|
773
774
|
|
|
774
775
|
return jsi::Object::createFromHostObject(rt, preparedStatementHostObject);
|
|
775
776
|
});
|
|
776
777
|
|
|
777
|
-
auto get_db_path = HOSTFN("getDbPath"
|
|
778
|
+
auto get_db_path = HOSTFN("getDbPath") {
|
|
778
779
|
std::string path = std::string(base_path);
|
|
779
780
|
if (count == 1 && !args[0].isUndefined() && !args[0].isNull()) {
|
|
780
781
|
if (!args[0].isString()) {
|
|
@@ -800,12 +801,11 @@ void DBHostObject::create_jsi_functions() {
|
|
|
800
801
|
function_map["attach"] = std::move(attach);
|
|
801
802
|
function_map["detach"] = std::move(detach);
|
|
802
803
|
function_map["close"] = std::move(close);
|
|
803
|
-
function_map["executeRawAsync"] = std::move(execute_raw_async);
|
|
804
804
|
function_map["execute"] = std::move(execute);
|
|
805
|
-
function_map["
|
|
805
|
+
function_map["executeRaw"] = std::move(execute_raw);
|
|
806
|
+
function_map["executeWithHostObjects"] = std::move(execute_with_host_objects);
|
|
806
807
|
function_map["delete"] = std::move(remove);
|
|
807
808
|
function_map["executeBatch"] = std::move(execute_batch);
|
|
808
|
-
function_map["executeBatchAsync"] = std::move(execute_batch_async);
|
|
809
809
|
function_map["prepareStatement"] = std::move(prepare_statement);
|
|
810
810
|
function_map["getDbPath"] = std::move(get_db_path);
|
|
811
811
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
@@ -839,14 +839,14 @@ jsi::Value DBHostObject::get(jsi::Runtime &rt,
|
|
|
839
839
|
if (name == "close") {
|
|
840
840
|
return jsi::Value(rt, function_map["close"]);
|
|
841
841
|
}
|
|
842
|
-
if (name == "
|
|
843
|
-
return jsi::Value(rt, function_map["
|
|
842
|
+
if (name == "executeRaw") {
|
|
843
|
+
return jsi::Value(rt, function_map["executeRaw"]);
|
|
844
844
|
}
|
|
845
845
|
if (name == "execute") {
|
|
846
846
|
return jsi::Value(rt, function_map["execute"]);
|
|
847
847
|
}
|
|
848
|
-
if (name == "
|
|
849
|
-
return jsi::Value(rt, function_map["
|
|
848
|
+
if (name == "executeWithHostObjects") {
|
|
849
|
+
return jsi::Value(rt, function_map["executeWithHostObjects"]);
|
|
850
850
|
}
|
|
851
851
|
if (name == "delete") {
|
|
852
852
|
return jsi::Value(rt, function_map["delete"]);
|
|
@@ -854,9 +854,6 @@ jsi::Value DBHostObject::get(jsi::Runtime &rt,
|
|
|
854
854
|
if (name == "executeBatch") {
|
|
855
855
|
return jsi::Value(rt, function_map["executeBatch"]);
|
|
856
856
|
}
|
|
857
|
-
if (name == "executeBatchAsync") {
|
|
858
|
-
return jsi::Value(rt, function_map["executeBatchAsync"]);
|
|
859
|
-
}
|
|
860
857
|
if (name == "prepareStatement") {
|
|
861
858
|
return jsi::Value(rt, function_map["prepareStatement"]);
|
|
862
859
|
}
|
|
@@ -868,32 +865,32 @@ jsi::Value DBHostObject::get(jsi::Runtime &rt,
|
|
|
868
865
|
}
|
|
869
866
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
870
867
|
if (name == "loadFile") {
|
|
871
|
-
return HOSTFN("loadFile"
|
|
868
|
+
return HOSTFN("loadFile") {
|
|
872
869
|
throw std::runtime_error("[op-sqlite] Load file not implemented");
|
|
873
870
|
});
|
|
874
871
|
}
|
|
875
872
|
if (name == "updateHook") {
|
|
876
|
-
return HOSTFN("updateHook"
|
|
873
|
+
return HOSTFN("updateHook") {
|
|
877
874
|
throw std::runtime_error("[op-sqlite] Hooks not supported in libsql");
|
|
878
875
|
});
|
|
879
876
|
}
|
|
880
877
|
if (name == "commitHook") {
|
|
881
|
-
return HOSTFN("commitHook"
|
|
878
|
+
return HOSTFN("commitHook") {
|
|
882
879
|
throw std::runtime_error("[op-sqlite] Hooks not supported in libsql");
|
|
883
880
|
});
|
|
884
881
|
}
|
|
885
882
|
if (name == "rollbackHook") {
|
|
886
|
-
return HOSTFN("rollbackHook"
|
|
883
|
+
return HOSTFN("rollbackHook") {
|
|
887
884
|
throw std::runtime_error("[op-sqlite] Hooks not supported in libsql");
|
|
888
885
|
});
|
|
889
886
|
}
|
|
890
887
|
if (name == "loadExtension") {
|
|
891
|
-
return HOSTFN("loadExtension"
|
|
888
|
+
return HOSTFN("loadExtension") {
|
|
892
889
|
throw std::runtime_error("[op-sqlite] Hooks not supported in libsql");
|
|
893
890
|
});
|
|
894
891
|
}
|
|
895
892
|
if (name == "reactiveExecute") {
|
|
896
|
-
return HOSTFN("reactiveExecute"
|
|
893
|
+
return HOSTFN("reactiveExecute") {
|
|
897
894
|
throw std::runtime_error("[op-sqlite] Hooks not supported in libsql");
|
|
898
895
|
});
|
|
899
896
|
}
|
package/cpp/DBHostObject.h
CHANGED
|
@@ -32,7 +32,7 @@ public:
|
|
|
32
32
|
std::shared_ptr<react::CallInvoker> js_call_invoker,
|
|
33
33
|
std::shared_ptr<ThreadPool> thread_pool, std::string &db_name,
|
|
34
34
|
std::string &path, std::string &crsqlite_path,
|
|
35
|
-
std::string &encryption_key);
|
|
35
|
+
std::string &sqlite_vec_path, std::string &encryption_key);
|
|
36
36
|
|
|
37
37
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
38
38
|
// Constructor for remoteOpen, purely for remote databases
|