@op-engineering/op-sqlite 1.0.2 → 1.0.4

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,9 +37,9 @@ 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 | 488 | 981 |
40
+ | op-sqlite | 507 | 1125 |
41
41
 
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.
42
+ 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
43
 
44
44
  # DB Paths
45
45
 
@@ -48,6 +48,8 @@ The library creates/opens databases by appending the passed name plus, the [libr
48
48
  If you have an existing database file you want to load you can navigate from these directories using dot notation. e.g.:
49
49
 
50
50
  ```ts
51
+ import { open } from '@op-engineering/op-sqlite';
52
+
51
53
  const largeDb = open({
52
54
  name: 'largeDB',
53
55
  location: '../files/databases',
@@ -56,7 +58,20 @@ const largeDb = open({
56
58
 
57
59
  Note that on iOS the file system is sand-boxed, so you cannot access files/directories outside your app bundle directories.
58
60
 
59
- ## API
61
+ ## In memory
62
+
63
+ Using SQLite in memory mode is supported:
64
+
65
+ ```ts
66
+ import { open } from '@op-engineering/op-sqlite';
67
+
68
+ const largeDb = open({
69
+ name: 'inMemoryDb',
70
+ inMemory: true,
71
+ });
72
+ ```
73
+
74
+ # API
60
75
 
61
76
  ```typescript
62
77
  import {open} from '@op-engineering/op-sqlite'
@@ -89,7 +104,7 @@ The basic query is **synchronous**, it will block rendering on large operations,
89
104
  import { open } from '@op-engineering/op-sqlite';
90
105
 
91
106
  try {
92
- const db = open('myDb.sqlite');
107
+ const db = open({ name: 'myDb.sqlite' });
93
108
 
94
109
  let { rows } = db.execute('SELECT somevalue FROM sometable');
95
110
 
@@ -31,6 +31,8 @@ add_library(
31
31
  ../cpp/sqlbatchexecutor.cpp
32
32
  ../cpp/DynamicHostObject.cpp
33
33
  ../cpp/DynamicHostObject.h
34
+ ../cpp/DumbHostObject.cpp
35
+ ../cpp/DumbHostObject.h
34
36
  ../cpp/macros.h
35
37
  ../cpp/types.h
36
38
  cpp-adapter.cpp
@@ -0,0 +1,37 @@
1
+ #include "DumbHostObject.h"
2
+ #include "utils.h"
3
+ #include <iostream>
4
+
5
+ namespace osp {
6
+
7
+ namespace jsi = facebook::jsi;
8
+
9
+ DumbHostObject::DumbHostObject(std::shared_ptr<std::vector<DynamicHostObject>> metadata) {
10
+ this->metadata = metadata;
11
+ };
12
+
13
+ std::vector<jsi::PropNameID> DumbHostObject::getPropertyNames(jsi::Runtime &rt) {
14
+ std::vector<jsi::PropNameID> keys;
15
+
16
+ for (auto field : *metadata) {
17
+ // TODO improve this by generating the propName once on metadata creation
18
+ keys.push_back(jsi::PropNameID::forAscii(rt, std::get<std::string>(field.fields[0].second)));
19
+ }
20
+
21
+ return keys;
22
+ }
23
+
24
+ jsi::Value DumbHostObject::get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) {
25
+ auto name = propNameID.utf8(rt);
26
+ auto fields = metadata.get();
27
+ for(int i = 0; i < fields->size(); i++) {
28
+ auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
29
+ if(fieldName == name) {
30
+ return toJSI(rt, values.at(i));
31
+ }
32
+ }
33
+
34
+ return {};
35
+ }
36
+
37
+ }
@@ -0,0 +1,33 @@
1
+ #ifndef DumbHostObject_h
2
+ #define DumbHostObject_h
3
+
4
+ #include <stdio.h>
5
+
6
+ #include <jsi/jsi.h>
7
+ #include <any>
8
+ #include <vector>
9
+ #include "types.h"
10
+ #include "DynamicHostObject.h"
11
+
12
+ namespace osp {
13
+
14
+ namespace jsi = facebook::jsi;
15
+
16
+ class JSI_EXPORT DumbHostObject: public jsi::HostObject {
17
+ public:
18
+ DumbHostObject() {};
19
+
20
+ DumbHostObject(std::shared_ptr<std::vector<DynamicHostObject>> metadata);
21
+
22
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
23
+
24
+ jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
25
+
26
+ std::vector<jsVal> values;
27
+
28
+ std::shared_ptr<std::vector<DynamicHostObject>> metadata;
29
+ };
30
+
31
+ }
32
+
33
+ #endif /* DumbHostObject_h */
@@ -14,13 +14,10 @@ namespace osp {
14
14
  public:
15
15
  DynamicHostObject() {};
16
16
 
17
- virtual ~DynamicHostObject() {};
18
-
19
17
  std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
20
18
 
21
19
  jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
22
20
 
23
-
24
21
  std::vector<std::pair<std::string, jsVal>> fields;
25
22
  };
26
23
 
package/cpp/bindings.cpp CHANGED
@@ -8,6 +8,7 @@
8
8
  #include <string>
9
9
  #include "macros.h"
10
10
  #include <iostream>
11
+ #include "DumbHostObject.h"
11
12
 
12
13
  namespace osp {
13
14
 
@@ -27,7 +28,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
27
28
  pool = std::make_shared<ThreadPool>();
28
29
  invoker = jsCallInvoker;
29
30
 
30
- auto open = HOSTFN("open", 2) {
31
+ auto open = HOSTFN("open", 3) {
31
32
  if (count == 0)
32
33
  {
33
34
  throw jsi::JSError(rt, "[op-sqlite][open] database name is required");
@@ -40,6 +41,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
40
41
 
41
42
  std::string dbName = args[0].asString(rt).utf8(rt);
42
43
  std::string tempDocPath = std::string(basePath);
44
+ bool memoryStorage = false;
43
45
 
44
46
  if (count > 1 && !args[1].isUndefined() && !args[1].isNull())
45
47
  {
@@ -51,7 +53,15 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
51
53
  tempDocPath = tempDocPath + "/" + args[1].asString(rt).utf8(rt);
52
54
  }
53
55
 
54
- BridgeResult result = sqliteOpenDb(dbName, tempDocPath);
56
+ if(count == 3) {
57
+ if(!args[2].isBool()) {
58
+ throw jsi::JSError(rt, "[op-sqlite][open] memoryStorage must be a bool");
59
+ }
60
+
61
+ memoryStorage = args[2].asBool();
62
+ }
63
+
64
+ BridgeResult result = sqliteOpenDb(dbName, tempDocPath, memoryStorage);
55
65
 
56
66
  if (result.type == SQLiteError)
57
67
  {
@@ -188,17 +198,17 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
188
198
  params = toAnyVec(rt, originalParams);
189
199
  }
190
200
 
191
- std::vector<std::shared_ptr<DynamicHostObject>> results;
192
- std::vector<std::shared_ptr<DynamicHostObject>> metadata;
201
+ std::vector<DumbHostObject> results;
202
+ std::shared_ptr<std::vector<DynamicHostObject>> metadata = std::make_shared<std::vector<DynamicHostObject>>();
193
203
 
194
204
  try {
195
- auto status = sqliteExecute(dbName, query, &params, &results, &metadata);
205
+ auto status = sqliteExecute(dbName, query, &params, &results, metadata);
196
206
 
197
207
  if(status.type == SQLiteError) {
198
208
  throw jsi::JSError(rt, status.message);
199
209
  }
200
210
 
201
- auto jsiResult = createResult(rt, status, &results, &metadata);
211
+ auto jsiResult = createResult(rt, status, &results, metadata);
202
212
  return jsiResult;
203
213
  } catch(std::exception &e) {
204
214
  throw jsi::JSError(rt, e.what());
@@ -228,19 +238,19 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
228
238
  {
229
239
  try
230
240
  {
231
- std::vector<std::shared_ptr<DynamicHostObject>> results;
232
- std::vector<std::shared_ptr<DynamicHostObject>> metadata;
233
-
234
- auto status = sqliteExecute(dbName, query, params.get(), &results, &metadata);
241
+ std::vector<DumbHostObject> results;
242
+ std::shared_ptr<std::vector<DynamicHostObject>> metadata = std::make_shared<std::vector<DynamicHostObject>>();;
235
243
 
244
+ auto status = sqliteExecute(dbName, query, params.get(), &results, metadata);
245
+
236
246
  invoker->invokeAsync([&rt,
237
- results = std::make_shared<std::vector<std::shared_ptr<DynamicHostObject>>>(results),
238
- metadata = std::make_shared<std::vector<std::shared_ptr<DynamicHostObject>>>(metadata),
247
+ results = std::make_shared<std::vector<DumbHostObject>>(results),
248
+ metadata,
239
249
  status = std::move(status),
240
250
  resolve,
241
251
  reject] {
242
252
  if(status.type == SQLiteOk) {
243
- auto jsiResult = createResult(rt, status, results.get(), metadata.get());
253
+ auto jsiResult = createResult(rt, status, results.get(), metadata);
244
254
  resolve->asObject(rt).asFunction(rt).call(rt, std::move(jsiResult));
245
255
  } else {
246
256
  auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
package/cpp/bridge.cpp CHANGED
@@ -8,6 +8,7 @@
8
8
  #include <unordered_map>
9
9
  #include "logs.h"
10
10
  #include "DynamicHostObject.h"
11
+ #include "DumbHostObject.h"
11
12
  #include <variant>
12
13
 
13
14
  namespace osp {
@@ -72,9 +73,9 @@ std::string get_db_path(std::string const dbName, std::string const docPath)
72
73
  return docPath + "/" + dbName;
73
74
  }
74
75
 
75
- BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath)
76
+ BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath, bool memoryStorage)
76
77
  {
77
- std::string dbPath = get_db_path(dbName, docPath);
78
+ std::string dbPath = memoryStorage ? ":memory:" : get_db_path(dbName, docPath);
78
79
 
79
80
  int sqlOpenFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
80
81
 
@@ -208,7 +209,7 @@ inline void bindStatement(sqlite3_stmt *statement, std::vector<jsVal> *values)
208
209
  {
209
210
  int sqIndex = ii + 1;
210
211
  jsVal value = values->at(ii);
211
-
212
+
212
213
  if (std::holds_alternative<bool>(value))
213
214
  {
214
215
  sqlite3_bind_int(statement, sqIndex, std::get<bool>(value));
@@ -237,22 +238,22 @@ inline void bindStatement(sqlite3_stmt *statement, std::vector<jsVal> *values)
237
238
  } else {
238
239
  sqlite3_bind_null(statement, sqIndex);
239
240
  }
240
- // else if (value.type() == typeid(const char*))
241
- // {
242
- // sqlite3_bind_text(statement, sqIndex, str.c_str(), str.length(), SQLITE_TRANSIENT);
243
- // return jsi::String::createFromAscii(rt, std::any_cast<const char*>(value));
244
- // }
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
+ // }
245
246
  }
246
247
  }
247
248
 
248
249
  BridgeResult sqliteExecute(std::string const dbName,
249
- std::string const &query,
250
- std::vector<jsVal> *params,
251
- std::vector<std::shared_ptr<DynamicHostObject>> *results,
252
- std::vector<std::shared_ptr<DynamicHostObject>> *metadatas)
250
+ std::string const &query,
251
+ std::vector<jsVal> *params,
252
+ std::vector<DumbHostObject> *results,
253
+ std::shared_ptr<std::vector<DynamicHostObject>> metadatas)
253
254
  {
254
255
 
255
- if (dbMap.count(dbName) == 0)
256
+ if (dbMap.find(dbName) == dbMap.end())
256
257
  {
257
258
  return {
258
259
  .type = SQLiteError,
@@ -283,7 +284,6 @@ BridgeResult sqliteExecute(std::string const dbName,
283
284
 
284
285
  int result, i, count, column_type;
285
286
  std::string column_name, column_declared_type;
286
- std::shared_ptr<DynamicHostObject> row;
287
287
 
288
288
  while (isConsuming)
289
289
  {
@@ -291,24 +291,23 @@ BridgeResult sqliteExecute(std::string const dbName,
291
291
 
292
292
  switch (result)
293
293
  {
294
- case SQLITE_ROW:
294
+ case SQLITE_ROW: {
295
295
  if(results == NULL)
296
296
  {
297
297
  break;
298
298
  }
299
299
 
300
300
  i = 0;
301
- row = std::make_shared<DynamicHostObject>();
301
+ DumbHostObject row = DumbHostObject(metadatas);
302
+
302
303
  count = sqlite3_column_count(statement);
303
304
 
304
305
  while (i < count)
305
306
  {
306
307
  column_type = sqlite3_column_type(statement, i);
307
- column_name = sqlite3_column_name(statement, i);
308
308
 
309
309
  switch (column_type)
310
310
  {
311
-
312
311
  case SQLITE_INTEGER:
313
312
  {
314
313
  /**
@@ -316,14 +315,14 @@ BridgeResult sqliteExecute(std::string const dbName,
316
315
  * only represent Integers up to 53 bits
317
316
  */
318
317
  double column_value = sqlite3_column_double(statement, i);
319
- row->fields.push_back(std::make_pair(column_name, jsVal(column_value)));
318
+ row.values.push_back(jsVal(column_value));
320
319
  break;
321
320
  }
322
321
 
323
322
  case SQLITE_FLOAT:
324
323
  {
325
324
  double column_value = sqlite3_column_double(statement, i);
326
- row->fields.push_back(std::make_pair(column_name, jsVal(column_value)));
325
+ row.values.push_back(jsVal(column_value));
327
326
  break;
328
327
  }
329
328
 
@@ -332,7 +331,7 @@ BridgeResult sqliteExecute(std::string const dbName,
332
331
  const char *column_value = reinterpret_cast<const char *>(sqlite3_column_text(statement, i));
333
332
  int byteLen = sqlite3_column_bytes(statement, i);
334
333
  // Specify length too; in case string contains NULL in the middle (which SQLite supports!)
335
- row->fields.push_back(std::make_pair(column_name, jsVal(std::string(column_value, byteLen))));
334
+ row.values.push_back(jsVal(std::string(column_value, byteLen)));
336
335
  break;
337
336
  }
338
337
 
@@ -342,42 +341,43 @@ BridgeResult sqliteExecute(std::string const dbName,
342
341
  const void *blob = sqlite3_column_blob(statement, i);
343
342
  uint8_t *data = new uint8_t[blob_size];
344
343
  memcpy(data, blob, blob_size);
345
- row->fields.push_back(std::make_pair(column_name, jsVal(JSBuffer {
344
+ row.values.push_back(jsVal(JSBuffer {
346
345
  .data = std::shared_ptr<uint8_t>{data},
347
346
  .size = static_cast<size_t>(blob_size)
348
- })));
347
+ }));
349
348
  break;
350
349
  }
351
350
 
352
351
  case SQLITE_NULL:
353
352
  // Intentionally left blank
354
-
353
+
355
354
  default:
356
- row->fields.push_back(std::make_pair(column_name, jsVal(NULL)));
355
+ row.values.push_back(jsVal(NULL));
357
356
  break;
358
357
  }
359
358
  i++;
360
359
  }
361
360
  results->push_back(row);
362
361
  break;
363
-
362
+ }
363
+
364
364
  case SQLITE_DONE:
365
- if(metadatas != nullptr)
365
+ i = 0;
366
+ count = sqlite3_column_count(statement);
367
+
368
+ while (i < count)
366
369
  {
367
- i = 0;
368
- count = sqlite3_column_count(statement);
369
- while (i < count)
370
- {
371
- column_name = sqlite3_column_name(statement, i);
372
- const char *type = sqlite3_column_decltype(statement, i);
373
- auto metadata = std::make_shared<DynamicHostObject>();
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
-
378
- i++;
379
- }
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++;
380
379
  }
380
+
381
381
  isConsuming = false;
382
382
  break;
383
383
 
package/cpp/bridge.h CHANGED
@@ -4,13 +4,14 @@
4
4
  #include "utils.h"
5
5
  #include <vector>
6
6
  #include "DynamicHostObject.h"
7
+ #include "DumbHostObject.h"
7
8
  #include "types.h"
8
9
 
9
10
  namespace osp {
10
11
 
11
12
  namespace jsi = facebook::jsi;
12
13
 
13
- BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath);
14
+ BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath, bool memoryStorage);
14
15
 
15
16
  BridgeResult sqliteCloseDb(std::string const dbName);
16
17
 
@@ -23,8 +24,8 @@ BridgeResult sqliteDetachDb(std::string const mainDBName, std::string const alia
23
24
  BridgeResult sqliteExecute(std::string const dbName,
24
25
  std::string const &query,
25
26
  std::vector<jsVal> *values,
26
- std::vector<std::shared_ptr<DynamicHostObject>> *result,
27
- std::vector<std::shared_ptr<DynamicHostObject>> *metadata);
27
+ std::vector<DumbHostObject> *results,
28
+ std::shared_ptr<std::vector<DynamicHostObject>> metadatas);
28
29
 
29
30
  BridgeResult sqliteExecuteLiteral(std::string const dbName, std::string const &query);
30
31
 
package/cpp/utils.cpp CHANGED
@@ -118,8 +118,8 @@ std::vector<jsVal> toAnyVec(jsi::Runtime &rt, jsi::Value const &params)
118
118
 
119
119
  jsi::Value createResult(jsi::Runtime &rt,
120
120
  BridgeResult status,
121
- std::vector<std::shared_ptr<DynamicHostObject>> *results,
122
- std::vector<std::shared_ptr<DynamicHostObject>> *metadata)
121
+ std::vector<DumbHostObject> *results,
122
+ std::shared_ptr<std::vector<DynamicHostObject>> metadata)
123
123
  {
124
124
  if(status.type == SQLiteError) {
125
125
  throw std::invalid_argument(status.message);
@@ -142,7 +142,8 @@ jsi::Value createResult(jsi::Runtime &rt,
142
142
  auto array = jsi::Array(rt, rowCount);
143
143
  for (int i = 0; i < rowCount; i++)
144
144
  {
145
- array.setValueAtIndex(rt, i, jsi::Object::createFromHostObject(rt, results->at(i)));
145
+ auto obj = results->at(i);
146
+ array.setValueAtIndex(rt, i, jsi::Object::createFromHostObject(rt, std::make_shared<DumbHostObject>(obj)));
146
147
  }
147
148
  rows.setProperty(rt, "_array", std::move(array));
148
149
  res.setProperty(rt, "rows", std::move(rows));
@@ -154,7 +155,7 @@ jsi::Value createResult(jsi::Runtime &rt,
154
155
  auto column_array = jsi::Array(rt, column_count);
155
156
  for (int i = 0; i < column_count; i++) {
156
157
  auto column = metadata->at(i);
157
- column_array.setValueAtIndex(rt, i, jsi::Object::createFromHostObject(rt, column));
158
+ column_array.setValueAtIndex(rt, i, jsi::Object::createFromHostObject(rt, std::make_shared<DynamicHostObject>(column)));
158
159
  }
159
160
  res.setProperty(rt, "metadata", std::move(column_array));
160
161
  }
package/cpp/utils.h CHANGED
@@ -9,6 +9,7 @@
9
9
  #include <any>
10
10
  #include "types.h"
11
11
  #include "DynamicHostObject.h"
12
+ #include "DumbHostObject.h"
12
13
 
13
14
  namespace osp {
14
15
 
@@ -46,8 +47,8 @@ std::vector<jsVal> toAnyVec(jsi::Runtime &rt, jsi::Value const &args);
46
47
 
47
48
  jsi::Value createResult(jsi::Runtime &rt,
48
49
  BridgeResult status,
49
- std::vector<std::shared_ptr<DynamicHostObject>> *results,
50
- std::vector<std::shared_ptr<DynamicHostObject>> *metadata);
50
+ std::vector<DumbHostObject> *results,
51
+ std::shared_ptr<std::vector<DynamicHostObject>> metadata);
51
52
 
52
53
  BatchResult importSQLFile(std::string dbName, std::string fileLocation);
53
54
 
package/ios/OPSQLite.mm CHANGED
@@ -12,52 +12,53 @@
12
12
 
13
13
  RCT_EXPORT_MODULE(OPSQLite)
14
14
 
15
-
16
15
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
17
- NSLog(@"Installing OPSQLite module...");
18
-
19
- RCTBridge *bridge = [RCTBridge currentBridge];
20
- RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
21
- if (cxxBridge == nil) {
22
- return @false;
23
- }
24
-
25
- using namespace facebook;
26
-
27
- auto jsiRuntime = (jsi::Runtime *)cxxBridge.runtime;
28
- if (jsiRuntime == nil) {
29
- return @false;
30
- }
31
- auto &runtime = *jsiRuntime;
32
- auto callInvoker = bridge.jsCallInvoker;
33
-
16
+ NSLog(@"Initializing OP-SQLite module...");
17
+
18
+ RCTBridge *bridge = [RCTBridge currentBridge];
19
+ RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
20
+ if (cxxBridge == nil) {
21
+ return @false;
22
+ }
23
+
24
+ using namespace facebook;
25
+
26
+ auto jsiRuntime = (jsi::Runtime *)cxxBridge.runtime;
27
+ if (jsiRuntime == nil) {
28
+ return @false;
29
+ }
30
+ auto &runtime = *jsiRuntime;
31
+ auto callInvoker = bridge.jsCallInvoker;
32
+
34
33
  // Get appGroupID value from Info.plist using key "AppGroup"
35
- NSString *appGroupID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OPSQLite_AppGroup"];
36
- NSString *documentPath;
37
-
38
- if (appGroupID != nil) {
39
- // Get the app groups container storage url
40
- NSFileManager *fileManager = [NSFileManager defaultManager];
41
- NSURL *storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:appGroupID];
42
-
43
- if (storeUrl == nil) {
44
- NSLog(@"Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID);
45
- return @false;
34
+ NSString *appGroupID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OPSQLite_AppGroup"];
35
+ NSString *documentPath;
36
+
37
+ if (appGroupID != nil) {
38
+ // Get the app groups container storage url
39
+ NSFileManager *fileManager = [NSFileManager defaultManager];
40
+ NSURL *storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:appGroupID];
41
+
42
+ if (storeUrl == nil) {
43
+ NSLog(@"Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID);
44
+ return @false;
45
+ }
46
+ NSLog(@"Configured with AppGroup ID: %@", appGroupID);
47
+
48
+ documentPath = [storeUrl path];
49
+ } else {
50
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true);
51
+ documentPath = [paths objectAtIndex:0];
46
52
  }
47
- NSLog(@"Configured with AppGroup ID: %@", appGroupID);
48
-
49
- documentPath = [storeUrl path];
50
- } else {
51
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true);
52
- documentPath = [paths objectAtIndex:0];
53
- }
54
-
55
- osp::install(runtime, callInvoker, [documentPath UTF8String]);
56
- return @true;
53
+
54
+ osp::install(runtime, callInvoker, [documentPath UTF8String]);
55
+
56
+ NSLog(@"OP-SQLite initialized");
57
+ return @true;
57
58
  }
58
59
 
59
60
  - (void)invalidate {
60
- osp::clearState();
61
+ osp::clearState();
61
62
  }
62
63
 
63
64
  @end
@@ -59,7 +59,7 @@ const enhanceQueryResult = result => {
59
59
  }
60
60
  };
61
61
  const _open = OPSQLite.open;
62
- OPSQLite.open = (dbName, location) => {
62
+ OPSQLite.open = (dbName, location, inMemory) => {
63
63
  _open(dbName, location);
64
64
  locks[dbName] = {
65
65
  queue: [],
@@ -172,7 +172,7 @@ const startNextTransaction = dbName => {
172
172
  }
173
173
  };
174
174
  const open = options => {
175
- OPSQLite.open(options.name, options.location);
175
+ OPSQLite.open(options.name, options.location, options.inMemory);
176
176
  return {
177
177
  close: () => OPSQLite.close(options.name),
178
178
  delete: () => OPSQLite.delete(options.name, options.location),
@@ -1 +1 @@
1
- {"version":3,"names":["global","__OPSQLiteProxy","OPSQLiteModule","NativeModules","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","queue","inProgress","_close","close","_execute","execute","query","params","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void> | void\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nconst enhanceQueryResult = (result: QueryResult): void => {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows._array[idx];\n }\n};\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const result = _execute(dbName, query, params);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const res = await _executeAsync(dbName, query, params);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void> | void) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void> | void) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n };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CAAC;AAAC"}
1
+ {"version":3,"names":["global","__OPSQLiteProxy","OPSQLiteModule","NativeModules","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","inMemory","queue","inProgress","_close","close","_execute","execute","query","params","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string, inMemory?: boolean) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void> | void\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nconst enhanceQueryResult = (result: QueryResult): void => {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows._array[idx];\n }\n};\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string, inMemory?: boolean) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const result = _execute(dbName, query, params);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const res = await _executeAsync(dbName, query, params);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void> | void) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n inMemory?: boolean;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location, options.inMemory);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void> | void) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n };\n};\n"],"mappings":";;;;;;AAAA;AAOA,IAAIA,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGC,0BAAa,CAACC,QAAQ;EAE7C,IAAIF,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIG,KAAK,CAAC,sDAAsD,CAAC;EACzE;;EAEA;EACA,IAAIL,MAAM,CAACM,kBAAkB,IAAI,IAAI,IAAIJ,cAAc,CAACK,OAAO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AC;IAC7DmC,MAAM,EAAE,CAACC,cAAsB,EAAEC,KAAa,EAAErC,QAAiB,KAC/DhB,QAAQ,CAACmD,MAAM,CAACH,OAAO,CAACC,IAAI,EAAEG,cAAc,EAAEC,KAAK,EAAErC,QAAQ,CAAC;IAChEsC,MAAM,EAAGD,KAAa,IAAKrD,QAAQ,CAACsD,MAAM,CAACN,OAAO,CAACC,IAAI,EAAEI,KAAK,CAAC;IAC/DxB,WAAW,EAAGC,EAA6C,IACzD9B,QAAQ,CAAC6B,WAAW,CAACmB,OAAO,CAACC,IAAI,EAAEnB,EAAE,CAAC;IACxCP,OAAO,EAAE,CAACC,KAAa,EAAEC,MAA0B,KACjDzB,QAAQ,CAACuB,OAAO,CAACyB,OAAO,CAACC,IAAI,EAAEzB,KAAK,EAAEC,MAAM,CAAC;IAC/CE,YAAY,EAAE,CACZH,KAAa,EACbC,MAA0B,KAE1BzB,QAAQ,CAAC2B,YAAY,CAACqB,OAAO,CAACC,IAAI,EAAEzB,KAAK,EAAEC,MAAM,CAAC;IACpD8B,YAAY,EAAGC,QAAyB,IACtCxD,QAAQ,CAACuD,YAAY,CAACP,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IAC/CC,iBAAiB,EAAGD,QAAyB,IAC3CxD,QAAQ,CAACyD,iBAAiB,CAACT,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IACpDE,QAAQ,EAAG1C,QAAgB,IAAKhB,QAAQ,CAAC0D,QAAQ,CAACV,OAAO,CAACC,IAAI,EAAEjC,QAAQ;EAC1E,CAAC;AACH,CAAC;AAAC"}
@@ -53,7 +53,7 @@ const enhanceQueryResult = result => {
53
53
  }
54
54
  };
55
55
  const _open = OPSQLite.open;
56
- OPSQLite.open = (dbName, location) => {
56
+ OPSQLite.open = (dbName, location, inMemory) => {
57
57
  _open(dbName, location);
58
58
  locks[dbName] = {
59
59
  queue: [],
@@ -166,7 +166,7 @@ const startNextTransaction = dbName => {
166
166
  }
167
167
  };
168
168
  export const open = options => {
169
- OPSQLite.open(options.name, options.location);
169
+ OPSQLite.open(options.name, options.location, options.inMemory);
170
170
  return {
171
171
  close: () => OPSQLite.close(options.name),
172
172
  delete: () => OPSQLite.delete(options.name, options.location),
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","global","__OPSQLiteProxy","OPSQLiteModule","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","queue","inProgress","_close","close","_execute","execute","query","params","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void> | void\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nconst enhanceQueryResult = (result: QueryResult): void => {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows._array[idx];\n }\n};\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const result = _execute(dbName, query, params);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const res = await _executeAsync(dbName, query, params);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void> | void) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void> | void) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAO5C,IAAIC,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGH,aAAa,CAACI,QAAQ;EAE7C,IAAID,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIE,KA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AMjD,QAAQ,CAACiD,MAAM,CAACF,OAAO,CAACC,IAAI,EAAED,OAAO,CAAC/B,QAAQ,CAAC;IAC7DkC,MAAM,EAAE,CAACC,cAAsB,EAAEC,KAAa,EAAEpC,QAAiB,KAC/DhB,QAAQ,CAACkD,MAAM,CAACH,OAAO,CAACC,IAAI,EAAEG,cAAc,EAAEC,KAAK,EAAEpC,QAAQ,CAAC;IAChEqC,MAAM,EAAGD,KAAa,IAAKpD,QAAQ,CAACqD,MAAM,CAACN,OAAO,CAACC,IAAI,EAAEI,KAAK,CAAC;IAC/DxB,WAAW,EAAGC,EAA6C,IACzD7B,QAAQ,CAAC4B,WAAW,CAACmB,OAAO,CAACC,IAAI,EAAEnB,EAAE,CAAC;IACxCP,OAAO,EAAE,CAACC,KAAa,EAAEC,MAA0B,KACjDxB,QAAQ,CAACsB,OAAO,CAACyB,OAAO,CAACC,IAAI,EAAEzB,KAAK,EAAEC,MAAM,CAAC;IAC/CE,YAAY,EAAE,CACZH,KAAa,EACbC,MAA0B,KAE1BxB,QAAQ,CAAC0B,YAAY,CAACqB,OAAO,CAACC,IAAI,EAAEzB,KAAK,EAAEC,MAAM,CAAC;IACpD8B,YAAY,EAAGC,QAAyB,IACtCvD,QAAQ,CAACsD,YAAY,CAACP,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IAC/CC,iBAAiB,EAAGD,QAAyB,IAC3CvD,QAAQ,CAACwD,iBAAiB,CAACT,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IACpDE,QAAQ,EAAGzC,QAAgB,IAAKhB,QAAQ,CAACyD,QAAQ,CAACV,OAAO,CAACC,IAAI,EAAEhC,QAAQ;EAC1E,CAAC;AACH,CAAC"}
1
+ {"version":3,"names":["NativeModules","global","__OPSQLiteProxy","OPSQLiteModule","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","inMemory","queue","inProgress","_close","close","_execute","execute","query","params","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string, inMemory?: boolean) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void> | void\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nconst enhanceQueryResult = (result: QueryResult): void => {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows._array[idx];\n }\n};\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string, inMemory?: boolean) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const result = _execute(dbName, query, params);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const res = await _executeAsync(dbName, query, params);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void> | void) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n inMemory?: boolean;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location, options.inMemory);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void> | void) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAO5C,IAAIC,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGH,aAAa,CAACI,QAAQ;EAE7C,IAAID,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIE,KAAK,CAAC,sDAAsD,CAAC;EACzE;;EAEA;EACA,IAAIJ,MAAM,CAACK,kBAAkB,IAAI,IAAI,IAAIH,cAAc,CAACI,OAAO,IAAI,IAAI,EAAE;IACvE,MAAM,IAAIF,KAAK,CACb,iQAAiQ,CAClQ;EACH;;EAEA;EACA,MAAMG,MAAM,GAAGL,cAAc,CAACI,OAAO,EAAE;EACvC,IAAIC,MAAM,KAAK,IAAI,EAAE;I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,CAAC;IAChEsC,MAAM,EAAGD,KAAa,IAAKrD,QAAQ,CAACsD,MAAM,CAACN,OAAO,CAACC,IAAI,EAAEI,KAAK,CAAC;IAC/DxB,WAAW,EAAGC,EAA6C,IACzD9B,QAAQ,CAAC6B,WAAW,CAACmB,OAAO,CAACC,IAAI,EAAEnB,EAAE,CAAC;IACxCP,OAAO,EAAE,CAACC,KAAa,EAAEC,MAA0B,KACjDzB,QAAQ,CAACuB,OAAO,CAACyB,OAAO,CAACC,IAAI,EAAEzB,KAAK,EAAEC,MAAM,CAAC;IAC/CE,YAAY,EAAE,CACZH,KAAa,EACbC,MAA0B,KAE1BzB,QAAQ,CAAC2B,YAAY,CAACqB,OAAO,CAACC,IAAI,EAAEzB,KAAK,EAAEC,MAAM,CAAC;IACpD8B,YAAY,EAAGC,QAAyB,IACtCxD,QAAQ,CAACuD,YAAY,CAACP,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IAC/CC,iBAAiB,EAAGD,QAAyB,IAC3CxD,QAAQ,CAACyD,iBAAiB,CAACT,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IACpDE,QAAQ,EAAG1C,QAAgB,IAAKhB,QAAQ,CAAC0D,QAAQ,CAACV,OAAO,CAACC,IAAI,EAAEjC,QAAQ;EAC1E,CAAC;AACH,CAAC"}
@@ -77,7 +77,7 @@ export interface PendingTransaction {
77
77
  start: () => void;
78
78
  }
79
79
  interface ISQLite {
80
- open: (dbName: string, location?: string) => void;
80
+ open: (dbName: string, location?: string, inMemory?: boolean) => void;
81
81
  close: (dbName: string) => void;
82
82
  delete: (dbName: string, location?: string) => void;
83
83
  attach: (mainDbName: string, dbNameToAttach: string, alias: string, location?: string) => void;
@@ -104,5 +104,6 @@ export type OPSQLiteConnection = {
104
104
  export declare const open: (options: {
105
105
  name: string;
106
106
  location?: string;
107
+ inMemory?: boolean;
107
108
  }) => OPSQLiteConnection;
108
109
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.ts CHANGED
@@ -131,7 +131,7 @@ export interface PendingTransaction {
131
131
  }
132
132
 
133
133
  interface ISQLite {
134
- open: (dbName: string, location?: string) => void;
134
+ open: (dbName: string, location?: string, inMemory?: boolean) => void;
135
135
  close: (dbName: string) => void;
136
136
  delete: (dbName: string, location?: string) => void;
137
137
  attach: (
@@ -181,7 +181,7 @@ const enhanceQueryResult = (result: QueryResult): void => {
181
181
  };
182
182
 
183
183
  const _open = OPSQLite.open;
184
- OPSQLite.open = (dbName: string, location?: string) => {
184
+ OPSQLite.open = (dbName: string, location?: string, inMemory?: boolean) => {
185
185
  _open(dbName, location);
186
186
 
187
187
  locks[dbName] = {
@@ -347,8 +347,9 @@ export type OPSQLiteConnection = {
347
347
  export const open = (options: {
348
348
  name: string;
349
349
  location?: string;
350
+ inMemory?: boolean;
350
351
  }): OPSQLiteConnection => {
351
- OPSQLite.open(options.name, options.location);
352
+ OPSQLite.open(options.name, options.location, options.inMemory);
352
353
 
353
354
  return {
354
355
  close: () => OPSQLite.close(options.name),