@op-engineering/op-sqlite 1.0.3 → 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 +49 -13
- package/android/cpp-adapter.cpp +2 -2
- package/cpp/DumbHostObject.cpp +1 -1
- package/cpp/DumbHostObject.h +2 -2
- package/cpp/DynamicHostObject.cpp +1 -1
- package/cpp/DynamicHostObject.h +2 -2
- package/cpp/ThreadPool.cpp +1 -1
- package/cpp/ThreadPool.h +1 -1
- package/cpp/bindings.cpp +15 -6
- package/cpp/bindings.h +1 -1
- package/cpp/bridge.cpp +126 -126
- package/cpp/bridge.h +3 -3
- package/cpp/sqlbatchexecutor.cpp +3 -3
- package/cpp/sqlbatchexecutor.h +2 -2
- package/cpp/types.h +5 -5
- package/cpp/utils.cpp +14 -14
- package/cpp/utils.h +29 -31
- package/ios/OPSQLite.mm +41 -40
- package/lib/commonjs/index.js +2 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/index.ts +4 -3
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 |
|
|
39
|
-
| expo-sqlite |
|
|
40
|
-
| op-sqlite |
|
|
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
|
|
|
@@ -48,6 +44,8 @@ The library creates/opens databases by appending the passed name plus, the [libr
|
|
|
48
44
|
If you have an existing database file you want to load you can navigate from these directories using dot notation. e.g.:
|
|
49
45
|
|
|
50
46
|
```ts
|
|
47
|
+
import { open } from '@op-engineering/op-sqlite';
|
|
48
|
+
|
|
51
49
|
const largeDb = open({
|
|
52
50
|
name: 'largeDB',
|
|
53
51
|
location: '../files/databases',
|
|
@@ -56,7 +54,20 @@ const largeDb = open({
|
|
|
56
54
|
|
|
57
55
|
Note that on iOS the file system is sand-boxed, so you cannot access files/directories outside your app bundle directories.
|
|
58
56
|
|
|
59
|
-
##
|
|
57
|
+
## In memory
|
|
58
|
+
|
|
59
|
+
Using SQLite in memory mode is supported:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { open } from '@op-engineering/op-sqlite';
|
|
63
|
+
|
|
64
|
+
const largeDb = open({
|
|
65
|
+
name: 'inMemoryDb',
|
|
66
|
+
inMemory: true,
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
# API
|
|
60
71
|
|
|
61
72
|
```typescript
|
|
62
73
|
import {open} from '@op-engineering/op-sqlite'
|
|
@@ -85,15 +96,16 @@ db = {
|
|
|
85
96
|
|
|
86
97
|
The basic query is **synchronous**, it will block rendering on large operations, further below you will find async versions.
|
|
87
98
|
|
|
88
|
-
```
|
|
99
|
+
```ts
|
|
89
100
|
import { open } from '@op-engineering/op-sqlite';
|
|
90
101
|
|
|
91
102
|
try {
|
|
92
|
-
const db = open('myDb.sqlite');
|
|
103
|
+
const db = open({ name: 'myDb.sqlite' });
|
|
93
104
|
|
|
94
105
|
let { rows } = db.execute('SELECT somevalue FROM sometable');
|
|
95
106
|
|
|
96
|
-
|
|
107
|
+
// _array internally holds the values, this is meant to comply with the webSQL spec
|
|
108
|
+
rows._array.forEach((row) => {
|
|
97
109
|
console.log(row);
|
|
98
110
|
});
|
|
99
111
|
|
|
@@ -108,6 +120,30 @@ try {
|
|
|
108
120
|
}
|
|
109
121
|
```
|
|
110
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
|
+
|
|
111
147
|
### Transactions
|
|
112
148
|
|
|
113
149
|
Throwing an error inside the callback will ROLLBACK the transaction.
|
|
@@ -184,7 +220,7 @@ db.executeAsync(
|
|
|
184
220
|
'myDatabase',
|
|
185
221
|
'SELECT * FROM "User";',
|
|
186
222
|
[]).then(({rows}) => {
|
|
187
|
-
console.log('users', rows);
|
|
223
|
+
console.log('users', rows._array);
|
|
188
224
|
})
|
|
189
225
|
);
|
|
190
226
|
```
|
|
@@ -266,7 +302,7 @@ For example, you could add `SQLITE_ENABLE_FTS5=1` to `GCC_PREPROCESSOR_DEFINITIO
|
|
|
266
302
|
You can specify flags via `<PROJECT_ROOT>/android/gradle.properties` like so:
|
|
267
303
|
|
|
268
304
|
```
|
|
269
|
-
|
|
305
|
+
OPSQLiteFlags="-DSQLITE_ENABLE_FTS5=1"
|
|
270
306
|
```
|
|
271
307
|
|
|
272
308
|
## Additional configuration
|
package/android/cpp-adapter.cpp
CHANGED
|
@@ -29,11 +29,11 @@ private:
|
|
|
29
29
|
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
|
|
30
30
|
std::string docPathString = docPath->toStdString();
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
opsqlite::install(*jsiRuntime, jsCallInvoker, docPathString.c_str());
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
static void clearStateNativeJsi(jni::alias_ref<jni::JObject> thiz) {
|
|
36
|
-
|
|
36
|
+
opsqlite::clearState();
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
|
package/cpp/DumbHostObject.cpp
CHANGED
package/cpp/DumbHostObject.h
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#include "types.h"
|
|
10
10
|
#include "DynamicHostObject.h"
|
|
11
11
|
|
|
12
|
-
namespace
|
|
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<
|
|
26
|
+
std::vector<JSVariant> values;
|
|
27
27
|
|
|
28
28
|
std::shared_ptr<std::vector<DynamicHostObject>> metadata;
|
|
29
29
|
};
|
package/cpp/DynamicHostObject.h
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#include <vector>
|
|
7
7
|
#include "types.h"
|
|
8
8
|
|
|
9
|
-
namespace
|
|
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,
|
|
21
|
+
std::vector<std::pair<std::string, JSVariant>> fields;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
}
|
package/cpp/ThreadPool.cpp
CHANGED
package/cpp/ThreadPool.h
CHANGED
package/cpp/bindings.cpp
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
#include <iostream>
|
|
11
11
|
#include "DumbHostObject.h"
|
|
12
12
|
|
|
13
|
-
namespace
|
|
13
|
+
namespace opsqlite {
|
|
14
14
|
|
|
15
15
|
namespace jsi = facebook::jsi;
|
|
16
16
|
|
|
@@ -28,7 +28,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
28
28
|
pool = std::make_shared<ThreadPool>();
|
|
29
29
|
invoker = jsCallInvoker;
|
|
30
30
|
|
|
31
|
-
auto open = HOSTFN("open",
|
|
31
|
+
auto open = HOSTFN("open", 3) {
|
|
32
32
|
if (count == 0)
|
|
33
33
|
{
|
|
34
34
|
throw jsi::JSError(rt, "[op-sqlite][open] database name is required");
|
|
@@ -41,6 +41,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
41
41
|
|
|
42
42
|
std::string dbName = args[0].asString(rt).utf8(rt);
|
|
43
43
|
std::string tempDocPath = std::string(basePath);
|
|
44
|
+
bool memoryStorage = false;
|
|
44
45
|
|
|
45
46
|
if (count > 1 && !args[1].isUndefined() && !args[1].isNull())
|
|
46
47
|
{
|
|
@@ -52,7 +53,15 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
52
53
|
tempDocPath = tempDocPath + "/" + args[1].asString(rt).utf8(rt);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
|
|
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);
|
|
56
65
|
|
|
57
66
|
if (result.type == SQLiteError)
|
|
58
67
|
{
|
|
@@ -183,7 +192,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
183
192
|
{
|
|
184
193
|
const std::string dbName = args[0].asString(rt).utf8(rt);
|
|
185
194
|
const std::string query = args[1].asString(rt).utf8(rt);
|
|
186
|
-
std::vector<
|
|
195
|
+
std::vector<JSVariant> params;
|
|
187
196
|
if(count == 3) {
|
|
188
197
|
const jsi::Value &originalParams = args[2];
|
|
189
198
|
params = toAnyVec(rt, originalParams);
|
|
@@ -217,7 +226,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
217
226
|
const std::string query = args[1].asString(rt).utf8(rt);
|
|
218
227
|
const jsi::Value &originalParams = args[2];
|
|
219
228
|
|
|
220
|
-
std::vector<
|
|
229
|
+
std::vector<JSVariant> params = toAnyVec(rt, originalParams);
|
|
221
230
|
|
|
222
231
|
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
223
232
|
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor", 2) {
|
|
@@ -225,7 +234,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
|
|
|
225
234
|
auto reject = std::make_shared<jsi::Value>(rt, args[1]);
|
|
226
235
|
|
|
227
236
|
auto task =
|
|
228
|
-
[&rt, dbName, query, params = std::make_shared<std::vector<
|
|
237
|
+
[&rt, dbName, query, params = std::make_shared<std::vector<JSVariant>>(params), resolve, reject]()
|
|
229
238
|
{
|
|
230
239
|
try
|
|
231
240
|
{
|
package/cpp/bindings.h
CHANGED
package/cpp/bridge.cpp
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
#include "DumbHostObject.h"
|
|
12
12
|
#include <variant>
|
|
13
13
|
|
|
14
|
-
namespace
|
|
14
|
+
namespace opsqlite {
|
|
15
15
|
|
|
16
16
|
std::unordered_map<std::string, sqlite3 *> dbMap = std::unordered_map<std::string, sqlite3 *>();
|
|
17
17
|
|
|
@@ -73,9 +73,9 @@ std::string get_db_path(std::string const dbName, std::string const docPath)
|
|
|
73
73
|
return docPath + "/" + dbName;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath)
|
|
76
|
+
BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath, bool memoryStorage)
|
|
77
77
|
{
|
|
78
|
-
std::string dbPath = get_db_path(dbName, docPath);
|
|
78
|
+
std::string dbPath = memoryStorage ? ":memory:" : get_db_path(dbName, docPath);
|
|
79
79
|
|
|
80
80
|
int sqlOpenFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
|
|
81
81
|
|
|
@@ -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<
|
|
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
|
-
|
|
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<
|
|
234
|
+
else if(std::holds_alternative<ArrayBuffer>(value))
|
|
235
235
|
{
|
|
236
|
-
|
|
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<
|
|
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
|
-
|
|
286
|
-
|
|
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
|
-
|
|
270
|
+
int statementStatus = sqlite3_prepare_v2(db, queryStr, -1, &statement, &remainingStatement);
|
|
271
|
+
|
|
272
|
+
if (statementStatus == SQLITE_ERROR)
|
|
293
273
|
{
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
305
|
+
while (i < count)
|
|
310
306
|
{
|
|
311
|
-
|
|
307
|
+
column_type = sqlite3_column_type(statement, i);
|
|
308
|
+
|
|
309
|
+
switch (column_type)
|
|
312
310
|
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
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
|
-
|
|
378
|
-
i
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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,11 +7,11 @@
|
|
|
7
7
|
#include "DumbHostObject.h"
|
|
8
8
|
#include "types.h"
|
|
9
9
|
|
|
10
|
-
namespace
|
|
10
|
+
namespace opsqlite {
|
|
11
11
|
|
|
12
12
|
namespace jsi = facebook::jsi;
|
|
13
13
|
|
|
14
|
-
BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath);
|
|
14
|
+
BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath, bool memoryStorage);
|
|
15
15
|
|
|
16
16
|
BridgeResult sqliteCloseDb(std::string const dbName);
|
|
17
17
|
|
|
@@ -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<
|
|
26
|
+
std::vector<JSVariant> *values,
|
|
27
27
|
std::vector<DumbHostObject> *results,
|
|
28
28
|
std::shared_ptr<std::vector<DynamicHostObject>> metadatas);
|
|
29
29
|
|
package/cpp/sqlbatchexecutor.cpp
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#include "sqlbatchexecutor.h"
|
|
2
2
|
|
|
3
|
-
namespace
|
|
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<
|
|
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<
|
|
37
|
+
auto params = std::make_shared<std::vector<JSVariant>>(toAnyVec(rt, commandParams));
|
|
38
38
|
commands->push_back({
|
|
39
39
|
query,
|
|
40
40
|
params
|
package/cpp/sqlbatchexecutor.h
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
#include "bridge.h"
|
|
6
6
|
#include "types.h"
|
|
7
7
|
|
|
8
|
-
namespace
|
|
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<
|
|
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
|
|
2
|
-
#define
|
|
1
|
+
#ifndef types_h
|
|
2
|
+
#define types_h
|
|
3
3
|
|
|
4
4
|
#include <variant>
|
|
5
5
|
|
|
6
|
-
struct
|
|
6
|
+
struct ArrayBuffer {
|
|
7
7
|
std::shared_ptr<uint8_t> data;
|
|
8
8
|
size_t size;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
using
|
|
12
|
+
using JSVariant = std::variant<nullptr_t, bool, int, double, long, long long, std::string, ArrayBuffer>;
|
|
13
13
|
|
|
14
|
-
#endif /*
|
|
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
|
|
7
|
+
namespace opsqlite {
|
|
8
8
|
|
|
9
9
|
namespace jsi = facebook::jsi;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
JSVariant toAny(jsi::Runtime &rt, jsi::Value &value) {
|
|
12
12
|
if (value.isNull() || value.isUndefined())
|
|
13
13
|
{
|
|
14
|
-
return
|
|
14
|
+
return JSVariant(nullptr);
|
|
15
15
|
}
|
|
16
16
|
else if (value.isBool())
|
|
17
17
|
{
|
|
18
|
-
return
|
|
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
|
|
27
|
+
return JSVariant(intVal);
|
|
28
28
|
}
|
|
29
29
|
else if (longVal == doubleVal)
|
|
30
30
|
{
|
|
31
|
-
return
|
|
31
|
+
return JSVariant(longVal);
|
|
32
32
|
}
|
|
33
33
|
else
|
|
34
34
|
{
|
|
35
|
-
return
|
|
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
|
|
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
|
|
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,
|
|
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<
|
|
85
|
+
else if (std::holds_alternative<ArrayBuffer>(value))
|
|
86
86
|
{
|
|
87
|
-
auto jsBuffer = std::get<
|
|
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<
|
|
99
|
+
std::vector<JSVariant> toAnyVec(jsi::Runtime &rt, jsi::Value const ¶ms)
|
|
100
100
|
{
|
|
101
|
-
std::vector<
|
|
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
|
|
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
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
struct BatchResult
|
|
33
|
+
{
|
|
34
|
+
ResultType type;
|
|
35
|
+
std::string message;
|
|
36
|
+
int affectedRows;
|
|
37
|
+
int commands;
|
|
38
|
+
};
|
|
25
39
|
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
44
|
+
std::vector<JSVariant> toAnyVec(jsi::Runtime &rt, jsi::Value const &args);
|
|
43
45
|
|
|
44
|
-
jsi::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
|
-
|
|
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
|
@@ -12,52 +12,53 @@
|
|
|
12
12
|
|
|
13
13
|
RCT_EXPORT_MODULE(OPSQLite)
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
documentPath = [paths objectAtIndex:0];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
osp::install(runtime, callInvoker, [documentPath UTF8String]);
|
|
56
|
-
return @true;
|
|
53
|
+
|
|
54
|
+
opsqlite::install(runtime, callInvoker, [documentPath UTF8String]);
|
|
55
|
+
|
|
56
|
+
NSLog(@"OP-SQLite initialized");
|
|
57
|
+
return @true;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
- (void)invalidate {
|
|
60
|
-
|
|
61
|
+
opsqlite::clearState();
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
@end
|
package/lib/commonjs/index.js
CHANGED
|
@@ -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 };\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,IAAI,I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EC,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;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,IAAI,IAAI,EAAE;IACvE,MAAM,IAAIF,KAAK,CACb,iQAAiQ,CAClQ;EACH;;EAEA;EACA,MAAMG,MAAM,GAAGN,cAAc,CAACK,OAAO,EAAE;EACvC,IAAIC,MAAM,KAAK,IAAI,EAAE;IACnB,MAAM,IAAIH,KAAK,CACZ,iJAAgJG,MAAO,EAAC,CAC1J;EACH;;EAEA;EACA,IAAIR,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;IAClC,MA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6C,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"}
|
package/lib/module/index.js
CHANGED
|
@@ -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),
|
package/lib/module/index.js.map
CHANGED
|
@@ -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,KAAK,CAAC,sDAAsD,CAAC;EACzE;;EAEA;EACA,IAAIJ,MAAM,CAACK,kBAAkB,IAAI,IAAI,IAAIH,cAAc,CAACI,OAAO,IAAI,IA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B,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;IACnB,MAAM,IAAIH,KAAK,CACZ,iJAAgJG,MAAO,EAAC,CAC1J;EACH;;EAEA;EACA,IAAIP,MAAM,CAACC,eAAe,IAAI,IA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AC/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
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),
|