@op-engineering/op-sqlite 1.0.5 → 1.0.7
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 +26 -0
- package/cpp/bindings.cpp +10 -10
- package/cpp/sqlbatchexecutor.cpp +2 -2
- package/cpp/utils.cpp +51 -50
- package/cpp/utils.h +1 -3
- package/op-sqlite.podspec +39 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -225,6 +225,32 @@ db.executeAsync(
|
|
|
225
225
|
);
|
|
226
226
|
```
|
|
227
227
|
|
|
228
|
+
### Blobs
|
|
229
|
+
|
|
230
|
+
Blobs are supported via `ArrayBuffer`, you need to be careful about the semantics though. You cannot instanciate an instance of `ArrayBuffer` directly, nor pass a typed array directly. Here is an example:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
db = open({
|
|
234
|
+
name: 'blobs',
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
db.execute('DROP TABLE IF EXISTS BlobTable;');
|
|
238
|
+
db.execute(
|
|
239
|
+
'CREATE TABLE BlobTable ( id INT PRIMARY KEY, name TEXT NOT NULL, content BLOB) STRICT;'
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
let buffer = new ArrayBuffer(24);
|
|
243
|
+
let content = new Uint8Array(buffer, 4, 16);
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
crypto.getRandomValues(content);
|
|
246
|
+
|
|
247
|
+
db.execute(`INSERT OR REPLACE INTO BlobTable VALUES (?, ?, ?);`, [
|
|
248
|
+
1,
|
|
249
|
+
'myTestBlob',
|
|
250
|
+
buffer,
|
|
251
|
+
]);
|
|
252
|
+
```
|
|
253
|
+
|
|
228
254
|
### Attach or Detach other databases
|
|
229
255
|
|
|
230
256
|
SQLite supports attaching or detaching other database files into your main database connection through an alias.
|
package/cpp/bindings.cpp
CHANGED
|
@@ -193,15 +193,15 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
193
193
|
const std::string dbName = args[0].asString(rt).utf8(rt);
|
|
194
194
|
const std::string query = args[1].asString(rt).utf8(rt);
|
|
195
195
|
std::vector<JSVariant> params;
|
|
196
|
-
if(count == 3) {
|
|
197
|
-
const jsi::Value &originalParams = args[2];
|
|
198
|
-
params = toAnyVec(rt, originalParams);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
std::vector<DumbHostObject> results;
|
|
202
|
-
std::shared_ptr<std::vector<DynamicHostObject>> metadata = std::make_shared<std::vector<DynamicHostObject>>();
|
|
203
|
-
|
|
204
196
|
try {
|
|
197
|
+
if(count == 3) {
|
|
198
|
+
const jsi::Value &originalParams = args[2];
|
|
199
|
+
params = toVariantVec(rt, originalParams);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
std::vector<DumbHostObject> results;
|
|
203
|
+
std::shared_ptr<std::vector<DynamicHostObject>> metadata = std::make_shared<std::vector<DynamicHostObject>>();
|
|
204
|
+
|
|
205
205
|
auto status = sqliteExecute(dbName, query, ¶ms, &results, metadata);
|
|
206
206
|
|
|
207
207
|
if(status.type == SQLiteError) {
|
|
@@ -210,7 +210,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
210
210
|
|
|
211
211
|
auto jsiResult = createResult(rt, status, &results, metadata);
|
|
212
212
|
return jsiResult;
|
|
213
|
-
} catch(std::exception &e) {
|
|
213
|
+
} catch (const std::exception &e) {
|
|
214
214
|
throw jsi::JSError(rt, e.what());
|
|
215
215
|
}
|
|
216
216
|
});
|
|
@@ -226,7 +226,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
226
226
|
const std::string query = args[1].asString(rt).utf8(rt);
|
|
227
227
|
const jsi::Value &originalParams = args[2];
|
|
228
228
|
|
|
229
|
-
std::vector<JSVariant> params =
|
|
229
|
+
std::vector<JSVariant> params = toVariantVec(rt, originalParams);
|
|
230
230
|
|
|
231
231
|
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
232
232
|
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor", 2) {
|
package/cpp/sqlbatchexecutor.cpp
CHANGED
|
@@ -25,7 +25,7 @@ void toBatchArguments(jsi::Runtime &rt, jsi::Array const &batchParams, std::vect
|
|
|
25
25
|
for (int x = 0; x < batchUpdateParams.length(rt); x++)
|
|
26
26
|
{
|
|
27
27
|
const jsi::Value &p = batchUpdateParams.getValueAtIndex(rt, x);
|
|
28
|
-
auto params = std::make_shared<std::vector<JSVariant>>(
|
|
28
|
+
auto params = std::make_shared<std::vector<JSVariant>>(toVariantVec(rt, p));
|
|
29
29
|
commands->push_back({
|
|
30
30
|
query,
|
|
31
31
|
params
|
|
@@ -34,7 +34,7 @@ void toBatchArguments(jsi::Runtime &rt, jsi::Array const &batchParams, std::vect
|
|
|
34
34
|
}
|
|
35
35
|
else
|
|
36
36
|
{
|
|
37
|
-
auto params = std::make_shared<std::vector<JSVariant>>(
|
|
37
|
+
auto params = std::make_shared<std::vector<JSVariant>>(toVariantVec(rt, commandParams));
|
|
38
38
|
commands->push_back({
|
|
39
39
|
query,
|
|
40
40
|
params
|
package/cpp/utils.cpp
CHANGED
|
@@ -8,54 +8,6 @@ namespace opsqlite {
|
|
|
8
8
|
|
|
9
9
|
namespace jsi = facebook::jsi;
|
|
10
10
|
|
|
11
|
-
JSVariant toAny(jsi::Runtime &rt, jsi::Value &value) {
|
|
12
|
-
if (value.isNull() || value.isUndefined())
|
|
13
|
-
{
|
|
14
|
-
return JSVariant(nullptr);
|
|
15
|
-
}
|
|
16
|
-
else if (value.isBool())
|
|
17
|
-
{
|
|
18
|
-
return JSVariant(value.getBool());
|
|
19
|
-
}
|
|
20
|
-
else if (value.isNumber())
|
|
21
|
-
{
|
|
22
|
-
double doubleVal = value.asNumber();
|
|
23
|
-
int intVal = (int)doubleVal;
|
|
24
|
-
long long longVal = (long)doubleVal;
|
|
25
|
-
if (intVal == doubleVal)
|
|
26
|
-
{
|
|
27
|
-
return JSVariant(intVal);
|
|
28
|
-
}
|
|
29
|
-
else if (longVal == doubleVal)
|
|
30
|
-
{
|
|
31
|
-
return JSVariant(longVal);
|
|
32
|
-
}
|
|
33
|
-
else
|
|
34
|
-
{
|
|
35
|
-
return JSVariant(doubleVal);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else if (value.isString())
|
|
39
|
-
{
|
|
40
|
-
std::string strVal = value.asString(rt).utf8(rt);
|
|
41
|
-
return JSVariant(strVal);
|
|
42
|
-
}
|
|
43
|
-
else if (value.isObject())
|
|
44
|
-
{
|
|
45
|
-
auto object = value.asObject(rt);
|
|
46
|
-
if (object.isArrayBuffer(rt))
|
|
47
|
-
{
|
|
48
|
-
auto buffer = object.getArrayBuffer(rt);
|
|
49
|
-
return JSVariant(ArrayBuffer {
|
|
50
|
-
.data = std::shared_ptr<uint8_t>{buffer.data(rt)},
|
|
51
|
-
.size = buffer.size(rt)
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
throw new std::invalid_argument("Unknown JSI to any value conversion");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
11
|
jsi::Value toJSI(jsi::Runtime &rt, JSVariant value) {
|
|
60
12
|
|
|
61
13
|
if (std::holds_alternative<bool>(value))
|
|
@@ -96,7 +48,7 @@ jsi::Value toJSI(jsi::Runtime &rt, JSVariant value) {
|
|
|
96
48
|
return jsi::Value::null();
|
|
97
49
|
}
|
|
98
50
|
|
|
99
|
-
std::vector<JSVariant>
|
|
51
|
+
std::vector<JSVariant> toVariantVec(jsi::Runtime &rt, jsi::Value const ¶ms)
|
|
100
52
|
{
|
|
101
53
|
std::vector<JSVariant> res;
|
|
102
54
|
|
|
@@ -110,7 +62,56 @@ std::vector<JSVariant> toAnyVec(jsi::Runtime &rt, jsi::Value const ¶ms)
|
|
|
110
62
|
for (int ii = 0; ii < values.length(rt); ii++)
|
|
111
63
|
{
|
|
112
64
|
jsi::Value value = values.getValueAtIndex(rt, ii);
|
|
113
|
-
|
|
65
|
+
|
|
66
|
+
if (value.isNull() || value.isUndefined())
|
|
67
|
+
{
|
|
68
|
+
res.push_back(JSVariant(nullptr));
|
|
69
|
+
}
|
|
70
|
+
else if (value.isBool())
|
|
71
|
+
{
|
|
72
|
+
res.push_back(JSVariant(value.getBool()));
|
|
73
|
+
}
|
|
74
|
+
else if (value.isNumber())
|
|
75
|
+
{
|
|
76
|
+
double doubleVal = value.asNumber();
|
|
77
|
+
int intVal = (int)doubleVal;
|
|
78
|
+
long long longVal = (long)doubleVal;
|
|
79
|
+
if (intVal == doubleVal)
|
|
80
|
+
{
|
|
81
|
+
res.push_back(JSVariant(intVal));
|
|
82
|
+
}
|
|
83
|
+
else if (longVal == doubleVal)
|
|
84
|
+
{
|
|
85
|
+
res.push_back(JSVariant(longVal));
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
{
|
|
89
|
+
res.push_back(JSVariant(doubleVal));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (value.isString())
|
|
93
|
+
{
|
|
94
|
+
std::string strVal = value.asString(rt).utf8(rt);
|
|
95
|
+
res.push_back(JSVariant(strVal));
|
|
96
|
+
}
|
|
97
|
+
else if (value.isObject())
|
|
98
|
+
{
|
|
99
|
+
auto obj = value.asObject(rt);
|
|
100
|
+
auto isArray = obj.isArray(rt);
|
|
101
|
+
auto isFunction = obj.isFunction(rt);
|
|
102
|
+
auto isArrayBuffer = obj.isArrayBuffer(rt);
|
|
103
|
+
if (obj.isArrayBuffer(rt)) {
|
|
104
|
+
auto buffer = obj.getArrayBuffer(rt);
|
|
105
|
+
res.push_back(JSVariant(ArrayBuffer {
|
|
106
|
+
.data = std::shared_ptr<uint8_t>{buffer.data(rt)},
|
|
107
|
+
.size = buffer.size(rt)
|
|
108
|
+
}));
|
|
109
|
+
} else {
|
|
110
|
+
throw std::invalid_argument("Unknown JSI ArrayBuffer to variant value conversion, received object instead of ArrayBuffer");
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
throw std::invalid_argument("Unknown JSI to variant value conversion");
|
|
114
|
+
}
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
return res;
|
package/cpp/utils.h
CHANGED
|
@@ -37,11 +37,9 @@ namespace opsqlite {
|
|
|
37
37
|
int commands;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
JSVariant toAny(jsi::Runtime &rt, jsi::Value &value);
|
|
41
|
-
|
|
42
40
|
jsi::Value toJSI(jsi::Runtime &rt, JSVariant value);
|
|
43
41
|
|
|
44
|
-
std::vector<JSVariant>
|
|
42
|
+
std::vector<JSVariant> toVariantVec(jsi::Runtime &rt, jsi::Value const &args);
|
|
45
43
|
|
|
46
44
|
jsi::Value createResult(jsi::Runtime &rt,
|
|
47
45
|
BridgeResult status,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "op-sqlite"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => "12.0", :osx => "10.7" }
|
|
14
|
+
s.source = { :git => "https://github.com/op-engineering/op-sqlite.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.pod_target_xcconfig = {
|
|
17
|
+
:GCC_PREPROCESSOR_DEFINITIONS => "HAVE_FULLFSYNC=1",
|
|
18
|
+
:WARNING_CFLAGS => "-Wno-shorten-64-to-32 -Wno-comma -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-deprecated-declarations",
|
|
19
|
+
:USE_HEADERMAP => "No"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
s.header_mappings_dir = "cpp"
|
|
23
|
+
s.source_files = "ios/**/*.{h,hpp,m,mm}", "cpp/**/*.{h,hpp,cpp,c}"
|
|
24
|
+
|
|
25
|
+
s.dependency "React-callinvoker"
|
|
26
|
+
s.dependency "React"
|
|
27
|
+
s.dependency "React-Core"
|
|
28
|
+
|
|
29
|
+
s.xcconfig = {
|
|
30
|
+
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if ENV['OP_SQLITE_USE_PHONE_VERSION'] == '1' then
|
|
35
|
+
s.exclude_files = "cpp/sqlite3.c", "cpp/sqlite3.h"
|
|
36
|
+
s.library = "sqlite3"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@op-engineering/op-sqlite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Next generation SQLite for React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"android",
|
|
14
14
|
"ios",
|
|
15
15
|
"cpp",
|
|
16
|
-
"
|
|
16
|
+
"op-sqlite.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
18
18
|
"!android/build",
|
|
19
19
|
"!android/.cxx",
|