@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
|
@@ -23,7 +23,7 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
|
23
23
|
auto name = propNameID.utf8(rt);
|
|
24
24
|
|
|
25
25
|
if (name == "bind") {
|
|
26
|
-
return HOSTFN("bind"
|
|
26
|
+
return HOSTFN("bind") {
|
|
27
27
|
if (_stmt == nullptr) {
|
|
28
28
|
throw std::runtime_error("statement has been freed");
|
|
29
29
|
}
|
|
@@ -41,28 +41,53 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (name == "execute") {
|
|
44
|
-
return HOSTFN("execute"
|
|
44
|
+
return HOSTFN("execute") {
|
|
45
45
|
if (_stmt == nullptr) {
|
|
46
46
|
throw std::runtime_error("statement has been freed");
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
50
|
+
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
|
|
51
|
+
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
|
|
52
|
+
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
53
|
+
|
|
54
|
+
auto task = [&rt, this, resolve, reject,
|
|
55
|
+
invoker = this->_js_call_invoker]() {
|
|
56
|
+
std::vector<DumbHostObject> results;
|
|
57
|
+
std::shared_ptr<std::vector<SmartHostObject>> metadata =
|
|
58
|
+
std::make_shared<std::vector<SmartHostObject>>();
|
|
52
59
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
auto status = opsqlite_libsql_execute_prepared_statement(
|
|
61
|
+
_name, _stmt, &results, metadata);
|
|
55
62
|
#else
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
auto status = opsqlite_execute_prepared_statement(_name, _stmt,
|
|
64
|
+
&results, metadata);
|
|
58
65
|
#endif
|
|
66
|
+
invoker->invokeAsync(
|
|
67
|
+
[&rt, status = std::move(status),
|
|
68
|
+
results = std::make_shared<std::vector<DumbHostObject>>(results),
|
|
69
|
+
metadata, resolve, reject] {
|
|
70
|
+
if (status.type == SQLiteOk) {
|
|
71
|
+
auto jsiResult =
|
|
72
|
+
createResult(rt, status, results.get(), metadata);
|
|
73
|
+
resolve->asObject(rt).asFunction(rt).call(
|
|
74
|
+
rt, std::move(jsiResult));
|
|
75
|
+
} else {
|
|
76
|
+
auto errorCtr =
|
|
77
|
+
rt.global().getPropertyAsFunction(rt, "Error");
|
|
78
|
+
auto error = errorCtr.callAsConstructor(
|
|
79
|
+
rt, jsi::String::createFromUtf8(rt, status.message));
|
|
80
|
+
reject->asObject(rt).asFunction(rt).call(rt, error);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
59
84
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
_thread_pool->queueWork(task);
|
|
86
|
+
|
|
87
|
+
return {};
|
|
88
|
+
}));
|
|
63
89
|
|
|
64
|
-
|
|
65
|
-
return jsiResult;
|
|
90
|
+
return promise;
|
|
66
91
|
});
|
|
67
92
|
}
|
|
68
93
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <ReactCommon/CallInvoker.h>
|
|
3
4
|
#include <jsi/jsi.h>
|
|
4
5
|
#include <memory>
|
|
5
6
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
@@ -7,19 +8,29 @@
|
|
|
7
8
|
#else
|
|
8
9
|
#include <sqlite3.h>
|
|
9
10
|
#endif
|
|
11
|
+
#include "ThreadPool.h"
|
|
10
12
|
#include <string>
|
|
11
13
|
|
|
12
14
|
namespace opsqlite {
|
|
13
15
|
namespace jsi = facebook::jsi;
|
|
16
|
+
namespace react = facebook::react;
|
|
14
17
|
|
|
15
18
|
class PreparedStatementHostObject : public jsi::HostObject {
|
|
16
19
|
public:
|
|
17
20
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
18
|
-
PreparedStatementHostObject(
|
|
19
|
-
|
|
21
|
+
PreparedStatementHostObject(
|
|
22
|
+
std::string name, libsql_stmt_t stmt,
|
|
23
|
+
std::shared_ptr<react::CallInvoker> js_call_invoker,
|
|
24
|
+
std::shared_ptr<ThreadPool> thread_pool)
|
|
25
|
+
: _name(name), _stmt(stmt), _js_call_invoker(js_call_invoker),
|
|
26
|
+
_thread_pool(thread_pool){};
|
|
20
27
|
#else
|
|
21
|
-
PreparedStatementHostObject(
|
|
22
|
-
|
|
28
|
+
PreparedStatementHostObject(
|
|
29
|
+
std::string name, sqlite3_stmt *stmt,
|
|
30
|
+
std::shared_ptr<react::CallInvoker> js_call_invoker,
|
|
31
|
+
std::shared_ptr<ThreadPool> thread_pool)
|
|
32
|
+
: _name(name), _stmt(stmt), _js_call_invoker(js_call_invoker),
|
|
33
|
+
_thread_pool(thread_pool){};
|
|
23
34
|
#endif
|
|
24
35
|
virtual ~PreparedStatementHostObject();
|
|
25
36
|
|
|
@@ -28,6 +39,8 @@ public:
|
|
|
28
39
|
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
|
|
29
40
|
|
|
30
41
|
private:
|
|
42
|
+
std::shared_ptr<react::CallInvoker> _js_call_invoker;
|
|
43
|
+
std::shared_ptr<ThreadPool> _thread_pool;
|
|
31
44
|
std::string _name;
|
|
32
45
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
33
46
|
libsql_stmt_t _stmt;
|
package/cpp/bindings.cpp
CHANGED
|
@@ -21,6 +21,7 @@ namespace jsi = facebook::jsi;
|
|
|
21
21
|
|
|
22
22
|
std::string _base_path;
|
|
23
23
|
std::string _crsqlite_path;
|
|
24
|
+
std::string _sqlite_vec_path;
|
|
24
25
|
std::shared_ptr<react::CallInvoker> _invoker;
|
|
25
26
|
std::shared_ptr<ThreadPool> thread_pool = std::make_shared<ThreadPool>();
|
|
26
27
|
|
|
@@ -43,13 +44,15 @@ void clearState() {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
|
|
46
|
-
const char *base_path, const char *crsqlite_path
|
|
47
|
+
const char *base_path, const char *crsqlite_path,
|
|
48
|
+
const char *sqlite_vec_path) {
|
|
47
49
|
invalidated = false;
|
|
48
50
|
_base_path = std::string(base_path);
|
|
49
51
|
_crsqlite_path = std::string(crsqlite_path);
|
|
52
|
+
_sqlite_vec_path = std::string(sqlite_vec_path);
|
|
50
53
|
_invoker = invoker;
|
|
51
54
|
|
|
52
|
-
auto open = HOSTFN("open"
|
|
55
|
+
auto open = HOSTFN("open") {
|
|
53
56
|
jsi::Object options = args[0].asObject(rt);
|
|
54
57
|
std::string name = options.getProperty(rt, "name").asString(rt).utf8(rt);
|
|
55
58
|
std::string path = std::string(_base_path);
|
|
@@ -82,13 +85,13 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
|
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
std::shared_ptr<DBHostObject> db =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
|
|
89
|
+
rt, path, invoker, thread_pool, name, path, _crsqlite_path,
|
|
90
|
+
_sqlite_vec_path, encryptionKey);
|
|
88
91
|
return jsi::Object::createFromHostObject(rt, db);
|
|
89
92
|
});
|
|
90
93
|
|
|
91
|
-
auto is_sqlcipher = HOSTFN("isSQLCipher"
|
|
94
|
+
auto is_sqlcipher = HOSTFN("isSQLCipher") {
|
|
92
95
|
#ifdef OP_SQLITE_USE_SQLCIPHER
|
|
93
96
|
return true;
|
|
94
97
|
#else
|
|
@@ -96,7 +99,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
|
|
|
96
99
|
#endif
|
|
97
100
|
});
|
|
98
101
|
|
|
99
|
-
auto is_libsql = HOSTFN("isLibsql"
|
|
102
|
+
auto is_libsql = HOSTFN("isLibsql") {
|
|
100
103
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
101
104
|
return true;
|
|
102
105
|
#else
|
|
@@ -105,7 +108,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
|
|
|
105
108
|
});
|
|
106
109
|
|
|
107
110
|
#ifdef OP_SQLITE_USE_LIBSQL
|
|
108
|
-
auto open_remote = HOSTFN("openRemote"
|
|
111
|
+
auto open_remote = HOSTFN("openRemote") {
|
|
109
112
|
jsi::Object options = args[0].asObject(rt);
|
|
110
113
|
std::string url = options.getProperty(rt, "url").asString(rt).utf8(rt);
|
|
111
114
|
std::string auth_token =
|
|
@@ -116,7 +119,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
|
|
|
116
119
|
return jsi::Object::createFromHostObject(rt, db);
|
|
117
120
|
});
|
|
118
121
|
|
|
119
|
-
auto open_sync = HOSTFN("openSync"
|
|
122
|
+
auto open_sync = HOSTFN("openSync") {
|
|
120
123
|
jsi::Object options = args[0].asObject(rt);
|
|
121
124
|
std::string name = options.getProperty(rt, "name").asString(rt).utf8(rt);
|
|
122
125
|
std::string path = std::string(_base_path);
|
package/cpp/bindings.h
CHANGED
|
@@ -10,7 +10,8 @@ namespace jsi = facebook::jsi;
|
|
|
10
10
|
namespace react = facebook::react;
|
|
11
11
|
|
|
12
12
|
void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
|
|
13
|
-
const char *base_path, const char *crsqlite_path
|
|
13
|
+
const char *base_path, const char *crsqlite_path,
|
|
14
|
+
const char *sqlite_vec_path);
|
|
14
15
|
void clearState();
|
|
15
16
|
|
|
16
17
|
} // namespace opsqlite
|