@op-engineering/op-sqlite 2.0.15 → 2.0.17
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 +20 -2
- package/cpp/PreparedStatementHostObject.cpp +3 -3
- package/cpp/bindings.cpp +34 -37
- package/cpp/bridge.cpp +98 -126
- package/cpp/bridge.h +53 -49
- package/cpp/sqlbatchexecutor.cpp +6 -6
- package/cpp/sqlite3.c +5642 -2573
- package/cpp/sqlite3.h +127 -31
- package/cpp/utils.cpp +5 -5
- package/op-sqlite.podspec +10 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ yarn add @op-engineering/op-sqlite && npx pod-install
|
|
|
6
6
|
|
|
7
7
|
OP-SQLite embeds the latest version of SQLite and provides a low-level API to execute SQL queries.
|
|
8
8
|
|
|
9
|
-
**Current SQLite version: 3.
|
|
9
|
+
**Current SQLite version: 3.45.1**
|
|
10
10
|
|
|
11
11
|
Created by [@ospfranco](https://twitter.com/ospfranco). **Please consider sponsoring!**.
|
|
12
12
|
|
|
@@ -502,7 +502,7 @@ On iOS you can use the embedded SQLite, when running `pod-install` add an enviro
|
|
|
502
502
|
OP_SQLITE_USE_PHONE_VERSION=1 npx pod-install
|
|
503
503
|
```
|
|
504
504
|
|
|
505
|
-
On Android, it is not possible to link the OS SQLite. It is also a bad idea due to vendor changes, old android bugs, etc. Unfortunately, this means this library will add some megabytes to your app size.
|
|
505
|
+
On Android, it is not possible to link the OS SQLite. It is also a bad idea due to vendor changes, old android bugs, etc. Unfortunately, this means this library will add some megabytes to your app size. Take note that the embedded version of SQLite does not support loading runtime extensions due to security concerns from apple.
|
|
506
506
|
|
|
507
507
|
# Enable compile-time options
|
|
508
508
|
|
|
@@ -553,6 +553,24 @@ On iOS, the SQLite database can be placed in an app group, in order to make it a
|
|
|
553
553
|
|
|
554
554
|
To use an app group, add the app group ID as the value for the `OPSQLite_AppGroup` key in your project's `Info.plist` file. You'll also need to configure the app group in your project settings. (Xcode -> Project Settings -> Signing & Capabilities -> Add Capability -> App Groups)
|
|
555
555
|
|
|
556
|
+
## use_frameworks
|
|
557
|
+
|
|
558
|
+
If you are using `use_frameworks` (because one of your dependencies requires e.g. firebase), you might get a linking error since the OS version will try to be linked instead of the version compiled directly from sources. In order to get around this you can add the following into your Podfile:
|
|
559
|
+
|
|
560
|
+
```ruby
|
|
561
|
+
pre_install do |installer|
|
|
562
|
+
installer.pod_targets.each do |pod|
|
|
563
|
+
if pod.name.eql?('op-sqlite')
|
|
564
|
+
def pod.build_type
|
|
565
|
+
Pod::BuildType.static_library
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
end
|
|
569
|
+
end
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
It will change the type of library only for op-sqlite only to static. This should be fine as SQLite is compiled from sources, so no missing symbols should be there.
|
|
573
|
+
|
|
556
574
|
# Contribute
|
|
557
575
|
|
|
558
576
|
You need to have clang-format installed (`brew install clang-format`)
|
|
@@ -38,7 +38,7 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
|
38
38
|
const jsi::Value &js_params = args[0];
|
|
39
39
|
std::vector<JSVariant> params = toVariantVec(rt, js_params);
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
opsqlite_bind_statement(_statement, ¶ms);
|
|
42
42
|
|
|
43
43
|
return {};
|
|
44
44
|
});
|
|
@@ -53,8 +53,8 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
|
53
53
|
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
54
54
|
std::make_shared<std::vector<SmartHostObject>>();
|
|
55
55
|
|
|
56
|
-
auto status =
|
|
57
|
-
|
|
56
|
+
auto status = opsqlite_execute_prepared_statement(_dbName, _statement,
|
|
57
|
+
&results, metadata);
|
|
58
58
|
|
|
59
59
|
if (status.type == SQLiteError) {
|
|
60
60
|
throw std::runtime_error(status.message);
|
package/cpp/bindings.cpp
CHANGED
|
@@ -35,7 +35,7 @@ bool invalidated = false;
|
|
|
35
35
|
void clearState() {
|
|
36
36
|
invalidated = true;
|
|
37
37
|
// Will terminate all operations and database connections
|
|
38
|
-
|
|
38
|
+
opsqlite_close_all();
|
|
39
39
|
// We then join all the threads before the context gets invalidated
|
|
40
40
|
pool.restartPool();
|
|
41
41
|
updateHooks.clear();
|
|
@@ -80,7 +80,7 @@ void install(jsi::Runtime &rt,
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
BridgeResult result =
|
|
83
|
+
BridgeResult result = opsqlite_open(dbName, path);
|
|
84
84
|
|
|
85
85
|
if (result.type == SQLiteError) {
|
|
86
86
|
throw std::runtime_error(result.message);
|
|
@@ -114,7 +114,7 @@ void install(jsi::Runtime &rt,
|
|
|
114
114
|
std::string databaseToAttach = args[1].asString(rt).utf8(rt);
|
|
115
115
|
std::string alias = args[2].asString(rt).utf8(rt);
|
|
116
116
|
BridgeResult result =
|
|
117
|
-
|
|
117
|
+
opsqlite_attach(dbName, tempDocPath, databaseToAttach, alias);
|
|
118
118
|
|
|
119
119
|
if (result.type == SQLiteError) {
|
|
120
120
|
throw std::runtime_error(result.message);
|
|
@@ -136,7 +136,7 @@ void install(jsi::Runtime &rt,
|
|
|
136
136
|
|
|
137
137
|
std::string dbName = args[0].asString(rt).utf8(rt);
|
|
138
138
|
std::string alias = args[1].asString(rt).utf8(rt);
|
|
139
|
-
BridgeResult result =
|
|
139
|
+
BridgeResult result = opsqlite_detach(dbName, alias);
|
|
140
140
|
|
|
141
141
|
if (result.type == SQLiteError) {
|
|
142
142
|
throw jsi::JSError(rt, result.message.c_str());
|
|
@@ -157,7 +157,7 @@ void install(jsi::Runtime &rt,
|
|
|
157
157
|
|
|
158
158
|
std::string dbName = args[0].asString(rt).utf8(rt);
|
|
159
159
|
|
|
160
|
-
BridgeResult result =
|
|
160
|
+
BridgeResult result = opsqlite_close(dbName);
|
|
161
161
|
|
|
162
162
|
if (result.type == SQLiteError) {
|
|
163
163
|
throw jsi::JSError(rt, result.message.c_str());
|
|
@@ -189,7 +189,7 @@ void install(jsi::Runtime &rt,
|
|
|
189
189
|
tempDocPath = tempDocPath + "/" + args[1].asString(rt).utf8(rt);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
BridgeResult result =
|
|
192
|
+
BridgeResult result = opsqlite_remove(dbName, tempDocPath);
|
|
193
193
|
|
|
194
194
|
if (result.type == SQLiteError) {
|
|
195
195
|
throw std::runtime_error(result.message);
|
|
@@ -212,7 +212,7 @@ void install(jsi::Runtime &rt,
|
|
|
212
212
|
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
213
213
|
std::make_shared<std::vector<SmartHostObject>>();
|
|
214
214
|
|
|
215
|
-
auto status =
|
|
215
|
+
auto status = opsqlite_execute(dbName, query, ¶ms, &results, metadata);
|
|
216
216
|
|
|
217
217
|
if (status.type == SQLiteError) {
|
|
218
218
|
throw std::runtime_error(status.message);
|
|
@@ -245,7 +245,7 @@ void install(jsi::Runtime &rt,
|
|
|
245
245
|
try {
|
|
246
246
|
std::vector<std::vector<JSVariant>> results;
|
|
247
247
|
|
|
248
|
-
auto status =
|
|
248
|
+
auto status = opsqlite_execute_raw(dbName, query, ¶ms, &results);
|
|
249
249
|
|
|
250
250
|
if (invalidated) {
|
|
251
251
|
return;
|
|
@@ -283,7 +283,7 @@ void install(jsi::Runtime &rt,
|
|
|
283
283
|
return promise;
|
|
284
284
|
});
|
|
285
285
|
|
|
286
|
-
auto
|
|
286
|
+
auto execute_async = HOSTFN("executeAsync", 3) {
|
|
287
287
|
if (count < 3) {
|
|
288
288
|
throw std::runtime_error(
|
|
289
289
|
"[op-sqlite][executeAsync] Incorrect arguments for executeAsync");
|
|
@@ -309,7 +309,7 @@ void install(jsi::Runtime &rt,
|
|
|
309
309
|
std::make_shared<std::vector<SmartHostObject>>();
|
|
310
310
|
|
|
311
311
|
auto status =
|
|
312
|
-
|
|
312
|
+
opsqlite_execute(dbName, query, ¶ms, &results, metadata);
|
|
313
313
|
|
|
314
314
|
if (invalidated) {
|
|
315
315
|
return;
|
|
@@ -351,9 +351,7 @@ void install(jsi::Runtime &rt,
|
|
|
351
351
|
return promise;
|
|
352
352
|
});
|
|
353
353
|
|
|
354
|
-
|
|
355
|
-
// Parameters can be: [[sql: string, arguments: any[] | arguments: any[][] ]]
|
|
356
|
-
auto executeBatch = HOSTFN("executeBatch", 2) {
|
|
354
|
+
auto execute_batch = HOSTFN("executeBatch", 2) {
|
|
357
355
|
if (sizeof(args) < 2) {
|
|
358
356
|
throw std::runtime_error(
|
|
359
357
|
"[op-sqlite][executeBatch] - Incorrect parameter count");
|
|
@@ -379,7 +377,7 @@ void install(jsi::Runtime &rt,
|
|
|
379
377
|
}
|
|
380
378
|
});
|
|
381
379
|
|
|
382
|
-
auto
|
|
380
|
+
auto execute_batch_async = HOSTFN("executeBatchAsync", 2) {
|
|
383
381
|
if (sizeof(args) < 2) {
|
|
384
382
|
throw std::runtime_error(
|
|
385
383
|
"[op-sqlite][executeAsyncBatch] Incorrect parameter count");
|
|
@@ -437,7 +435,7 @@ void install(jsi::Runtime &rt,
|
|
|
437
435
|
return promise;
|
|
438
436
|
});
|
|
439
437
|
|
|
440
|
-
auto
|
|
438
|
+
auto load_file = HOSTFN("loadFile", 2) {
|
|
441
439
|
if (sizeof(args) < 2) {
|
|
442
440
|
throw std::runtime_error(
|
|
443
441
|
"[op-sqlite][loadFileAsync] Incorrect parameter count");
|
|
@@ -480,7 +478,7 @@ void install(jsi::Runtime &rt,
|
|
|
480
478
|
return promise;
|
|
481
479
|
});
|
|
482
480
|
|
|
483
|
-
auto
|
|
481
|
+
auto update_hook = HOSTFN("updateHook", 2) {
|
|
484
482
|
if (sizeof(args) < 2) {
|
|
485
483
|
throw std::runtime_error("[op-sqlite][updateHook] Incorrect parameters: "
|
|
486
484
|
"dbName and callback needed");
|
|
@@ -491,7 +489,7 @@ void install(jsi::Runtime &rt,
|
|
|
491
489
|
auto callback = std::make_shared<jsi::Value>(rt, args[1]);
|
|
492
490
|
|
|
493
491
|
if (callback->isUndefined() || callback->isNull()) {
|
|
494
|
-
|
|
492
|
+
opsqlite_deregister_update_hook(dbName);
|
|
495
493
|
return {};
|
|
496
494
|
}
|
|
497
495
|
|
|
@@ -503,12 +501,11 @@ void install(jsi::Runtime &rt,
|
|
|
503
501
|
std::vector<DumbHostObject> results;
|
|
504
502
|
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
505
503
|
std::make_shared<std::vector<SmartHostObject>>();
|
|
506
|
-
;
|
|
507
504
|
|
|
508
505
|
if (operation != "DELETE") {
|
|
509
506
|
std::string query = "SELECT * FROM " + tableName +
|
|
510
507
|
" where rowid = " + std::to_string(rowId) + ";";
|
|
511
|
-
|
|
508
|
+
opsqlite_execute(dbName, query, ¶ms, &results, metadata);
|
|
512
509
|
}
|
|
513
510
|
|
|
514
511
|
invoker->invokeAsync(
|
|
@@ -533,12 +530,12 @@ void install(jsi::Runtime &rt,
|
|
|
533
530
|
});
|
|
534
531
|
};
|
|
535
532
|
|
|
536
|
-
|
|
533
|
+
opsqlite_register_update_hook(dbName, std::move(hook));
|
|
537
534
|
|
|
538
535
|
return {};
|
|
539
536
|
});
|
|
540
537
|
|
|
541
|
-
auto
|
|
538
|
+
auto commit_hook = HOSTFN("commitHook", 2) {
|
|
542
539
|
if (sizeof(args) < 2) {
|
|
543
540
|
throw std::runtime_error("[op-sqlite][commitHook] Incorrect parameters: "
|
|
544
541
|
"dbName and callback needed");
|
|
@@ -548,7 +545,7 @@ void install(jsi::Runtime &rt,
|
|
|
548
545
|
auto dbName = args[0].asString(rt).utf8(rt);
|
|
549
546
|
auto callback = std::make_shared<jsi::Value>(rt, args[1]);
|
|
550
547
|
if (callback->isUndefined() || callback->isNull()) {
|
|
551
|
-
|
|
548
|
+
opsqlite_deregister_commit_hook(dbName);
|
|
552
549
|
return {};
|
|
553
550
|
}
|
|
554
551
|
commitHooks[dbName] = callback;
|
|
@@ -558,12 +555,12 @@ void install(jsi::Runtime &rt,
|
|
|
558
555
|
[&rt, callback] { callback->asObject(rt).asFunction(rt).call(rt); });
|
|
559
556
|
};
|
|
560
557
|
|
|
561
|
-
|
|
558
|
+
opsqlite_register_commit_hook(dbName, std::move(hook));
|
|
562
559
|
|
|
563
560
|
return {};
|
|
564
561
|
});
|
|
565
562
|
|
|
566
|
-
auto
|
|
563
|
+
auto rollback_hook = HOSTFN("rollbackHook", 2) {
|
|
567
564
|
if (sizeof(args) < 2) {
|
|
568
565
|
throw std::runtime_error(
|
|
569
566
|
"[op-sqlite][rollbackHook] Incorrect parameters: "
|
|
@@ -575,7 +572,7 @@ void install(jsi::Runtime &rt,
|
|
|
575
572
|
auto callback = std::make_shared<jsi::Value>(rt, args[1]);
|
|
576
573
|
|
|
577
574
|
if (callback->isUndefined() || callback->isNull()) {
|
|
578
|
-
|
|
575
|
+
opsqlite_deregister_rollback_hook(dbName);
|
|
579
576
|
return {};
|
|
580
577
|
}
|
|
581
578
|
rollbackHooks[dbName] = callback;
|
|
@@ -585,15 +582,15 @@ void install(jsi::Runtime &rt,
|
|
|
585
582
|
[&rt, callback] { callback->asObject(rt).asFunction(rt).call(rt); });
|
|
586
583
|
};
|
|
587
584
|
|
|
588
|
-
|
|
585
|
+
opsqlite_register_rollback_hook(dbName, std::move(hook));
|
|
589
586
|
return {};
|
|
590
587
|
});
|
|
591
588
|
|
|
592
|
-
auto
|
|
589
|
+
auto prepare_statement = HOSTFN("prepareStatement", 1) {
|
|
593
590
|
auto dbName = args[0].asString(rt).utf8(rt);
|
|
594
591
|
auto query = args[1].asString(rt).utf8(rt);
|
|
595
592
|
|
|
596
|
-
sqlite3_stmt *statement =
|
|
593
|
+
sqlite3_stmt *statement = opsqlite_prepare_statement(dbName, query);
|
|
597
594
|
|
|
598
595
|
auto preparedStatementHostObject =
|
|
599
596
|
std::make_shared<PreparedStatementHostObject>(dbName, statement);
|
|
@@ -609,7 +606,7 @@ void install(jsi::Runtime &rt,
|
|
|
609
606
|
entryPoint = args[2].asString(rt).utf8(rt);
|
|
610
607
|
}
|
|
611
608
|
|
|
612
|
-
auto result =
|
|
609
|
+
auto result = opsqlite_load_extension(db_name, path, entryPoint);
|
|
613
610
|
if (result.type == SQLiteError) {
|
|
614
611
|
throw std::runtime_error(result.message);
|
|
615
612
|
}
|
|
@@ -624,14 +621,14 @@ void install(jsi::Runtime &rt,
|
|
|
624
621
|
module.setProperty(rt, "detach", std::move(detach));
|
|
625
622
|
module.setProperty(rt, "delete", std::move(remove));
|
|
626
623
|
module.setProperty(rt, "execute", std::move(execute));
|
|
627
|
-
module.setProperty(rt, "executeAsync", std::move(
|
|
628
|
-
module.setProperty(rt, "executeBatch", std::move(
|
|
629
|
-
module.setProperty(rt, "executeBatchAsync", std::move(
|
|
630
|
-
module.setProperty(rt, "loadFile", std::move(
|
|
631
|
-
module.setProperty(rt, "updateHook", std::move(
|
|
632
|
-
module.setProperty(rt, "commitHook", std::move(
|
|
633
|
-
module.setProperty(rt, "rollbackHook", std::move(
|
|
634
|
-
module.setProperty(rt, "prepareStatement", std::move(
|
|
624
|
+
module.setProperty(rt, "executeAsync", std::move(execute_async));
|
|
625
|
+
module.setProperty(rt, "executeBatch", std::move(execute_batch));
|
|
626
|
+
module.setProperty(rt, "executeBatchAsync", std::move(execute_batch_async));
|
|
627
|
+
module.setProperty(rt, "loadFile", std::move(load_file));
|
|
628
|
+
module.setProperty(rt, "updateHook", std::move(update_hook));
|
|
629
|
+
module.setProperty(rt, "commitHook", std::move(commit_hook));
|
|
630
|
+
module.setProperty(rt, "rollbackHook", std::move(rollback_hook));
|
|
631
|
+
module.setProperty(rt, "prepareStatement", std::move(prepare_statement));
|
|
635
632
|
module.setProperty(rt, "loadExtension", std::move(load_extension));
|
|
636
633
|
module.setProperty(rt, "executeRawAsync", std::move(execute_raw_async));
|
|
637
634
|
|