@op-engineering/op-sqlite 1.0.4 → 1.0.5

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
@@ -16,10 +16,6 @@ Created by [@ospfranco](https://twitter.com/ospfranco). Also created `react-nati
16
16
 
17
17
  **Please consider Sponsoring**, none of this work is for free. I pay for it with my time and knowledge. If you are a company in need of help with your React Native/React apps feel free to reach out. I also do a lot of C++ and nowadays Rust.
18
18
 
19
- ## Known issues
20
-
21
- [ArrayBuffer support is commented out right now](https://github.com/OP-Engineering/op-sqlite/blob/main/cpp/bridge.cpp#L247). I will get to it in the next days or feel free to submit a PR.
22
-
23
19
  ## Coming up
24
20
 
25
21
  I will gladly review bug fixes, but in order for me to continue support and add new features, I ask you to sponsor me. Some of the things that can still be done to make this package faster and more complete:
@@ -35,9 +31,9 @@ You can find the [benchmarking code in the example app](https://github.com/OP-En
35
31
 
36
32
  | Library | iPhone 15 Pro | Galaxy S22 |
37
33
  | ------------ | ------------- | ---------- |
38
- | quick-sqlite | 2719 | 8851 |
39
- | expo-sqlite | 2293 | 10626 |
40
- | op-sqlite | 507 | 1125 |
34
+ | quick-sqlite | 2719ms | 8851ms |
35
+ | expo-sqlite | 2293ms | 10626ms |
36
+ | op-sqlite | 507ms | 1125ms |
41
37
 
42
38
  Memory consumption is also is also 1/4 compared to `react-native-quick-sqlite`. This query used to take 1.2gb of peak memory usage, now runs in 250mbs.
43
39
 
@@ -100,7 +96,7 @@ db = {
100
96
 
101
97
  The basic query is **synchronous**, it will block rendering on large operations, further below you will find async versions.
102
98
 
103
- ```typescript
99
+ ```ts
104
100
  import { open } from '@op-engineering/op-sqlite';
105
101
 
106
102
  try {
@@ -108,7 +104,8 @@ try {
108
104
 
109
105
  let { rows } = db.execute('SELECT somevalue FROM sometable');
110
106
 
111
- rows.forEach((row) => {
107
+ // _array internally holds the values, this is meant to comply with the webSQL spec
108
+ rows._array.forEach((row) => {
112
109
  console.log(row);
113
110
  });
114
111
 
@@ -123,6 +120,30 @@ try {
123
120
  }
124
121
  ```
125
122
 
123
+ ### Multiple statements in a single string
124
+
125
+ You can execute multiple statements in a single operation. The API however is not really thought for this use case and the results (and their metadata) will be mangled, so you can discard it.
126
+
127
+ ```ts
128
+ // The result of this query will all be in a single array, no point in trying to read it
129
+ db.execute(
130
+ `CREATE TABLE T1 ( id INT PRIMARY KEY) STRICT;
131
+ CREATE TABLE T2 ( id INT PRIMARY KEY) STRICT;`
132
+ );
133
+
134
+ let t1name = db.execute(
135
+ "SELECT name FROM sqlite_master WHERE type='table' AND name='T1';"
136
+ );
137
+
138
+ console.log(t1name.rows?._array[0].name); // outputs "T1"
139
+
140
+ let t2name = db.execute(
141
+ "SELECT name FROM sqlite_master WHERE type='table' AND name='T2';"
142
+ );
143
+
144
+ console.log(t2name.rows?._array[0].name); // outputs "T2"
145
+ ```
146
+
126
147
  ### Transactions
127
148
 
128
149
  Throwing an error inside the callback will ROLLBACK the transaction.
@@ -199,7 +220,7 @@ db.executeAsync(
199
220
  'myDatabase',
200
221
  'SELECT * FROM "User";',
201
222
  []).then(({rows}) => {
202
- console.log('users', rows);
223
+ console.log('users', rows._array);
203
224
  })
204
225
  );
205
226
  ```
@@ -281,7 +302,7 @@ For example, you could add `SQLITE_ENABLE_FTS5=1` to `GCC_PREPROCESSOR_DEFINITIO
281
302
  You can specify flags via `<PROJECT_ROOT>/android/gradle.properties` like so:
282
303
 
283
304
  ```
284
- quickSqliteFlags="-DSQLITE_ENABLE_FTS5=1"
305
+ OPSQLiteFlags="-DSQLITE_ENABLE_FTS5=1"
285
306
  ```
286
307
 
287
308
  ## Additional configuration
@@ -29,11 +29,11 @@ private:
29
29
  auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
30
30
  std::string docPathString = docPath->toStdString();
31
31
 
32
- osp::install(*jsiRuntime, jsCallInvoker, docPathString.c_str());
32
+ opsqlite::install(*jsiRuntime, jsCallInvoker, docPathString.c_str());
33
33
  }
34
34
 
35
35
  static void clearStateNativeJsi(jni::alias_ref<jni::JObject> thiz) {
36
- osp::clearState();
36
+ opsqlite::clearState();
37
37
  }
38
38
  };
39
39
 
@@ -2,7 +2,7 @@
2
2
  #include "utils.h"
3
3
  #include <iostream>
4
4
 
5
- namespace osp {
5
+ namespace opsqlite {
6
6
 
7
7
  namespace jsi = facebook::jsi;
8
8
 
@@ -9,7 +9,7 @@
9
9
  #include "types.h"
10
10
  #include "DynamicHostObject.h"
11
11
 
12
- namespace osp {
12
+ namespace opsqlite {
13
13
 
14
14
  namespace jsi = facebook::jsi;
15
15
 
@@ -23,7 +23,7 @@ namespace osp {
23
23
 
24
24
  jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
25
25
 
26
- std::vector<jsVal> values;
26
+ std::vector<JSVariant> values;
27
27
 
28
28
  std::shared_ptr<std::vector<DynamicHostObject>> metadata;
29
29
  };
@@ -2,7 +2,7 @@
2
2
  #include "utils.h"
3
3
  #include <iostream>
4
4
 
5
- namespace osp {
5
+ namespace opsqlite {
6
6
 
7
7
  namespace jsi = facebook::jsi;
8
8
 
@@ -6,7 +6,7 @@
6
6
  #include <vector>
7
7
  #include "types.h"
8
8
 
9
- namespace osp {
9
+ namespace opsqlite {
10
10
 
11
11
  namespace jsi = facebook::jsi;
12
12
 
@@ -18,7 +18,7 @@ namespace osp {
18
18
 
19
19
  jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
20
20
 
21
- std::vector<std::pair<std::string, jsVal>> fields;
21
+ std::vector<std::pair<std::string, JSVariant>> fields;
22
22
  };
23
23
 
24
24
  }
@@ -1,6 +1,6 @@
1
1
  #include "ThreadPool.h"
2
2
 
3
- namespace osp {
3
+ namespace opsqlite {
4
4
 
5
5
  ThreadPool::ThreadPool() : done(false)
6
6
  {
package/cpp/ThreadPool.h CHANGED
@@ -9,7 +9,7 @@
9
9
  #include <thread>
10
10
  #include <vector>
11
11
 
12
- namespace osp {
12
+ namespace opsqlite {
13
13
 
14
14
  class ThreadPool {
15
15
  public:
package/cpp/bindings.cpp CHANGED
@@ -10,7 +10,7 @@
10
10
  #include <iostream>
11
11
  #include "DumbHostObject.h"
12
12
 
13
- namespace osp {
13
+ namespace opsqlite {
14
14
 
15
15
  namespace jsi = facebook::jsi;
16
16
 
@@ -192,7 +192,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
192
192
  {
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
- std::vector<jsVal> params;
195
+ std::vector<JSVariant> params;
196
196
  if(count == 3) {
197
197
  const jsi::Value &originalParams = args[2];
198
198
  params = toAnyVec(rt, originalParams);
@@ -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<jsVal> params = toAnyVec(rt, originalParams);
229
+ std::vector<JSVariant> params = toAnyVec(rt, originalParams);
230
230
 
231
231
  auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
232
232
  auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor", 2) {
@@ -234,7 +234,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
234
234
  auto reject = std::make_shared<jsi::Value>(rt, args[1]);
235
235
 
236
236
  auto task =
237
- [&rt, dbName, query, params = std::make_shared<std::vector<jsVal>>(params), resolve, reject]()
237
+ [&rt, dbName, query, params = std::make_shared<std::vector<JSVariant>>(params), resolve, reject]()
238
238
  {
239
239
  try
240
240
  {
package/cpp/bindings.h CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  using namespace facebook;
6
6
 
7
- namespace osp {
7
+ namespace opsqlite {
8
8
 
9
9
  void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker, const char *docPath);
10
10
  void clearState();
package/cpp/bridge.cpp CHANGED
@@ -11,7 +11,7 @@
11
11
  #include "DumbHostObject.h"
12
12
  #include <variant>
13
13
 
14
- namespace osp {
14
+ namespace opsqlite {
15
15
 
16
16
  std::unordered_map<std::string, sqlite3 *> dbMap = std::unordered_map<std::string, sqlite3 *>();
17
17
 
@@ -201,14 +201,14 @@ BridgeResult sqliteRemoveDb(std::string const dbName, std::string const docPath)
201
201
  };
202
202
  }
203
203
 
204
- inline void bindStatement(sqlite3_stmt *statement, std::vector<jsVal> *values)
204
+ inline void bindStatement(sqlite3_stmt *statement, std::vector<JSVariant> *values)
205
205
  {
206
206
  size_t size = values->size();
207
207
 
208
208
  for (int ii = 0; ii < size; ii++)
209
209
  {
210
210
  int sqIndex = ii + 1;
211
- jsVal value = values->at(ii);
211
+ JSVariant value = values->at(ii);
212
212
 
213
213
  if (std::holds_alternative<bool>(value))
214
214
  {
@@ -231,24 +231,19 @@ inline void bindStatement(sqlite3_stmt *statement, std::vector<jsVal> *values)
231
231
  std::string str = std::get<std::string>(value);
232
232
  sqlite3_bind_text(statement, sqIndex, str.c_str(), str.length(), SQLITE_TRANSIENT);
233
233
  }
234
- else if(std::holds_alternative<JSBuffer>(value))
234
+ else if(std::holds_alternative<ArrayBuffer>(value))
235
235
  {
236
- JSBuffer buffer = std::get<JSBuffer>(value);
236
+ ArrayBuffer buffer = std::get<ArrayBuffer>(value);
237
237
  sqlite3_bind_blob(statement, sqIndex, buffer.data.get(), buffer.size, SQLITE_STATIC);
238
238
  } else {
239
239
  sqlite3_bind_null(statement, sqIndex);
240
240
  }
241
- // else if (value.type() == typeid(const char*))
242
- // {
243
- // sqlite3_bind_text(statement, sqIndex, str.c_str(), str.length(), SQLITE_TRANSIENT);
244
- // return jsi::String::createFromAscii(rt, std::any_cast<const char*>(value));
245
- // }
246
241
  }
247
242
  }
248
243
 
249
244
  BridgeResult sqliteExecute(std::string const dbName,
250
245
  std::string const &query,
251
- std::vector<jsVal> *params,
246
+ std::vector<JSVariant> *params,
252
247
  std::vector<DumbHostObject> *results,
253
248
  std::shared_ptr<std::vector<DynamicHostObject>> metadatas)
254
249
  {
@@ -257,146 +252,151 @@ BridgeResult sqliteExecute(std::string const dbName,
257
252
  {
258
253
  return {
259
254
  .type = SQLiteError,
260
- .message = "[op-sqlite]: Database " + dbName + " is not open",
261
- .affectedRows = 0
255
+ .message = "[op-sqlite]: Database " + dbName + " is not open"
262
256
  };
263
257
  }
264
258
 
265
259
  sqlite3 *db = dbMap[dbName];
266
260
 
267
261
  sqlite3_stmt *statement;
268
-
269
- int statementStatus = sqlite3_prepare_v2(db, query.c_str(), -1, &statement, NULL);
270
-
271
- if (statementStatus == SQLITE_ERROR)
272
- {
273
- const char *message = sqlite3_errmsg(db);
274
- return {
275
- .type = SQLiteError,
276
- .message = "[op-sqlite] SQL execution error: " + std::string(message),
277
- .affectedRows = 0};
278
- }
279
-
280
- bindStatement(statement, params);
262
+ const char *remainingStatement = nullptr;
281
263
 
282
264
  bool isConsuming = true;
283
265
  bool isFailed = false;
284
266
 
285
- int result, i, count, column_type;
286
- std::string column_name, column_declared_type;
287
-
288
- while (isConsuming)
289
- {
290
- result = sqlite3_step(statement);
267
+ do {
268
+ const char *queryStr = remainingStatement == nullptr ? query.c_str() : remainingStatement;
291
269
 
292
- switch (result)
270
+ int statementStatus = sqlite3_prepare_v2(db, queryStr, -1, &statement, &remainingStatement);
271
+
272
+ if (statementStatus == SQLITE_ERROR)
293
273
  {
294
- case SQLITE_ROW: {
295
- if(results == NULL)
296
- {
297
- break;
298
- }
299
-
300
- i = 0;
301
- DumbHostObject row = DumbHostObject(metadatas);
302
-
303
- count = sqlite3_column_count(statement);
304
-
305
- while (i < count)
306
- {
307
- column_type = sqlite3_column_type(statement, i);
274
+ const char *message = sqlite3_errmsg(db);
275
+ return {
276
+ .type = SQLiteError,
277
+ .message = "[op-sqlite] SQL execution error: " + std::string(message),
278
+ };
279
+ }
280
+
281
+ bindStatement(statement, params);
282
+
283
+ isConsuming = true;
284
+
285
+ int result, i, count, column_type;
286
+ std::string column_name, column_declared_type;
287
+
288
+ while (isConsuming)
289
+ {
290
+ result = sqlite3_step(statement);
291
+
292
+ switch (result)
293
+ {
294
+ case SQLITE_ROW: {
295
+ if(results == NULL)
296
+ {
297
+ break;
298
+ }
299
+
300
+ i = 0;
301
+ DumbHostObject row = DumbHostObject(metadatas);
302
+
303
+ count = sqlite3_column_count(statement);
308
304
 
309
- switch (column_type)
305
+ while (i < count)
310
306
  {
311
- case SQLITE_INTEGER:
307
+ column_type = sqlite3_column_type(statement, i);
308
+
309
+ switch (column_type)
312
310
  {
313
- /**
314
- * Warning this will loose precision because JS can
315
- * only represent Integers up to 53 bits
316
- */
317
- double column_value = sqlite3_column_double(statement, i);
318
- row.values.push_back(jsVal(column_value));
319
- break;
311
+ case SQLITE_INTEGER:
312
+ {
313
+ /**
314
+ * Warning this will loose precision because JS can
315
+ * only represent Integers up to 53 bits
316
+ */
317
+ double column_value = sqlite3_column_double(statement, i);
318
+ row.values.push_back(JSVariant(column_value));
319
+ break;
320
+ }
321
+
322
+ case SQLITE_FLOAT:
323
+ {
324
+ double column_value = sqlite3_column_double(statement, i);
325
+ row.values.push_back(JSVariant(column_value));
326
+ break;
327
+ }
328
+
329
+ case SQLITE_TEXT:
330
+ {
331
+ const char *column_value = reinterpret_cast<const char *>(sqlite3_column_text(statement, i));
332
+ int byteLen = sqlite3_column_bytes(statement, i);
333
+ // Specify length too; in case string contains NULL in the middle (which SQLite supports!)
334
+ row.values.push_back(JSVariant(std::string(column_value, byteLen)));
335
+ break;
336
+ }
337
+
338
+ case SQLITE_BLOB:
339
+ {
340
+ int blob_size = sqlite3_column_bytes(statement, i);
341
+ const void *blob = sqlite3_column_blob(statement, i);
342
+ uint8_t *data = new uint8_t[blob_size];
343
+ memcpy(data, blob, blob_size);
344
+ row.values.push_back(JSVariant(ArrayBuffer {
345
+ .data = std::shared_ptr<uint8_t>{data},
346
+ .size = static_cast<size_t>(blob_size)
347
+ }));
348
+ break;
349
+ }
350
+
351
+ case SQLITE_NULL:
352
+ // Intentionally left blank
353
+
354
+ default:
355
+ row.values.push_back(JSVariant(NULL));
356
+ break;
320
357
  }
321
-
322
- case SQLITE_FLOAT:
323
- {
324
- double column_value = sqlite3_column_double(statement, i);
325
- row.values.push_back(jsVal(column_value));
326
- break;
327
- }
328
-
329
- case SQLITE_TEXT:
330
- {
331
- const char *column_value = reinterpret_cast<const char *>(sqlite3_column_text(statement, i));
332
- int byteLen = sqlite3_column_bytes(statement, i);
333
- // Specify length too; in case string contains NULL in the middle (which SQLite supports!)
334
- row.values.push_back(jsVal(std::string(column_value, byteLen)));
335
- break;
336
- }
337
-
338
- case SQLITE_BLOB:
339
- {
340
- int blob_size = sqlite3_column_bytes(statement, i);
341
- const void *blob = sqlite3_column_blob(statement, i);
342
- uint8_t *data = new uint8_t[blob_size];
343
- memcpy(data, blob, blob_size);
344
- row.values.push_back(jsVal(JSBuffer {
345
- .data = std::shared_ptr<uint8_t>{data},
346
- .size = static_cast<size_t>(blob_size)
347
- }));
348
- break;
349
- }
350
-
351
- case SQLITE_NULL:
352
- // Intentionally left blank
353
-
354
- default:
355
- row.values.push_back(jsVal(NULL));
356
- break;
358
+ i++;
357
359
  }
358
- i++;
360
+ results->push_back(row);
361
+ break;
359
362
  }
360
- results->push_back(row);
361
- break;
362
- }
363
-
364
- case SQLITE_DONE:
365
- i = 0;
366
- count = sqlite3_column_count(statement);
367
-
368
- while (i < count)
369
- {
370
- column_name = sqlite3_column_name(statement, i);
371
- const char *type = sqlite3_column_decltype(statement, i);
372
- auto metadata = DynamicHostObject();
373
- metadata.fields.push_back(std::make_pair("name", column_name));
374
- metadata.fields.push_back(std::make_pair("index", i));
375
- metadata.fields.push_back(std::make_pair("type", type));
376
363
 
377
- metadatas->push_back(metadata);
378
- i++;
379
- }
380
-
381
- isConsuming = false;
382
- break;
383
-
384
- default:
385
- isFailed = true;
386
- isConsuming = false;
364
+ case SQLITE_DONE:
365
+ i = 0;
366
+ count = sqlite3_column_count(statement);
367
+
368
+ while (i < count)
369
+ {
370
+ column_name = sqlite3_column_name(statement, i);
371
+ const char *type = sqlite3_column_decltype(statement, i);
372
+ auto metadata = DynamicHostObject();
373
+ metadata.fields.push_back(std::make_pair("name", column_name));
374
+ metadata.fields.push_back(std::make_pair("index", i));
375
+ metadata.fields.push_back(std::make_pair("type", type));
376
+
377
+ metadatas->push_back(metadata);
378
+ i++;
379
+ }
380
+
381
+ isConsuming = false;
382
+ break;
383
+
384
+ default:
385
+ isFailed = true;
386
+ isConsuming = false;
387
+ }
387
388
  }
388
- }
389
+
390
+ sqlite3_finalize(statement);
391
+ } while (strcmp(remainingStatement, "") != 0 && !isFailed);
389
392
 
390
- sqlite3_finalize(statement);
391
393
 
392
394
  if (isFailed)
393
395
  {
394
396
  const char *message = sqlite3_errmsg(db);
395
397
  return {
396
398
  .type = SQLiteError,
397
- .message = "[op-sqlite] SQL execution error: " + std::string(message),
398
- .affectedRows = 0,
399
- .insertId = 0
399
+ .message = "[op-sqlite] SQL execution error: " + std::string(message)
400
400
  };
401
401
  }
402
402
 
package/cpp/bridge.h CHANGED
@@ -7,7 +7,7 @@
7
7
  #include "DumbHostObject.h"
8
8
  #include "types.h"
9
9
 
10
- namespace osp {
10
+ namespace opsqlite {
11
11
 
12
12
  namespace jsi = facebook::jsi;
13
13
 
@@ -23,7 +23,7 @@ BridgeResult sqliteDetachDb(std::string const mainDBName, std::string const alia
23
23
 
24
24
  BridgeResult sqliteExecute(std::string const dbName,
25
25
  std::string const &query,
26
- std::vector<jsVal> *values,
26
+ std::vector<JSVariant> *values,
27
27
  std::vector<DumbHostObject> *results,
28
28
  std::shared_ptr<std::vector<DynamicHostObject>> metadatas);
29
29
 
@@ -1,6 +1,6 @@
1
1
  #include "sqlbatchexecutor.h"
2
2
 
3
- namespace osp {
3
+ namespace opsqlite {
4
4
 
5
5
  /**
6
6
  * Batch execution implementation
@@ -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<jsVal>>(toAnyVec(rt, p));
28
+ auto params = std::make_shared<std::vector<JSVariant>>(toAnyVec(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<jsVal>>(toAnyVec(rt, commandParams));
37
+ auto params = std::make_shared<std::vector<JSVariant>>(toAnyVec(rt, commandParams));
38
38
  commands->push_back({
39
39
  query,
40
40
  params
@@ -5,13 +5,13 @@
5
5
  #include "bridge.h"
6
6
  #include "types.h"
7
7
 
8
- namespace osp {
8
+ namespace opsqlite {
9
9
 
10
10
  namespace jsi = facebook::jsi;
11
11
 
12
12
  struct BatchArguments {
13
13
  std::string sql;
14
- std::shared_ptr<std::vector<jsVal>> params;
14
+ std::shared_ptr<std::vector<JSVariant>> params;
15
15
  };
16
16
 
17
17
  /**
package/cpp/types.h CHANGED
@@ -1,14 +1,14 @@
1
- #ifndef jsVal_h
2
- #define jsVal_h
1
+ #ifndef types_h
2
+ #define types_h
3
3
 
4
4
  #include <variant>
5
5
 
6
- struct JSBuffer {
6
+ struct ArrayBuffer {
7
7
  std::shared_ptr<uint8_t> data;
8
8
  size_t size;
9
9
  };
10
10
 
11
11
 
12
- using jsVal = std::variant<nullptr_t, bool, int, double, long, long long, std::string, JSBuffer>;
12
+ using JSVariant = std::variant<nullptr_t, bool, int, double, long, long long, std::string, ArrayBuffer>;
13
13
 
14
- #endif /* jsVal_h */
14
+ #endif /* types_h */
package/cpp/utils.cpp CHANGED
@@ -4,18 +4,18 @@
4
4
  #include <fstream>
5
5
  #include "bridge.h"
6
6
 
7
- namespace osp {
7
+ namespace opsqlite {
8
8
 
9
9
  namespace jsi = facebook::jsi;
10
10
 
11
- jsVal toAny(jsi::Runtime &rt, jsi::Value &value) {
11
+ JSVariant toAny(jsi::Runtime &rt, jsi::Value &value) {
12
12
  if (value.isNull() || value.isUndefined())
13
13
  {
14
- return jsVal(nullptr);
14
+ return JSVariant(nullptr);
15
15
  }
16
16
  else if (value.isBool())
17
17
  {
18
- return jsVal(value.getBool());
18
+ return JSVariant(value.getBool());
19
19
  }
20
20
  else if (value.isNumber())
21
21
  {
@@ -24,21 +24,21 @@ jsVal toAny(jsi::Runtime &rt, jsi::Value &value) {
24
24
  long long longVal = (long)doubleVal;
25
25
  if (intVal == doubleVal)
26
26
  {
27
- return jsVal(intVal);
27
+ return JSVariant(intVal);
28
28
  }
29
29
  else if (longVal == doubleVal)
30
30
  {
31
- return jsVal(longVal);
31
+ return JSVariant(longVal);
32
32
  }
33
33
  else
34
34
  {
35
- return jsVal(doubleVal);
35
+ return JSVariant(doubleVal);
36
36
  }
37
37
  }
38
38
  else if (value.isString())
39
39
  {
40
40
  std::string strVal = value.asString(rt).utf8(rt);
41
- return jsVal(strVal);
41
+ return JSVariant(strVal);
42
42
  }
43
43
  else if (value.isObject())
44
44
  {
@@ -46,7 +46,7 @@ jsVal toAny(jsi::Runtime &rt, jsi::Value &value) {
46
46
  if (object.isArrayBuffer(rt))
47
47
  {
48
48
  auto buffer = object.getArrayBuffer(rt);
49
- return jsVal(JSBuffer {
49
+ return JSVariant(ArrayBuffer {
50
50
  .data = std::shared_ptr<uint8_t>{buffer.data(rt)},
51
51
  .size = buffer.size(rt)
52
52
  });
@@ -56,7 +56,7 @@ jsVal toAny(jsi::Runtime &rt, jsi::Value &value) {
56
56
  throw new std::invalid_argument("Unknown JSI to any value conversion");
57
57
  }
58
58
 
59
- jsi::Value toJSI(jsi::Runtime &rt, jsVal value) {
59
+ jsi::Value toJSI(jsi::Runtime &rt, JSVariant value) {
60
60
 
61
61
  if (std::holds_alternative<bool>(value))
62
62
  {
@@ -82,9 +82,9 @@ jsi::Value toJSI(jsi::Runtime &rt, jsVal value) {
82
82
  // {
83
83
  // return jsi::String::createFromAscii(rt, std::get<const char*>(value));
84
84
  // }
85
- else if (std::holds_alternative<JSBuffer>(value))
85
+ else if (std::holds_alternative<ArrayBuffer>(value))
86
86
  {
87
- auto jsBuffer = std::get<JSBuffer>(value);
87
+ auto jsBuffer = std::get<ArrayBuffer>(value);
88
88
  jsi::Function array_buffer_ctor = rt.global().getPropertyAsFunction(rt, "ArrayBuffer");
89
89
  jsi::Object o = array_buffer_ctor.callAsConstructor(rt, (int)jsBuffer.size).getObject(rt);
90
90
  jsi::ArrayBuffer buf = o.getArrayBuffer(rt);
@@ -96,9 +96,9 @@ jsi::Value toJSI(jsi::Runtime &rt, jsVal value) {
96
96
  return jsi::Value::null();
97
97
  }
98
98
 
99
- std::vector<jsVal> toAnyVec(jsi::Runtime &rt, jsi::Value const &params)
99
+ std::vector<JSVariant> toAnyVec(jsi::Runtime &rt, jsi::Value const &params)
100
100
  {
101
- std::vector<jsVal> res;
101
+ std::vector<JSVariant> res;
102
102
 
103
103
  if (params.isNull() || params.isUndefined())
104
104
  {
package/cpp/utils.h CHANGED
@@ -11,46 +11,44 @@
11
11
  #include "DynamicHostObject.h"
12
12
  #include "DumbHostObject.h"
13
13
 
14
- namespace osp {
14
+ namespace opsqlite {
15
15
 
16
- namespace jsi = facebook::jsi;
16
+ namespace jsi = facebook::jsi;
17
17
 
18
+ enum ResultType
19
+ {
20
+ SQLiteOk,
21
+ SQLiteError
22
+ };
18
23
 
24
+ struct BridgeResult
25
+ {
26
+ ResultType type;
27
+ std::string message;
28
+ int affectedRows;
29
+ double insertId;
30
+ };
19
31
 
20
- enum ResultType
21
- {
22
- SQLiteOk,
23
- SQLiteError
24
- };
32
+ struct BatchResult
33
+ {
34
+ ResultType type;
35
+ std::string message;
36
+ int affectedRows;
37
+ int commands;
38
+ };
25
39
 
26
- struct BridgeResult
27
- {
28
- ResultType type;
29
- std::string message;
30
- int affectedRows;
31
- double insertId;
32
- };
40
+ JSVariant toAny(jsi::Runtime &rt, jsi::Value &value);
33
41
 
34
- struct BatchResult
35
- {
36
- ResultType type;
37
- std::string message;
38
- int affectedRows;
39
- int commands;
40
- };
42
+ jsi::Value toJSI(jsi::Runtime &rt, JSVariant value);
41
43
 
42
- jsVal toAny(jsi::Runtime &rt, jsi::Value &value);
44
+ std::vector<JSVariant> toAnyVec(jsi::Runtime &rt, jsi::Value const &args);
43
45
 
44
- jsi::Value toJSI(jsi::Runtime &rt, jsVal value);
46
+ jsi::Value createResult(jsi::Runtime &rt,
47
+ BridgeResult status,
48
+ std::vector<DumbHostObject> *results,
49
+ std::shared_ptr<std::vector<DynamicHostObject>> metadata);
45
50
 
46
- std::vector<jsVal> toAnyVec(jsi::Runtime &rt, jsi::Value const &args);
47
-
48
- jsi::Value createResult(jsi::Runtime &rt,
49
- BridgeResult status,
50
- std::vector<DumbHostObject> *results,
51
- std::shared_ptr<std::vector<DynamicHostObject>> metadata);
52
-
53
- BatchResult importSQLFile(std::string dbName, std::string fileLocation);
51
+ BatchResult importSQLFile(std::string dbName, std::string fileLocation);
54
52
 
55
53
  }
56
54
 
package/ios/OPSQLite.mm CHANGED
@@ -51,14 +51,14 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
51
51
  documentPath = [paths objectAtIndex:0];
52
52
  }
53
53
 
54
- osp::install(runtime, callInvoker, [documentPath UTF8String]);
54
+ opsqlite::install(runtime, callInvoker, [documentPath UTF8String]);
55
55
 
56
56
  NSLog(@"OP-SQLite initialized");
57
57
  return @true;
58
58
  }
59
59
 
60
60
  - (void)invalidate {
61
- osp::clearState();
61
+ opsqlite::clearState();
62
62
  }
63
63
 
64
64
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",