@op-engineering/op-sqlite 15.0.7 → 15.1.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/android/CMakeLists.txt +1 -1
- package/android/build.gradle +1 -1
- package/android/cpp-adapter.cpp +1 -1
- package/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt +7 -9
- package/cpp/DBHostObject.cpp +469 -677
- package/cpp/DBHostObject.h +56 -58
- package/cpp/DumbHostObject.cpp +1 -1
- package/cpp/DumbHostObject.h +12 -13
- package/cpp/OPSqlite.cpp +207 -0
- package/cpp/OPThreadPool.cpp +79 -79
- package/cpp/OPThreadPool.h +28 -28
- package/cpp/PreparedStatementHostObject.cpp +87 -136
- package/cpp/PreparedStatementHostObject.h +16 -28
- package/cpp/SmartHostObject.cpp +1 -1
- package/cpp/SmartHostObject.h +6 -7
- package/cpp/bridge.cpp +639 -633
- package/cpp/bridge.h +2 -2
- package/cpp/libsql/LICENSE.txt +9 -0
- package/cpp/libsql/bridge.cpp +2 -2
- package/cpp/libsql/{bridge.h → bridge.hpp} +4 -4
- package/cpp/macros.hpp +21 -0
- package/cpp/sqlcipher/LICENSE.txt +24 -0
- package/cpp/types.hpp +42 -0
- package/cpp/utils.cpp +320 -255
- package/cpp/{utils.h → utils.hpp} +9 -1
- package/ios/OPSQLite.mm +104 -106
- package/lib/module/functions.js +40 -33
- package/lib/module/functions.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/functions.d.ts +5 -1
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +5 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/op-sqlite.podspec +1 -1
- package/package.json +10 -8
- package/src/functions.ts +52 -43
- package/src/index.ts +1 -12
- package/src/types.ts +5 -1
- package/cpp/bindings.cpp +0 -202
- package/cpp/macros.h +0 -15
- package/cpp/types.h +0 -33
- /package/cpp/{bindings.h → OPSqlite.hpp} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#include "PreparedStatementHostObject.h"
|
|
2
2
|
#if OP_SQLITE_USE_LIBSQL
|
|
3
|
-
#include "libsql/bridge.
|
|
3
|
+
#include "libsql/bridge.hpp"
|
|
4
4
|
#else
|
|
5
5
|
#include "bridge.h"
|
|
6
6
|
#endif
|
|
7
|
-
#include "macros.
|
|
8
|
-
#include "utils.
|
|
7
|
+
#include "macros.hpp"
|
|
8
|
+
#include "utils.hpp"
|
|
9
9
|
|
|
10
10
|
namespace opsqlite {
|
|
11
11
|
|
|
@@ -13,161 +13,112 @@ 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 HFN(this) {
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 {
|
|
34
|
+
return promisify(
|
|
35
|
+
rt,
|
|
36
|
+
[this, params]() {
|
|
42
37
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
43
|
-
|
|
38
|
+
opsqlite_libsql_bind_statement(_stmt, ¶ms);
|
|
44
39
|
#else
|
|
45
|
-
|
|
40
|
+
opsqlite_bind_statement(_stmt, ¶ms);
|
|
46
41
|
#endif
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
_thread_pool->queueWork(task);
|
|
70
|
-
|
|
71
|
-
return {};
|
|
72
|
-
}));
|
|
73
|
-
return promise;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (name == "bindSync") {
|
|
78
|
-
return HOSTFN("bindSync") {
|
|
79
|
-
if (_stmt == nullptr) {
|
|
80
|
-
throw std::runtime_error("statement has been freed");
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const jsi::Value &js_params = args[0];
|
|
84
|
-
std::vector<JSVariant> params = to_variant_vec(rt, js_params);
|
|
85
|
-
try {
|
|
42
|
+
return nullptr;
|
|
43
|
+
},
|
|
44
|
+
[](jsi::Runtime &rt, std::any result) {
|
|
45
|
+
return jsi::Value::undefined;
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (name == "bindSync") {
|
|
51
|
+
return HOSTFN("bindSync") {
|
|
52
|
+
if (_stmt == nullptr) {
|
|
53
|
+
throw std::runtime_error("statement has been freed");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const jsi::Value &js_params = args[0];
|
|
57
|
+
std::vector<JSVariant> params = to_variant_vec(rt, js_params);
|
|
58
|
+
try {
|
|
86
59
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
87
|
-
|
|
60
|
+
opsqlite_libsql_bind_statement(_stmt, ¶ms);
|
|
88
61
|
#else
|
|
89
|
-
|
|
62
|
+
opsqlite_bind_statement(_stmt, ¶ms);
|
|
90
63
|
#endif
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
auto task = [&rt, this, resolve, reject,
|
|
112
|
-
invoker = this->_js_call_invoker]() {
|
|
113
|
-
std::vector<DumbHostObject> results;
|
|
114
|
-
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
115
|
-
std::make_shared<std::vector<SmartHostObject>>();
|
|
116
|
-
try {
|
|
64
|
+
} catch (const std::runtime_error &e) {
|
|
65
|
+
throw std::runtime_error(e.what());
|
|
66
|
+
} catch (const std::exception &e) {
|
|
67
|
+
throw std::runtime_error(e.what());
|
|
68
|
+
}
|
|
69
|
+
return {};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (name == "execute") {
|
|
74
|
+
return HOSTFN("execute") {
|
|
75
|
+
if (_stmt == nullptr) {
|
|
76
|
+
throw std::runtime_error("statement has been freed");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return promisify(
|
|
80
|
+
rt,
|
|
81
|
+
[this]() {
|
|
82
|
+
std::vector<DumbHostObject> results;
|
|
83
|
+
auto metadata = std::make_shared<std::vector<SmartHostObject>>();
|
|
117
84
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
_db, _stmt, &results, metadata);
|
|
85
|
+
auto status = opsqlite_libsql_execute_prepared_statement(
|
|
86
|
+
_db, _stmt, &results, metadata);
|
|
121
87
|
#else
|
|
122
|
-
|
|
123
|
-
|
|
88
|
+
auto status = opsqlite_execute_prepared_statement(
|
|
89
|
+
_db, _stmt, &results, metadata);
|
|
124
90
|
#endif
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
_thread_pool->queueWork(task);
|
|
149
|
-
|
|
150
|
-
return {};
|
|
151
|
-
}));
|
|
152
|
-
|
|
153
|
-
return promise;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return {};
|
|
91
|
+
return std::make_tuple(results, *metadata, status);
|
|
92
|
+
},
|
|
93
|
+
[](jsi::Runtime &rt, std::any result) {
|
|
94
|
+
auto tuple = std::any_cast<
|
|
95
|
+
std::tuple<std::vector<DumbHostObject>,
|
|
96
|
+
std::vector<SmartHostObject>, BridgeResult>>(result);
|
|
97
|
+
const auto &results = std::get<0>(tuple);
|
|
98
|
+
const auto &metadata = std::get<1>(tuple);
|
|
99
|
+
BridgeResult status = std::get<2>(tuple);
|
|
100
|
+
auto results_ptr =
|
|
101
|
+
std::make_shared<std::vector<DumbHostObject>>(results);
|
|
102
|
+
auto metadata_ptr =
|
|
103
|
+
std::make_shared<std::vector<SmartHostObject>>(metadata);
|
|
104
|
+
return create_result(rt, status, results_ptr.get(), metadata_ptr);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return {};
|
|
158
109
|
}
|
|
159
110
|
|
|
160
111
|
PreparedStatementHostObject::~PreparedStatementHostObject() {
|
|
161
112
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
113
|
+
if (_stmt != nullptr) {
|
|
114
|
+
libsql_free_stmt(_stmt);
|
|
115
|
+
_stmt = nullptr;
|
|
116
|
+
}
|
|
166
117
|
#else
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
118
|
+
if (_stmt != nullptr) {
|
|
119
|
+
// sqlite3_finalize(_stmt);
|
|
120
|
+
_stmt = nullptr;
|
|
121
|
+
}
|
|
171
122
|
#endif
|
|
172
123
|
}
|
|
173
124
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
#include <memory>
|
|
6
6
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
7
7
|
#include "libsql.h"
|
|
8
|
-
#include "libsql/bridge.
|
|
8
|
+
#include "libsql/bridge.hpp"
|
|
9
9
|
#else
|
|
10
10
|
#ifdef __ANDROID__
|
|
11
11
|
#include "sqlite3.h"
|
|
@@ -22,42 +22,30 @@ namespace jsi = facebook::jsi;
|
|
|
22
22
|
namespace react = facebook::react;
|
|
23
23
|
|
|
24
24
|
class PreparedStatementHostObject : public jsi::HostObject {
|
|
25
|
-
|
|
25
|
+
public:
|
|
26
26
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
std::shared_ptr<ThreadPool> thread_pool)
|
|
31
|
-
: _db(db), _name(std::move(name)), _stmt(stmt),
|
|
32
|
-
_js_call_invoker(js_call_invoker), _thread_pool(thread_pool) {};
|
|
27
|
+
PreparedStatementHostObject(
|
|
28
|
+
DB const &db, libsql_stmt_t stmt)
|
|
29
|
+
: _db(db), _stmt(stmt) {};
|
|
33
30
|
#else
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
std::shared_ptr<react::CallInvoker> js_call_invoker,
|
|
37
|
-
std::shared_ptr<ThreadPool> thread_pool)
|
|
38
|
-
: _db(db), _name(std::move(name)), _stmt(stmt),
|
|
39
|
-
_js_call_invoker(std::move(js_call_invoker)),
|
|
40
|
-
_thread_pool(std::move(thread_pool)) {};
|
|
31
|
+
PreparedStatementHostObject(sqlite3 *db, sqlite3_stmt *stmt)
|
|
32
|
+
: _db(db), _stmt(stmt) {};
|
|
41
33
|
#endif
|
|
42
|
-
|
|
34
|
+
~PreparedStatementHostObject() override;
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
const jsi::PropNameID &propNameID) override;
|
|
38
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
std::string _name;
|
|
40
|
+
private:
|
|
51
41
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
DB _db;
|
|
43
|
+
libsql_stmt_t _stmt;
|
|
54
44
|
#else
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
sqlite3 *_db;
|
|
46
|
+
// This shouldn't be de-allocated until sqlite3_finalize is called on it
|
|
47
|
+
sqlite3_stmt *_stmt;
|
|
58
48
|
#endif
|
|
59
|
-
std::shared_ptr<react::CallInvoker> _js_call_invoker;
|
|
60
|
-
std::shared_ptr<ThreadPool> _thread_pool;
|
|
61
49
|
};
|
|
62
50
|
|
|
63
51
|
} // namespace opsqlite
|
package/cpp/SmartHostObject.cpp
CHANGED
package/cpp/SmartHostObject.h
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include "types.
|
|
3
|
+
#include "types.hpp"
|
|
4
4
|
#include <any>
|
|
5
5
|
#include <jsi/jsi.h>
|
|
6
6
|
#include <vector>
|
|
@@ -10,15 +10,14 @@ namespace opsqlite {
|
|
|
10
10
|
namespace jsi = facebook::jsi;
|
|
11
11
|
|
|
12
12
|
class JSI_EXPORT SmartHostObject : public jsi::HostObject {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
public:
|
|
14
|
+
SmartHostObject() = default;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const jsi::PropNameID &propNameID) override;
|
|
18
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
std::vector<std::pair<std::string, JSVariant>> fields;
|
|
22
21
|
};
|
|
23
22
|
|
|
24
23
|
} // namespace opsqlite
|