@op-engineering/op-sqlite 1.0.1 → 1.0.2

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 CHANGED
@@ -37,7 +37,7 @@ You can find the [benchmarking code in the example app](https://github.com/OP-En
37
37
  | ------------ | ------------- | ---------- |
38
38
  | quick-sqlite | 2719 | 8851 |
39
39
  | expo-sqlite | 2293 | 10626 |
40
- | op-sqlite | 634 | 1548 |
40
+ | op-sqlite | 488 | 981 |
41
41
 
42
42
  Memory consumption is also 50% to 80% reduced compared to `react-native-quick-sqlite`. `expo-sqlite` OOMS itself even when trying to insert 300k elements in a row. Queries that before might have OOM now can run just fine.
43
43
 
@@ -19,12 +19,14 @@ std::vector<jsi::PropNameID> DynamicHostObject::getPropertyNames(jsi::Runtime &r
19
19
  jsi::Value DynamicHostObject::get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) {
20
20
  auto name = propNameID.utf8(rt);
21
21
 
22
- if(fields.find(name) == fields.end()) {
23
- return {};
24
- } else {
25
- jsVal val = fields[name];
26
- return toJSI(rt, val);
22
+ for (auto field: fields) {
23
+ auto fieldName = field.first;
24
+ if(fieldName == name) {
25
+ return toJSI(rt, field.second);
26
+ }
27
27
  }
28
+
29
+ return {};
28
30
  }
29
31
 
30
32
  }
@@ -4,7 +4,6 @@
4
4
  #include <jsi/jsi.h>
5
5
  #include <any>
6
6
  #include <vector>
7
- #include <unordered_map>
8
7
  #include "types.h"
9
8
 
10
9
  namespace osp {
@@ -21,7 +20,8 @@ namespace osp {
21
20
 
22
21
  jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
23
22
 
24
- std::unordered_map<std::string, jsVal> fields;
23
+
24
+ std::vector<std::pair<std::string, jsVal>> fields;
25
25
  };
26
26
 
27
27
  }
package/cpp/bridge.cpp CHANGED
@@ -5,7 +5,7 @@
5
5
  #include <ctime>
6
6
  #include <unistd.h>
7
7
  #include <sys/stat.h>
8
- #include <map>
8
+ #include <unordered_map>
9
9
  #include "logs.h"
10
10
  #include "DynamicHostObject.h"
11
11
  #include <variant>
@@ -316,14 +316,14 @@ BridgeResult sqliteExecute(std::string const dbName,
316
316
  * only represent Integers up to 53 bits
317
317
  */
318
318
  double column_value = sqlite3_column_double(statement, i);
319
- row->fields[column_name] = jsVal(column_value);
319
+ row->fields.push_back(std::make_pair(column_name, jsVal(column_value)));
320
320
  break;
321
321
  }
322
322
 
323
323
  case SQLITE_FLOAT:
324
324
  {
325
325
  double column_value = sqlite3_column_double(statement, i);
326
- row->fields[column_name] = jsVal(column_value);
326
+ row->fields.push_back(std::make_pair(column_name, jsVal(column_value)));
327
327
  break;
328
328
  }
329
329
 
@@ -332,7 +332,7 @@ BridgeResult sqliteExecute(std::string const dbName,
332
332
  const char *column_value = reinterpret_cast<const char *>(sqlite3_column_text(statement, i));
333
333
  int byteLen = sqlite3_column_bytes(statement, i);
334
334
  // Specify length too; in case string contains NULL in the middle (which SQLite supports!)
335
- row->fields[column_name] = jsVal(std::string(column_value, byteLen));
335
+ row->fields.push_back(std::make_pair(column_name, jsVal(std::string(column_value, byteLen))));
336
336
  break;
337
337
  }
338
338
 
@@ -342,10 +342,10 @@ BridgeResult sqliteExecute(std::string const dbName,
342
342
  const void *blob = sqlite3_column_blob(statement, i);
343
343
  uint8_t *data = new uint8_t[blob_size];
344
344
  memcpy(data, blob, blob_size);
345
- row->fields[column_name] = jsVal(JSBuffer {
345
+ row->fields.push_back(std::make_pair(column_name, jsVal(JSBuffer {
346
346
  .data = std::shared_ptr<uint8_t>{data},
347
347
  .size = static_cast<size_t>(blob_size)
348
- });
348
+ })));
349
349
  break;
350
350
  }
351
351
 
@@ -353,7 +353,7 @@ BridgeResult sqliteExecute(std::string const dbName,
353
353
  // Intentionally left blank
354
354
 
355
355
  default:
356
- row->fields[column_name] = jsVal(NULL);
356
+ row->fields.push_back(std::make_pair(column_name, jsVal(NULL)));
357
357
  break;
358
358
  }
359
359
  i++;
@@ -371,9 +371,9 @@ BridgeResult sqliteExecute(std::string const dbName,
371
371
  column_name = sqlite3_column_name(statement, i);
372
372
  const char *type = sqlite3_column_decltype(statement, i);
373
373
  auto metadata = std::make_shared<DynamicHostObject>();
374
- metadata->fields["name"] = column_name;
375
- metadata->fields["index"] = i;
376
- metadata->fields["type"] = type;
374
+ metadata->fields.push_back(std::make_pair("name", column_name));
375
+ metadata->fields.push_back(std::make_pair("index", i));
376
+ metadata->fields.push_back(std::make_pair("type", type));
377
377
 
378
378
  i++;
379
379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",