@op-engineering/op-sqlite 6.0.1 → 6.0.2-beta3
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/android/CMakeLists.txt +26 -15
- package/android/build.gradle +10 -1
- package/android/cpp-adapter.cpp +4 -0
- package/android/jniLibs/arm64-v8a/libsql_experimental.a +0 -0
- package/android/jniLibs/armeabi-v7a/libsql_experimental.a +0 -0
- package/android/jniLibs/x86/libsql_experimental.a +0 -0
- package/android/jniLibs/x86_64/libsql_experimental.a +0 -0
- package/cpp/DBHostObject.cpp +882 -0
- package/cpp/DBHostObject.h +61 -0
- package/cpp/PreparedStatementHostObject.cpp +29 -15
- package/cpp/PreparedStatementHostObject.h +18 -14
- package/cpp/bindings.cpp +24 -616
- package/cpp/bindings.h +5 -2
- package/cpp/bridge.cpp +55 -16
- package/cpp/bridge.h +5 -1
- package/cpp/libsql/bridge.cpp +629 -0
- package/cpp/libsql/bridge.h +88 -0
- package/cpp/libsql/libsql.h +133 -0
- package/cpp/sqlite3.h +0 -1
- package/cpp/types.h +5 -0
- package/cpp/utils.cpp +68 -6
- package/cpp/utils.h +5 -5
- package/ios/libsql.xcframework/Info.plist +48 -0
- package/ios/libsql.xcframework/ios-arm64/Headers/libsql.h +133 -0
- package/ios/libsql.xcframework/ios-arm64/libsql_experimental.a +0 -0
- package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h +133 -0
- package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a +0 -0
- package/lib/commonjs/index.js +143 -153
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +141 -152
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +28 -39
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/op-sqlite.podspec +20 -3
- package/package.json +1 -1
- package/src/index.ts +203 -272
- package/cpp/sqlbatchexecutor.cpp +0 -93
- package/cpp/sqlbatchexecutor.h +0 -30
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#ifndef DBHostObject_h
|
|
2
|
+
#define DBHostObject_h
|
|
3
|
+
|
|
4
|
+
#include "ThreadPool.h"
|
|
5
|
+
#include "sqlite3.h"
|
|
6
|
+
#include "types.h"
|
|
7
|
+
#include <ReactCommon/CallInvoker.h>
|
|
8
|
+
#include <any>
|
|
9
|
+
#include <jsi/jsi.h>
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
namespace opsqlite {
|
|
14
|
+
|
|
15
|
+
namespace jsi = facebook::jsi;
|
|
16
|
+
namespace react = facebook::react;
|
|
17
|
+
|
|
18
|
+
struct TableRowDiscriminator {
|
|
19
|
+
std::string table;
|
|
20
|
+
std::vector<int> ids;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
struct ReactiveQuery {
|
|
24
|
+
sqlite3_stmt *stmt;
|
|
25
|
+
std::vector<TableRowDiscriminator> discriminators;
|
|
26
|
+
std::shared_ptr<jsi::Value> callback;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
class JSI_EXPORT DBHostObject : public jsi::HostObject {
|
|
30
|
+
public:
|
|
31
|
+
DBHostObject(jsi::Runtime &rt, std::string &base_path,
|
|
32
|
+
std::shared_ptr<react::CallInvoker> js_call_invoker,
|
|
33
|
+
std::shared_ptr<ThreadPool> thread_pool, std::string &db_name,
|
|
34
|
+
std::string &path, std::string &crsqlite_path,
|
|
35
|
+
std::string &encryption_key);
|
|
36
|
+
|
|
37
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
|
|
38
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
|
|
39
|
+
void set(jsi::Runtime &rt, const jsi::PropNameID &name,
|
|
40
|
+
const jsi::Value &value);
|
|
41
|
+
|
|
42
|
+
void auto_register_update_hook();
|
|
43
|
+
|
|
44
|
+
std::unordered_map<std::string, jsi::Value> function_map;
|
|
45
|
+
std::string base_path;
|
|
46
|
+
|
|
47
|
+
std::shared_ptr<jsi::Value> update_hook;
|
|
48
|
+
std::shared_ptr<react::CallInvoker> jsCallInvoker;
|
|
49
|
+
std::shared_ptr<ThreadPool> thread_pool;
|
|
50
|
+
std::string db_name;
|
|
51
|
+
std::shared_ptr<jsi::Value> update_hook_callback;
|
|
52
|
+
std::shared_ptr<jsi::Value> commit_hook_callback;
|
|
53
|
+
std::shared_ptr<jsi::Value> rollback_hook_callback;
|
|
54
|
+
jsi::Runtime &rt;
|
|
55
|
+
std::vector<std::shared_ptr<ReactiveQuery>> reactive_queries;
|
|
56
|
+
bool has_update_hook_registered = false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace opsqlite
|
|
60
|
+
|
|
61
|
+
#endif /* DBHostObject_h */
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#include "PreparedStatementHostObject.h"
|
|
2
|
+
#if OP_SQLITE_USE_LIBSQL
|
|
3
|
+
#include "libsql/bridge.h"
|
|
4
|
+
#else
|
|
2
5
|
#include "bridge.h"
|
|
6
|
+
#endif
|
|
3
7
|
#include "macros.h"
|
|
4
8
|
#include "utils.h"
|
|
5
9
|
|
|
@@ -7,10 +11,6 @@ namespace opsqlite {
|
|
|
7
11
|
|
|
8
12
|
namespace jsi = facebook::jsi;
|
|
9
13
|
|
|
10
|
-
PreparedStatementHostObject::PreparedStatementHostObject(
|
|
11
|
-
std::string dbName, sqlite3_stmt *statementPtr)
|
|
12
|
-
: _dbName(dbName), _statement(statementPtr) {}
|
|
13
|
-
|
|
14
14
|
std::vector<jsi::PropNameID>
|
|
15
15
|
PreparedStatementHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
16
16
|
std::vector<jsi::PropNameID> keys;
|
|
@@ -24,14 +24,17 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
|
24
24
|
|
|
25
25
|
if (name == "bind") {
|
|
26
26
|
return HOSTFN("bind", 1) {
|
|
27
|
-
if (
|
|
27
|
+
if (_stmt == nullptr) {
|
|
28
28
|
throw std::runtime_error("statement has been freed");
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const jsi::Value &js_params = args[0];
|
|
32
|
-
std::vector<JSVariant> params =
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
std::vector<JSVariant> params = to_variant_vec(rt, js_params);
|
|
33
|
+
#ifdef OP_SQLITE_USE_LIBSQL
|
|
34
|
+
opsqlite_libsql_bind_statement(_stmt, ¶ms);
|
|
35
|
+
#else
|
|
36
|
+
opsqlite_bind_statement(_stmt, ¶ms);
|
|
37
|
+
#endif
|
|
35
38
|
|
|
36
39
|
return {};
|
|
37
40
|
});
|
|
@@ -39,16 +42,20 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
|
39
42
|
|
|
40
43
|
if (name == "execute") {
|
|
41
44
|
return HOSTFN("execute", 1) {
|
|
42
|
-
if (
|
|
45
|
+
if (_stmt == nullptr) {
|
|
43
46
|
throw std::runtime_error("statement has been freed");
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
std::vector<DumbHostObject> results;
|
|
47
50
|
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
48
51
|
std::make_shared<std::vector<SmartHostObject>>();
|
|
49
|
-
|
|
50
|
-
auto status =
|
|
51
|
-
|
|
52
|
+
#ifdef OP_SQLITE_USE_LIBSQL
|
|
53
|
+
auto status = opsqlite_libsql_execute_prepared_statement(
|
|
54
|
+
_name, _stmt, &results, metadata);
|
|
55
|
+
#else
|
|
56
|
+
auto status =
|
|
57
|
+
opsqlite_execute_prepared_statement(_name, _stmt, &results, metadata);
|
|
58
|
+
#endif
|
|
52
59
|
|
|
53
60
|
if (status.type == SQLiteError) {
|
|
54
61
|
throw std::runtime_error(status.message);
|
|
@@ -63,10 +70,17 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
PreparedStatementHostObject::~PreparedStatementHostObject() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
#ifdef OP_SQLITE_USE_LIBSQL
|
|
74
|
+
if (_stmt != nullptr) {
|
|
75
|
+
libsql_free_stmt(_stmt);
|
|
76
|
+
_stmt = nullptr;
|
|
77
|
+
}
|
|
78
|
+
#else
|
|
79
|
+
if (_stmt != nullptr) {
|
|
80
|
+
sqlite3_finalize(_stmt);
|
|
81
|
+
_stmt = nullptr;
|
|
69
82
|
}
|
|
83
|
+
#endif
|
|
70
84
|
}
|
|
71
85
|
|
|
72
86
|
} // namespace opsqlite
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
// PreparedStatementHostObject.hpp
|
|
3
|
-
// op-sqlite
|
|
4
|
-
//
|
|
5
|
-
// Created by Oscar Franco on 5/12/23.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#ifndef PreparedStatementHostObject_h
|
|
9
|
-
#define PreparedStatementHostObject_h
|
|
1
|
+
#pragma once
|
|
10
2
|
|
|
11
3
|
#include <jsi/jsi.h>
|
|
12
4
|
#include <memory>
|
|
5
|
+
#ifdef OP_SQLITE_USE_LIBSQL
|
|
6
|
+
#include "libsql.h"
|
|
7
|
+
#else
|
|
13
8
|
#include <sqlite3.h>
|
|
9
|
+
#endif
|
|
14
10
|
#include <string>
|
|
15
11
|
|
|
16
12
|
namespace opsqlite {
|
|
@@ -18,7 +14,13 @@ namespace jsi = facebook::jsi;
|
|
|
18
14
|
|
|
19
15
|
class PreparedStatementHostObject : public jsi::HostObject {
|
|
20
16
|
public:
|
|
21
|
-
|
|
17
|
+
#ifdef OP_SQLITE_USE_LIBSQL
|
|
18
|
+
PreparedStatementHostObject(std::string name, libsql_stmt_t stmt)
|
|
19
|
+
: _name(name), _stmt(stmt){};
|
|
20
|
+
#else
|
|
21
|
+
PreparedStatementHostObject(std::string name, sqlite3_stmt *stmt)
|
|
22
|
+
: _name(name), _stmt(stmt){};
|
|
23
|
+
#endif
|
|
22
24
|
virtual ~PreparedStatementHostObject();
|
|
23
25
|
|
|
24
26
|
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
|
|
@@ -26,11 +28,13 @@ public:
|
|
|
26
28
|
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
|
|
27
29
|
|
|
28
30
|
private:
|
|
29
|
-
std::string
|
|
31
|
+
std::string _name;
|
|
32
|
+
#ifdef OP_SQLITE_USE_LIBSQL
|
|
33
|
+
libsql_stmt_t _stmt;
|
|
34
|
+
#else
|
|
30
35
|
// This shouldn't be de-allocated until sqlite3_finalize is called on it
|
|
31
|
-
sqlite3_stmt *
|
|
36
|
+
sqlite3_stmt *_stmt;
|
|
37
|
+
#endif
|
|
32
38
|
};
|
|
33
39
|
|
|
34
40
|
} // namespace opsqlite
|
|
35
|
-
|
|
36
|
-
#endif /* PreparedStatementHostObject_hpp */
|