@op-engineering/op-sqlite 11.2.14 → 11.3.0
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/cpp/DBHostObject.cpp +627 -591
- package/cpp/DBHostObject.h +54 -53
- package/cpp/DumbHostObject.cpp +35 -34
- package/cpp/DumbHostObject.h +12 -11
- package/cpp/PreparedStatementHostObject.cpp +102 -96
- package/cpp/PreparedStatementHostObject.h +28 -26
- package/cpp/SmartHostObject.cpp +13 -13
- package/cpp/SmartHostObject.h +6 -5
- package/cpp/ThreadPool.cpp +80 -78
- package/cpp/ThreadPool.h +28 -28
- package/cpp/bindings.cpp +112 -108
- package/cpp/bridge.cpp +637 -615
- package/cpp/bridge.h +4 -4
- package/cpp/libsql/bridge.cpp +566 -564
- package/cpp/libsql/bridge.h +16 -23
- package/cpp/libsql/libsql.h +62 -48
- package/cpp/logs.h +17 -17
- package/cpp/types.h +12 -12
- package/cpp/utils.cpp +254 -248
- package/lib/commonjs/Storage.js +60 -0
- package/lib/commonjs/Storage.js.map +1 -0
- package/lib/commonjs/index.js +9 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Storage.js +53 -0
- package/lib/module/Storage.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/Storage.d.ts +23 -0
- package/lib/typescript/src/Storage.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Storage.ts +85 -0
- package/src/index.ts +4 -1
package/cpp/DBHostObject.h
CHANGED
|
@@ -19,79 +19,80 @@ namespace jsi = facebook::jsi;
|
|
|
19
19
|
namespace react = facebook::react;
|
|
20
20
|
|
|
21
21
|
struct PendingReactiveInvocation {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
std::string db_name;
|
|
23
|
+
std::string table;
|
|
24
|
+
std::string rowid;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
struct TableRowDiscriminator {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
std::string table;
|
|
29
|
+
std::vector<int> ids;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
struct ReactiveQuery {
|
|
33
33
|
#ifndef OP_SQLITE_USE_LIBSQL
|
|
34
|
-
|
|
34
|
+
sqlite3_stmt *stmt;
|
|
35
35
|
#endif
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
std::vector<TableRowDiscriminator> discriminators;
|
|
37
|
+
std::shared_ptr<jsi::Value> callback;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
class JSI_EXPORT DBHostObject : public jsi::HostObject {
|
|
41
|
-
public:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
public:
|
|
42
|
+
// Normal constructor shared between all backends
|
|
43
|
+
DBHostObject(jsi::Runtime &rt, std::string &base_path,
|
|
44
|
+
std::shared_ptr<react::CallInvoker> invoker,
|
|
45
|
+
std::string &db_name, std::string &path,
|
|
46
|
+
std::string &crsqlite_path, std::string &sqlite_vec_path,
|
|
47
|
+
std::string &encryption_key);
|
|
48
48
|
|
|
49
49
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// Constructor for remoteOpen, purely for remote databases
|
|
51
|
+
DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token,
|
|
52
|
+
std::shared_ptr<react::CallInvoker> invoker);
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
// Constructor for a local database with remote sync
|
|
55
|
+
DBHostObject(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
|
|
56
|
+
std::string &db_name, std::string &path, std::string &url,
|
|
57
|
+
std::string &auth_token, int sync_interval);
|
|
58
58
|
#endif
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
61
|
+
jsi::Value get(jsi::Runtime &rt,
|
|
62
|
+
const jsi::PropNameID &propNameID) override;
|
|
63
|
+
void set(jsi::Runtime &rt, const jsi::PropNameID &name,
|
|
64
|
+
const jsi::Value &value) override;
|
|
65
|
+
void on_update(const std::string &table, const std::string &operation,
|
|
66
|
+
long long row_id);
|
|
67
|
+
void on_commit();
|
|
68
|
+
void on_rollback();
|
|
69
|
+
void invalidate();
|
|
70
|
+
~DBHostObject() override;
|
|
70
71
|
|
|
71
|
-
private:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
private:
|
|
73
|
+
std::set<std::shared_ptr<ReactiveQuery>> pending_reactive_queries;
|
|
74
|
+
void auto_register_update_hook();
|
|
75
|
+
void create_jsi_functions();
|
|
76
|
+
void
|
|
77
|
+
flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
std::unordered_map<std::string, jsi::Value> function_map;
|
|
80
|
+
std::string base_path;
|
|
81
|
+
std::shared_ptr<react::CallInvoker> invoker;
|
|
82
|
+
std::shared_ptr<ThreadPool> _thread_pool;
|
|
83
|
+
std::string db_name;
|
|
84
|
+
std::shared_ptr<jsi::Value> update_hook_callback;
|
|
85
|
+
std::shared_ptr<jsi::Value> commit_hook_callback;
|
|
86
|
+
std::shared_ptr<jsi::Value> rollback_hook_callback;
|
|
87
|
+
jsi::Runtime &rt;
|
|
88
|
+
std::vector<std::shared_ptr<ReactiveQuery>> reactive_queries;
|
|
89
|
+
std::vector<PendingReactiveInvocation> pending_reactive_invocations;
|
|
90
|
+
bool is_update_hook_registered = false;
|
|
91
|
+
bool invalidated = false;
|
|
91
92
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
92
|
-
|
|
93
|
+
DB db;
|
|
93
94
|
#else
|
|
94
|
-
|
|
95
|
+
sqlite3 *db;
|
|
95
96
|
#endif
|
|
96
97
|
};
|
|
97
98
|
|
package/cpp/DumbHostObject.cpp
CHANGED
|
@@ -9,63 +9,64 @@ namespace jsi = facebook::jsi;
|
|
|
9
9
|
|
|
10
10
|
DumbHostObject::DumbHostObject(
|
|
11
11
|
std::shared_ptr<std::vector<SmartHostObject>> metadata) {
|
|
12
|
-
|
|
12
|
+
this->metadata = metadata;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
std::vector<jsi::PropNameID>
|
|
16
16
|
DumbHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
17
|
-
|
|
17
|
+
std::vector<jsi::PropNameID> keys;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
for (auto field : *metadata) {
|
|
20
|
+
// TODO improve this by generating the propName once on metadata
|
|
21
|
+
// creation
|
|
22
|
+
keys.push_back(jsi::PropNameID::forAscii(
|
|
23
|
+
rt, std::get<std::string>(field.fields[0].second)));
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
return keys;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
jsi::Value DumbHostObject::get(jsi::Runtime &rt,
|
|
29
30
|
const jsi::PropNameID &propNameID) {
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
auto name = propNameID.utf8(rt);
|
|
33
|
+
auto fields = metadata.get();
|
|
34
|
+
for (int i = 0; i < fields->size(); i++) {
|
|
35
|
+
auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
|
|
36
|
+
if (fieldName == name) {
|
|
37
|
+
return to_jsi(rt, values.at(i));
|
|
38
|
+
}
|
|
37
39
|
}
|
|
38
|
-
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
for (auto pairField : ownValues) {
|
|
42
|
+
if (name == pairField.first) {
|
|
43
|
+
return to_jsi(rt, pairField.second);
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
|
-
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
return {};
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
void DumbHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
|
|
50
51
|
const jsi::Value &value) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
auto key = name.utf8(rt);
|
|
53
|
+
auto fields = metadata.get();
|
|
54
|
+
for (int i = 0; i < fields->size(); i++) {
|
|
55
|
+
auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
|
|
56
|
+
if (fieldName == key) {
|
|
57
|
+
values[i] = to_variant(rt, value);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
58
60
|
}
|
|
59
|
-
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
for (auto pairField : ownValues) {
|
|
63
|
+
if (key == pairField.first) {
|
|
64
|
+
pairField.second = to_variant(rt, value);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
|
-
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
ownValues.push_back(std::make_pair(key, to_variant(rt, value)));
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
} // namespace opsqlite
|
package/cpp/DumbHostObject.h
CHANGED
|
@@ -12,24 +12,25 @@ namespace opsqlite {
|
|
|
12
12
|
namespace jsi = facebook::jsi;
|
|
13
13
|
|
|
14
14
|
class JSI_EXPORT DumbHostObject : public jsi::HostObject {
|
|
15
|
-
public:
|
|
16
|
-
|
|
15
|
+
public:
|
|
16
|
+
DumbHostObject() = default;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
explicit DumbHostObject(
|
|
19
|
+
std::shared_ptr<std::vector<SmartHostObject>> metadata);
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
jsi::Value get(jsi::Runtime &rt,
|
|
24
|
+
const jsi::PropNameID &propNameID) override;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
void set(jsi::Runtime &rt, const jsi::PropNameID &name,
|
|
27
|
+
const jsi::Value &value) override;
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
std::vector<JSVariant> values;
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
std::shared_ptr<std::vector<SmartHostObject>> metadata;
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
std::vector<std::pair<std::string, JSVariant>> ownValues;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
} // namespace opsqlite
|
|
@@ -13,132 +13,138 @@ namespace jsi = facebook::jsi;
|
|
|
13
13
|
|
|
14
14
|
std::vector<jsi::PropNameID>
|
|
15
15
|
PreparedStatementHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
16
|
-
|
|
16
|
+
std::vector<jsi::PropNameID> keys;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
return keys;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
22
22
|
const jsi::PropNameID &propNameID) {
|
|
23
|
-
|
|
23
|
+
auto name = propNameID.utf8(rt);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
if (name == "bind") {
|
|
26
|
+
return HOSTFN("bind") {
|
|
27
|
+
if (_stmt == nullptr) {
|
|
28
|
+
throw std::runtime_error("statement has been freed");
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const jsi::Value &js_params = args[0];
|
|
32
|
+
std::vector<JSVariant> params = to_variant_vec(rt, js_params);
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
35
35
|
auto promise = promiseCtr.callAsConstructor(
|
|
36
36
|
rt, HOSTFN("executor") {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
38
|
+
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
39
|
+
auto task = [&rt, this, resolve, reject,
|
|
40
|
+
invoker = this->_js_call_invoker, params]() {
|
|
41
|
+
try {
|
|
42
42
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
43
|
-
|
|
43
|
+
opsqlite_libsql_bind_statement(_stmt, ¶ms);
|
|
44
44
|
#else
|
|
45
|
-
|
|
45
|
+
opsqlite_bind_statement(_stmt, ¶ms);
|
|
46
46
|
#endif
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
invoker->invokeAsync([&rt, resolve] {
|
|
48
|
+
resolve->asObject(rt).asFunction(rt).call(rt, {});
|
|
49
|
+
});
|
|
50
|
+
} catch (const std::runtime_error &e) {
|
|
51
|
+
invoker->invokeAsync([&rt, e, reject] {
|
|
52
|
+
auto errorCtr =
|
|
53
|
+
rt.global().getPropertyAsFunction(rt, "Error");
|
|
54
|
+
auto error = errorCtr.callAsConstructor(
|
|
55
|
+
rt, jsi::String::createFromUtf8(rt, e.what()));
|
|
56
|
+
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
57
|
+
});
|
|
58
|
+
} catch (const std::exception &e) {
|
|
59
|
+
invoker->invokeAsync([&rt, e, reject] {
|
|
60
|
+
auto errorCtr =
|
|
61
|
+
rt.global().getPropertyAsFunction(rt, "Error");
|
|
62
|
+
auto error = errorCtr.callAsConstructor(
|
|
63
|
+
rt, jsi::String::createFromUtf8(rt, e.what()));
|
|
64
|
+
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
_thread_pool->queueWork(task);
|
|
70
|
+
|
|
71
|
+
return {};
|
|
70
72
|
}));
|
|
71
73
|
return promise;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
});
|
|
75
|
+
}
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
if (name == "execute") {
|
|
78
|
+
return HOSTFN("execute") {
|
|
79
|
+
if (_stmt == nullptr) {
|
|
80
|
+
throw std::runtime_error("statement has been freed");
|
|
81
|
+
}
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
82
84
|
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
86
|
+
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
87
|
+
|
|
88
|
+
auto task = [&rt, this, resolve, reject,
|
|
89
|
+
invoker = this->_js_call_invoker]() {
|
|
90
|
+
std::vector<DumbHostObject> results;
|
|
91
|
+
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
92
|
+
std::make_shared<std::vector<SmartHostObject>>();
|
|
93
|
+
try {
|
|
92
94
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
auto status =
|
|
96
|
+
opsqlite_libsql_execute_prepared_statement(
|
|
97
|
+
_db, _stmt, &results, metadata);
|
|
95
98
|
#else
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
auto status = opsqlite_execute_prepared_statement(
|
|
100
|
+
_db, _stmt, &results, metadata);
|
|
98
101
|
#endif
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
102
|
+
invoker->invokeAsync(
|
|
103
|
+
[&rt, status = std::move(status),
|
|
104
|
+
results =
|
|
105
|
+
std::make_shared<std::vector<DumbHostObject>>(
|
|
106
|
+
results),
|
|
107
|
+
metadata, resolve] {
|
|
108
|
+
auto jsiResult = create_result(
|
|
109
|
+
rt, status, results.get(), metadata);
|
|
110
|
+
resolve->asObject(rt).asFunction(rt).call(
|
|
111
|
+
rt, std::move(jsiResult));
|
|
112
|
+
});
|
|
113
|
+
} catch (std::exception &exc) {
|
|
114
|
+
invoker->invokeAsync([&rt, &exc, reject] {
|
|
115
|
+
auto errorCtr =
|
|
116
|
+
rt.global().getPropertyAsFunction(rt, "Error");
|
|
117
|
+
auto error = errorCtr.callAsConstructor(
|
|
118
|
+
rt,
|
|
119
|
+
jsi::String::createFromUtf8(rt, exc.what()));
|
|
120
|
+
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
_thread_pool->queueWork(task);
|
|
126
|
+
|
|
127
|
+
return {};
|
|
122
128
|
}));
|
|
123
129
|
|
|
124
130
|
return promise;
|
|
125
|
-
|
|
126
|
-
|
|
131
|
+
});
|
|
132
|
+
}
|
|
127
133
|
|
|
128
|
-
|
|
134
|
+
return {};
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
PreparedStatementHostObject::~PreparedStatementHostObject() {
|
|
132
138
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
if (_stmt != nullptr) {
|
|
140
|
+
libsql_free_stmt(_stmt);
|
|
141
|
+
_stmt = nullptr;
|
|
142
|
+
}
|
|
137
143
|
#else
|
|
138
|
-
|
|
139
|
-
// sqlite3_finalize(_stmt);
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
if (_stmt != nullptr) {
|
|
145
|
+
// sqlite3_finalize(_stmt);
|
|
146
|
+
_stmt = nullptr;
|
|
147
|
+
}
|
|
142
148
|
#endif
|
|
143
149
|
}
|
|
144
150
|
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
#include <jsi/jsi.h>
|
|
5
5
|
#include <memory>
|
|
6
6
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
7
|
-
#include "libsql/bridge.h"
|
|
8
7
|
#include "libsql.h"
|
|
8
|
+
#include "libsql/bridge.h"
|
|
9
9
|
#else
|
|
10
10
|
#include <sqlite3.h>
|
|
11
11
|
#endif
|
|
@@ -18,40 +18,42 @@ namespace jsi = facebook::jsi;
|
|
|
18
18
|
namespace react = facebook::react;
|
|
19
19
|
|
|
20
20
|
class PreparedStatementHostObject : public jsi::HostObject {
|
|
21
|
-
public:
|
|
21
|
+
public:
|
|
22
22
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
PreparedStatementHostObject(
|
|
24
|
+
DB const &db, std::string name, libsql_stmt_t stmt,
|
|
25
|
+
std::shared_ptr<react::CallInvoker> js_call_invoker,
|
|
26
|
+
std::shared_ptr<ThreadPool> thread_pool)
|
|
27
|
+
: _db(db), _name(std::move(name)), _stmt(stmt),
|
|
28
|
+
_js_call_invoker(js_call_invoker), _thread_pool(thread_pool) {};
|
|
29
29
|
#else
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
PreparedStatementHostObject(
|
|
31
|
+
sqlite3 *db, std::string name, sqlite3_stmt *stmt,
|
|
32
|
+
std::shared_ptr<react::CallInvoker> js_call_invoker,
|
|
33
|
+
std::shared_ptr<ThreadPool> thread_pool)
|
|
34
|
+
: _db(db), _name(std::move(name)), _stmt(stmt),
|
|
35
|
+
_js_call_invoker(std::move(js_call_invoker)),
|
|
36
|
+
_thread_pool(std::move(thread_pool)) {};
|
|
36
37
|
#endif
|
|
37
|
-
|
|
38
|
+
~PreparedStatementHostObject() override;
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
jsi::Value get(jsi::Runtime &rt,
|
|
43
|
+
const jsi::PropNameID &propNameID) override;
|
|
42
44
|
|
|
43
|
-
private:
|
|
44
|
-
|
|
45
|
+
private:
|
|
46
|
+
std::string _name;
|
|
45
47
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
DB _db;
|
|
49
|
+
libsql_stmt_t _stmt;
|
|
48
50
|
#else
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
sqlite3 *_db;
|
|
52
|
+
// This shouldn't be de-allocated until sqlite3_finalize is called on it
|
|
53
|
+
sqlite3_stmt *_stmt;
|
|
52
54
|
#endif
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
std::shared_ptr<react::CallInvoker> _js_call_invoker;
|
|
56
|
+
std::shared_ptr<ThreadPool> _thread_pool;
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
} // namespace opsqlite
|
package/cpp/SmartHostObject.cpp
CHANGED
|
@@ -7,28 +7,28 @@ namespace jsi = facebook::jsi;
|
|
|
7
7
|
|
|
8
8
|
std::vector<jsi::PropNameID>
|
|
9
9
|
SmartHostObject::getPropertyNames(jsi::Runtime &rt) {
|
|
10
|
-
|
|
10
|
+
std::vector<jsi::PropNameID> keys;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
for (const auto&
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
keys.reserve(fields.size());
|
|
13
|
+
for (const auto &field : fields) {
|
|
14
|
+
keys.emplace_back(jsi::PropNameID::forAscii(rt, field.first));
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
return keys;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
jsi::Value SmartHostObject::get(jsi::Runtime &rt,
|
|
21
21
|
const jsi::PropNameID &propNameID) {
|
|
22
|
-
|
|
22
|
+
auto name = propNameID.utf8(rt);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
for (const auto &field : fields) {
|
|
25
|
+
auto fieldName = field.first;
|
|
26
|
+
if (fieldName == name) {
|
|
27
|
+
return to_jsi(rt, field.second);
|
|
28
|
+
}
|
|
28
29
|
}
|
|
29
|
-
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
return {};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
} // namespace opsqlite
|
package/cpp/SmartHostObject.h
CHANGED
|
@@ -10,14 +10,15 @@ namespace opsqlite {
|
|
|
10
10
|
namespace jsi = facebook::jsi;
|
|
11
11
|
|
|
12
12
|
class JSI_EXPORT SmartHostObject : public jsi::HostObject {
|
|
13
|
-
public:
|
|
14
|
-
|
|
13
|
+
public:
|
|
14
|
+
SmartHostObject() = default;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
jsi::Value get(jsi::Runtime &rt,
|
|
19
|
+
const jsi::PropNameID &propNameID) override;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
std::vector<std::pair<std::string, JSVariant>> fields;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
} // namespace opsqlite
|