@op-engineering/op-sqlite 9.0.0 → 9.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/cpp/bridge.cpp +6 -3
- package/cpp/utils.cpp +4 -4
- package/cpp/utils.h +2 -2
- package/package.json +1 -1
package/cpp/bridge.cpp
CHANGED
|
@@ -400,8 +400,11 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
|
|
|
400
400
|
int status, current_column, column_count, column_type;
|
|
401
401
|
std::string column_name, column_declared_type;
|
|
402
402
|
std::vector<std::string> column_names;
|
|
403
|
+
column_names.reserve(20);
|
|
403
404
|
std::vector<std::vector<JSVariant>> rows;
|
|
405
|
+
rows.reserve(20);
|
|
404
406
|
std::vector<JSVariant> row;
|
|
407
|
+
row.reserve(10);
|
|
405
408
|
|
|
406
409
|
do {
|
|
407
410
|
const char *query_str =
|
|
@@ -436,7 +439,7 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
|
|
|
436
439
|
// Do a first pass to get the column names
|
|
437
440
|
for (int i = 0; i < column_count; i++) {
|
|
438
441
|
column_name = sqlite3_column_name(statement, i);
|
|
439
|
-
column_names.
|
|
442
|
+
column_names.emplace_back(column_name);
|
|
440
443
|
}
|
|
441
444
|
|
|
442
445
|
while (is_consuming_rows) {
|
|
@@ -464,9 +467,9 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
|
|
|
464
467
|
case SQLITE_TEXT: {
|
|
465
468
|
string_value = reinterpret_cast<const char *>(
|
|
466
469
|
sqlite3_column_text(statement, current_column));
|
|
467
|
-
int
|
|
470
|
+
int len = sqlite3_column_bytes(statement, current_column);
|
|
468
471
|
// Specify length too; in case string contains NULL in the middle
|
|
469
|
-
row.emplace_back(std::string(string_value,
|
|
472
|
+
row.emplace_back(std::string(string_value, len));
|
|
470
473
|
break;
|
|
471
474
|
}
|
|
472
475
|
|
package/cpp/utils.cpp
CHANGED
|
@@ -13,7 +13,7 @@ namespace opsqlite {
|
|
|
13
13
|
|
|
14
14
|
namespace jsi = facebook::jsi;
|
|
15
15
|
|
|
16
|
-
jsi::Value toJSI(jsi::Runtime &rt, JSVariant value) {
|
|
16
|
+
jsi::Value toJSI(jsi::Runtime &rt, const JSVariant &value) {
|
|
17
17
|
if (std::holds_alternative<bool>(value)) {
|
|
18
18
|
return std::get<bool>(value);
|
|
19
19
|
} else if (std::holds_alternative<int>(value)) {
|
|
@@ -158,7 +158,7 @@ std::vector<JSVariant> to_variant_vec(jsi::Runtime &rt, jsi::Value const &xs) {
|
|
|
158
158
|
return res;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
jsi::Value create_js_rows(jsi::Runtime &rt, BridgeResult status) {
|
|
161
|
+
jsi::Value create_js_rows(jsi::Runtime &rt, const BridgeResult &status) {
|
|
162
162
|
if (status.type == SQLiteError) {
|
|
163
163
|
throw std::invalid_argument(status.message);
|
|
164
164
|
}
|
|
@@ -181,10 +181,10 @@ jsi::Value create_js_rows(jsi::Runtime &rt, BridgeResult status) {
|
|
|
181
181
|
auto value = toJSI(rt, native_row[j]);
|
|
182
182
|
row.setValueAtIndex(rt, j, value);
|
|
183
183
|
}
|
|
184
|
-
rows.setValueAtIndex(rt, i,
|
|
184
|
+
rows.setValueAtIndex(rt, i, row);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
res.setProperty(rt, "rawRows",
|
|
187
|
+
res.setProperty(rt, "rawRows", rows);
|
|
188
188
|
|
|
189
189
|
size_t column_count = status.column_names.size();
|
|
190
190
|
auto column_array = jsi::Array(rt, column_count);
|
package/cpp/utils.h
CHANGED
|
@@ -15,7 +15,7 @@ namespace opsqlite {
|
|
|
15
15
|
|
|
16
16
|
namespace jsi = facebook::jsi;
|
|
17
17
|
|
|
18
|
-
jsi::Value toJSI(jsi::Runtime &rt, JSVariant value);
|
|
18
|
+
jsi::Value toJSI(jsi::Runtime &rt, const JSVariant &value);
|
|
19
19
|
JSVariant toVariant(jsi::Runtime &rt, jsi::Value const &value);
|
|
20
20
|
std::vector<std::string> to_string_vec(jsi::Runtime &rt, jsi::Value const &xs);
|
|
21
21
|
std::vector<JSVariant> to_variant_vec(jsi::Runtime &rt, jsi::Value const &xs);
|
|
@@ -23,7 +23,7 @@ std::vector<int> to_int_vec(jsi::Runtime &rt, jsi::Value const &xs);
|
|
|
23
23
|
jsi::Value createResult(jsi::Runtime &rt, BridgeResult status,
|
|
24
24
|
std::vector<DumbHostObject> *results,
|
|
25
25
|
std::shared_ptr<std::vector<SmartHostObject>> metadata);
|
|
26
|
-
jsi::Value create_js_rows(jsi::Runtime &rt, BridgeResult status);
|
|
26
|
+
jsi::Value create_js_rows(jsi::Runtime &rt, const BridgeResult &status);
|
|
27
27
|
jsi::Value
|
|
28
28
|
create_raw_result(jsi::Runtime &rt, BridgeResult status,
|
|
29
29
|
const std::vector<std::vector<JSVariant>> *results);
|