@op-engineering/op-sqlite 11.2.10 → 11.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/bridge.cpp +8 -4
- package/cpp/libsql/bridge.cpp +34 -35
- package/cpp/utils.cpp +0 -8
- package/cpp/utils.h +0 -5
- package/lib/commonjs/index.js +72 -52
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +71 -51
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +171 -32
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +259 -97
package/cpp/bridge.cpp
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#include "SmartHostObject.h"
|
|
9
9
|
#include "logs.h"
|
|
10
10
|
#include "utils.h"
|
|
11
|
+
#include <filesystem>
|
|
11
12
|
#include <iostream>
|
|
12
13
|
#include <sstream>
|
|
13
14
|
#include <stdexcept>
|
|
@@ -66,11 +67,14 @@ std::string opsqlite_get_db_path(std::string const &db_name,
|
|
|
66
67
|
if (location == ":memory:") {
|
|
67
68
|
return location;
|
|
68
69
|
}
|
|
70
|
+
char resolved_location[PATH_MAX];
|
|
71
|
+
realpath(location.c_str(), resolved_location);
|
|
72
|
+
std::string resolved_location_string = std::string(resolved_location);
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
74
|
+
// Will return false if the directory already exists, no need to check
|
|
75
|
+
std::filesystem::create_directories(resolved_location);
|
|
76
|
+
|
|
77
|
+
return resolved_location_string + "/" + db_name;
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
#ifdef OP_SQLITE_USE_SQLCIPHER
|
package/cpp/libsql/bridge.cpp
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include "SmartHostObject.h"
|
|
4
4
|
#include "logs.h"
|
|
5
5
|
#include "utils.h"
|
|
6
|
+
#include <filesystem>
|
|
6
7
|
#include <iostream>
|
|
7
8
|
#include <unordered_map>
|
|
8
9
|
#include <variant>
|
|
@@ -25,15 +26,20 @@ std::string opsqlite_get_db_path(std::string const &db_name,
|
|
|
25
26
|
return location;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
char resolved_location[PATH_MAX];
|
|
30
|
+
realpath(location.c_str(), resolved_location);
|
|
31
|
+
std::string resolved_location_string = std::string(resolved_location);
|
|
32
|
+
|
|
33
|
+
// Will return false if the directory already exists, no need to check
|
|
34
|
+
std::filesystem::create_directories(resolved_location);
|
|
35
|
+
|
|
36
|
+
return resolved_location_string + "/" + db_name;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
DB opsqlite_libsql_open_sync(std::string const &name,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
int sync_interval) {
|
|
40
|
+
std::string const &base_path,
|
|
41
|
+
std::string const &url,
|
|
42
|
+
std::string const &auth_token, int sync_interval) {
|
|
37
43
|
std::string path = opsqlite_get_db_path(name, base_path);
|
|
38
44
|
|
|
39
45
|
int status;
|
|
@@ -50,21 +56,20 @@ DB opsqlite_libsql_open_sync(std::string const &name,
|
|
|
50
56
|
.with_webpki = '1'};
|
|
51
57
|
status = libsql_open_sync_with_config(config, &db, &err);
|
|
52
58
|
if (status != 0) {
|
|
53
|
-
|
|
59
|
+
throw std::runtime_error(err);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
status = libsql_connect(db, &c, &err);
|
|
57
63
|
|
|
58
64
|
if (status != 0) {
|
|
59
|
-
|
|
65
|
+
throw std::runtime_error(err);
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
return {.db= db, .c= c
|
|
68
|
+
return {.db = db, .c = c};
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
DB opsqlite_libsql_open(std::string const &name,
|
|
66
|
-
|
|
67
|
-
std::string const &crsqlitePath) {
|
|
71
|
+
DB opsqlite_libsql_open(std::string const &name, std::string const &last_path,
|
|
72
|
+
std::string const &crsqlitePath) {
|
|
68
73
|
std::string path = opsqlite_get_db_path(name, last_path);
|
|
69
74
|
|
|
70
75
|
int status;
|
|
@@ -75,13 +80,13 @@ DB opsqlite_libsql_open(std::string const &name,
|
|
|
75
80
|
status = libsql_open_file(path.c_str(), &db, &err);
|
|
76
81
|
|
|
77
82
|
if (status != 0) {
|
|
78
|
-
|
|
83
|
+
throw std::runtime_error(err);
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
status = libsql_connect(db, &c, &err);
|
|
82
87
|
|
|
83
88
|
if (status != 0) {
|
|
84
|
-
|
|
89
|
+
throw std::runtime_error(err);
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
#ifdef OP_SQLITE_USE_CRSQLITE
|
|
@@ -102,7 +107,7 @@ DB opsqlite_libsql_open(std::string const &name,
|
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
DB opsqlite_libsql_open_remote(std::string const &url,
|
|
105
|
-
|
|
110
|
+
std::string const &auth_token) {
|
|
106
111
|
int status;
|
|
107
112
|
libsql_database_t db;
|
|
108
113
|
libsql_connection_t c;
|
|
@@ -112,13 +117,13 @@ DB opsqlite_libsql_open_remote(std::string const &url,
|
|
|
112
117
|
&err);
|
|
113
118
|
|
|
114
119
|
if (status != 0) {
|
|
115
|
-
|
|
120
|
+
throw std::runtime_error(err);
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
status = libsql_connect(db, &c, &err);
|
|
119
124
|
|
|
120
125
|
if (status != 0) {
|
|
121
|
-
|
|
126
|
+
throw std::runtime_error(err);
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
return {.db = db, .c = c};
|
|
@@ -135,19 +140,16 @@ void opsqlite_libsql_close(DB &db) {
|
|
|
135
140
|
}
|
|
136
141
|
}
|
|
137
142
|
|
|
138
|
-
void opsqlite_libsql_attach(DB const &db,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
std::string const &alias) {
|
|
143
|
+
void opsqlite_libsql_attach(DB const &db, std::string const &docPath,
|
|
144
|
+
std::string const &databaseToAttach,
|
|
145
|
+
std::string const &alias) {
|
|
142
146
|
std::string dbPath = opsqlite_get_db_path(databaseToAttach, docPath);
|
|
143
147
|
std::string statement = "ATTACH DATABASE '" + dbPath + "' AS " + alias;
|
|
144
148
|
|
|
145
149
|
opsqlite_libsql_execute(db, statement, nullptr);
|
|
146
|
-
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
void opsqlite_libsql_detach(DB const &db,
|
|
150
|
-
std::string const &alias) {
|
|
152
|
+
void opsqlite_libsql_detach(DB const &db, std::string const &alias) {
|
|
151
153
|
std::string statement = "DETACH DATABASE " + alias;
|
|
152
154
|
opsqlite_libsql_execute(db, statement, nullptr);
|
|
153
155
|
}
|
|
@@ -160,17 +162,17 @@ void opsqlite_libsql_sync(DB const &db) {
|
|
|
160
162
|
if (status != 0) {
|
|
161
163
|
throw std::runtime_error(err);
|
|
162
164
|
}
|
|
163
|
-
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
void opsqlite_libsql_remove(DB &db, std::string const &name,
|
|
167
|
-
|
|
168
|
+
std::string const &path) {
|
|
168
169
|
opsqlite_libsql_close(db);
|
|
169
170
|
|
|
170
171
|
std::string full_path = opsqlite_get_db_path(name, path);
|
|
171
172
|
|
|
172
173
|
if (!file_exists(full_path)) {
|
|
173
|
-
throw std::runtime_error("[op-sqlite]: Database file not found" +
|
|
174
|
+
throw std::runtime_error("[op-sqlite]: Database file not found" +
|
|
175
|
+
full_path);
|
|
174
176
|
}
|
|
175
177
|
|
|
176
178
|
remove(full_path.c_str());
|
|
@@ -215,9 +217,7 @@ void opsqlite_libsql_bind_statement(libsql_stmt_t statement,
|
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
BridgeResult opsqlite_libsql_execute_prepared_statement(
|
|
218
|
-
DB const &db,
|
|
219
|
-
libsql_stmt_t stmt,
|
|
220
|
-
std::vector<DumbHostObject> *results,
|
|
220
|
+
DB const &db, libsql_stmt_t stmt, std::vector<DumbHostObject> *results,
|
|
221
221
|
const std::shared_ptr<std::vector<SmartHostObject>> &metadatas) {
|
|
222
222
|
|
|
223
223
|
libsql_rows_t rows;
|
|
@@ -348,8 +348,7 @@ libsql_stmt_t opsqlite_libsql_prepare_statement(DB const &db,
|
|
|
348
348
|
return stmt;
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
BridgeResult opsqlite_libsql_execute(DB const &db,
|
|
352
|
-
std::string const &query,
|
|
351
|
+
BridgeResult opsqlite_libsql_execute(DB const &db, std::string const &query,
|
|
353
352
|
const std::vector<JSVariant> *params) {
|
|
354
353
|
|
|
355
354
|
std::vector<std::string> column_names;
|
|
@@ -364,7 +363,7 @@ BridgeResult opsqlite_libsql_execute(DB const &db,
|
|
|
364
363
|
status = libsql_prepare(db.c, query.c_str(), &stmt, &err);
|
|
365
364
|
|
|
366
365
|
if (status != 0) {
|
|
367
|
-
|
|
366
|
+
throw std::runtime_error(err);
|
|
368
367
|
}
|
|
369
368
|
|
|
370
369
|
if (params != nullptr && !params->empty()) {
|
|
@@ -374,7 +373,7 @@ BridgeResult opsqlite_libsql_execute(DB const &db,
|
|
|
374
373
|
status = libsql_query_stmt(stmt, &rows, &err);
|
|
375
374
|
|
|
376
375
|
if (status != 0) {
|
|
377
|
-
|
|
376
|
+
throw std::runtime_error(err);
|
|
378
377
|
}
|
|
379
378
|
|
|
380
379
|
// Get the column names on the first pass
|
|
@@ -719,7 +718,7 @@ opsqlite_libsql_execute_batch(DB const &db,
|
|
|
719
718
|
// don't need/want to handle this results in a batch execution
|
|
720
719
|
auto result =
|
|
721
720
|
opsqlite_libsql_execute(db, command.sql, command.params.get());
|
|
722
|
-
|
|
721
|
+
affectedRows += result.affectedRows;
|
|
723
722
|
}
|
|
724
723
|
opsqlite_libsql_execute(db, "COMMIT", nullptr);
|
|
725
724
|
return BatchResult{
|
package/cpp/utils.cpp
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
#include "bridge.h"
|
|
5
5
|
#endif
|
|
6
6
|
#include <fstream>
|
|
7
|
-
#include <iostream>
|
|
8
|
-
#include <sstream>
|
|
9
7
|
#include <sys/stat.h>
|
|
10
|
-
#include <unistd.h>
|
|
11
8
|
|
|
12
9
|
namespace opsqlite {
|
|
13
10
|
|
|
@@ -315,11 +312,6 @@ bool file_exists(const std::string &path) {
|
|
|
315
312
|
return (stat(path.c_str(), &buffer) == 0);
|
|
316
313
|
}
|
|
317
314
|
|
|
318
|
-
int mkdir(std::string const &path) {
|
|
319
|
-
std::filesystem::create_directories(path);
|
|
320
|
-
return 0;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
315
|
void log_to_console(jsi::Runtime &runtime, const std::string &message) {
|
|
324
316
|
auto console = runtime.global().getPropertyAsObject(runtime, "console");
|
|
325
317
|
auto log = console.getPropertyAsFunction(runtime, "log");
|
package/cpp/utils.h
CHANGED
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
#include "DumbHostObject.h"
|
|
4
4
|
#include "SmartHostObject.h"
|
|
5
5
|
#include "types.h"
|
|
6
|
-
#include <any>
|
|
7
6
|
#include <jsi/jsi.h>
|
|
8
|
-
#include <jsi/jsilib.h>
|
|
9
|
-
#include <map>
|
|
10
7
|
#include <sqlite3.h>
|
|
11
8
|
#include <string>
|
|
12
9
|
#include <vector>
|
|
@@ -41,8 +38,6 @@ void to_batch_arguments(jsi::Runtime &rt, jsi::Array const &batch_params,
|
|
|
41
38
|
|
|
42
39
|
BatchResult import_sql_file(sqlite3 *db, std::string path);
|
|
43
40
|
|
|
44
|
-
int mkdir(const std::string &path);
|
|
45
|
-
|
|
46
41
|
bool folder_exists(const std::string &name);
|
|
47
42
|
|
|
48
43
|
bool file_exists(const std::string &path);
|
package/lib/commonjs/index.js
CHANGED
|
@@ -5,35 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.openSync = exports.openRemote = exports.open = exports.moveAssetsDatabase = exports.isSQLCipher = exports.isLibsql = exports.isIOSEmbeeded = exports.getDylibPath = exports.OPSQLite = exports.IOS_LIBRARY_PATH = exports.IOS_DOCUMENT_PATH = exports.ANDROID_FILES_PATH = exports.ANDROID_EXTERNAL_FILES_PATH = exports.ANDROID_DATABASE_PATH = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
|
-
if (global.__OPSQLiteProxy == null) {
|
|
9
|
-
if (_reactNative.NativeModules.OPSQLite == null) {
|
|
10
|
-
throw new Error('Base module not found. Maybe try rebuilding the app.');
|
|
11
|
-
}
|
|
12
|
-
if (_reactNative.NativeModules.OPSQLite.install == null) {
|
|
13
|
-
throw new Error('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.');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Call the synchronous blocking install() function
|
|
17
|
-
const result = _reactNative.NativeModules.OPSQLite.install();
|
|
18
|
-
if (result !== true) {
|
|
19
|
-
throw new Error(`Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings, check the native logs for more info`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Check again if the constructor now exists. If not, throw an error.
|
|
23
|
-
if (global.__OPSQLiteProxy == null) {
|
|
24
|
-
throw new Error('Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const proxy = global.__OPSQLiteProxy;
|
|
28
|
-
const OPSQLite = exports.OPSQLite = proxy;
|
|
29
|
-
const {
|
|
30
|
-
IOS_DOCUMENT_PATH,
|
|
31
|
-
IOS_LIBRARY_PATH,
|
|
32
|
-
ANDROID_DATABASE_PATH,
|
|
33
|
-
ANDROID_FILES_PATH,
|
|
34
|
-
ANDROID_EXTERNAL_FILES_PATH
|
|
35
|
-
} = !!_reactNative.NativeModules.OPSQLite.getConstants ? _reactNative.NativeModules.OPSQLite.getConstants() : _reactNative.NativeModules.OPSQLite;
|
|
36
|
-
|
|
37
8
|
/**
|
|
38
9
|
* Object returned by SQL Query executions {
|
|
39
10
|
* insertId: Represent the auto-generated row id if applicable
|
|
@@ -67,12 +38,37 @@ const {
|
|
|
67
38
|
* Result of loading a file and executing every line as a SQL command
|
|
68
39
|
* Similar to BatchQueryResult
|
|
69
40
|
*/
|
|
41
|
+
|
|
42
|
+
if (global.__OPSQLiteProxy == null) {
|
|
43
|
+
if (_reactNative.NativeModules.OPSQLite == null) {
|
|
44
|
+
throw new Error('Base module not found. Did you do a pod install/clear the gradle cache?');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Call the synchronous blocking install() function
|
|
48
|
+
const installed = _reactNative.NativeModules.OPSQLite.install();
|
|
49
|
+
if (!installed) {
|
|
50
|
+
throw new Error(`Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings, check the native logs for more info`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Check again if the constructor now exists. If not, throw an error.
|
|
54
|
+
if (global.__OPSQLiteProxy == null) {
|
|
55
|
+
throw new Error('OPSqlite native object is not available. Something is wrong. Check the native logs for more information.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const proxy = global.__OPSQLiteProxy;
|
|
59
|
+
const OPSQLite = exports.OPSQLite = proxy;
|
|
60
|
+
const {
|
|
61
|
+
IOS_DOCUMENT_PATH,
|
|
62
|
+
IOS_LIBRARY_PATH,
|
|
63
|
+
ANDROID_DATABASE_PATH,
|
|
64
|
+
ANDROID_FILES_PATH,
|
|
65
|
+
ANDROID_EXTERNAL_FILES_PATH
|
|
66
|
+
} = !!_reactNative.NativeModules.OPSQLite.getConstants ? _reactNative.NativeModules.OPSQLite.getConstants() : _reactNative.NativeModules.OPSQLite;
|
|
70
67
|
exports.ANDROID_EXTERNAL_FILES_PATH = ANDROID_EXTERNAL_FILES_PATH;
|
|
71
68
|
exports.ANDROID_FILES_PATH = ANDROID_FILES_PATH;
|
|
72
69
|
exports.ANDROID_DATABASE_PATH = ANDROID_DATABASE_PATH;
|
|
73
70
|
exports.IOS_LIBRARY_PATH = IOS_LIBRARY_PATH;
|
|
74
71
|
exports.IOS_DOCUMENT_PATH = IOS_DOCUMENT_PATH;
|
|
75
|
-
const locks = {};
|
|
76
72
|
function enhanceDB(db, options) {
|
|
77
73
|
const lock = {
|
|
78
74
|
queue: [],
|
|
@@ -95,7 +91,8 @@ function enhanceDB(db, options) {
|
|
|
95
91
|
}
|
|
96
92
|
};
|
|
97
93
|
|
|
98
|
-
// spreading the object
|
|
94
|
+
// spreading the object does not work with HostObjects (db)
|
|
95
|
+
// We need to manually assign the fields
|
|
99
96
|
let enhancedDb = {
|
|
100
97
|
delete: db.delete,
|
|
101
98
|
attach: db.attach,
|
|
@@ -110,11 +107,7 @@ function enhanceDB(db, options) {
|
|
|
110
107
|
getDbPath: db.getDbPath,
|
|
111
108
|
reactiveExecute: db.reactiveExecute,
|
|
112
109
|
sync: db.sync,
|
|
113
|
-
|
|
114
|
-
close: () => {
|
|
115
|
-
db.close();
|
|
116
|
-
delete locks[options.url];
|
|
117
|
-
},
|
|
110
|
+
close: db.close,
|
|
118
111
|
executeWithHostObjects: async (query, params) => {
|
|
119
112
|
const sanitizedParams = params?.map(p => {
|
|
120
113
|
if (ArrayBuffer.isView(p)) {
|
|
@@ -195,22 +188,22 @@ function enhanceDB(db, options) {
|
|
|
195
188
|
let isFinalized = false;
|
|
196
189
|
const execute = async (query, params) => {
|
|
197
190
|
if (isFinalized) {
|
|
198
|
-
throw Error(`OP-Sqlite Error: Database: ${options.url}. Cannot execute query on finalized transaction`);
|
|
191
|
+
throw Error(`OP-Sqlite Error: Database: ${options.name || options.url}. Cannot execute query on finalized transaction`);
|
|
199
192
|
}
|
|
200
193
|
return await enhancedDb.execute(query, params);
|
|
201
194
|
};
|
|
202
195
|
const commit = async () => {
|
|
203
196
|
if (isFinalized) {
|
|
204
|
-
throw Error(`OP-Sqlite Error: Database: ${options.url}. Cannot execute query on finalized transaction`);
|
|
197
|
+
throw Error(`OP-Sqlite Error: Database: ${options.name || options.url}. Cannot execute query on finalized transaction`);
|
|
205
198
|
}
|
|
206
199
|
const result = await enhancedDb.execute('COMMIT;');
|
|
207
|
-
await
|
|
200
|
+
await db.flushPendingReactiveQueries();
|
|
208
201
|
isFinalized = true;
|
|
209
202
|
return result;
|
|
210
203
|
};
|
|
211
204
|
const rollback = async () => {
|
|
212
205
|
if (isFinalized) {
|
|
213
|
-
throw Error(`OP-Sqlite Error: Database: ${options.url}. Cannot execute query on finalized transaction`);
|
|
206
|
+
throw Error(`OP-Sqlite Error: Database: ${options.name || options.url}. Cannot execute query on finalized transaction`);
|
|
214
207
|
}
|
|
215
208
|
const result = await enhancedDb.execute('ROLLBACK;');
|
|
216
209
|
isFinalized = true;
|
|
@@ -228,7 +221,6 @@ function enhanceDB(db, options) {
|
|
|
228
221
|
await commit();
|
|
229
222
|
}
|
|
230
223
|
} catch (executionError) {
|
|
231
|
-
// console.warn('transaction error', executionError);
|
|
232
224
|
if (!isFinalized) {
|
|
233
225
|
try {
|
|
234
226
|
await rollback();
|
|
@@ -257,40 +249,68 @@ function enhanceDB(db, options) {
|
|
|
257
249
|
return enhancedDb;
|
|
258
250
|
}
|
|
259
251
|
|
|
260
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* Open a replicating connection via libsql to a turso db
|
|
261
254
|
* libsql needs to be enabled on your package.json
|
|
262
255
|
*/
|
|
263
|
-
const openSync =
|
|
256
|
+
const openSync = params => {
|
|
264
257
|
if (!isLibsql()) {
|
|
265
258
|
throw new Error('This function is only available for libsql');
|
|
266
259
|
}
|
|
267
|
-
const db = OPSQLite.openSync(
|
|
268
|
-
const enhancedDb = enhanceDB(db,
|
|
260
|
+
const db = OPSQLite.openSync(params);
|
|
261
|
+
const enhancedDb = enhanceDB(db, params);
|
|
269
262
|
return enhancedDb;
|
|
270
263
|
};
|
|
271
264
|
|
|
272
|
-
/**
|
|
265
|
+
/**
|
|
266
|
+
* Open a remote connection via libsql to a turso db
|
|
273
267
|
* libsql needs to be enabled on your package.json
|
|
274
268
|
*/
|
|
275
269
|
exports.openSync = openSync;
|
|
276
|
-
const openRemote =
|
|
270
|
+
const openRemote = params => {
|
|
277
271
|
if (!isLibsql()) {
|
|
278
272
|
throw new Error('This function is only available for libsql');
|
|
279
273
|
}
|
|
280
|
-
const db = OPSQLite.openRemote(
|
|
281
|
-
const enhancedDb = enhanceDB(db,
|
|
274
|
+
const db = OPSQLite.openRemote(params);
|
|
275
|
+
const enhancedDb = enhanceDB(db, params);
|
|
282
276
|
return enhancedDb;
|
|
283
277
|
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Open a connection to a local sqlite or sqlcipher database
|
|
281
|
+
* If you want libsql remote or sync connections, use openSync or openRemote
|
|
282
|
+
*/
|
|
284
283
|
exports.openRemote = openRemote;
|
|
285
|
-
const open =
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
const open = params => {
|
|
285
|
+
if (params.location?.startsWith('file://')) {
|
|
286
|
+
console.warn("[op-sqlite] You are passing a path with 'file://' prefix, it's automatically removed");
|
|
287
|
+
params.location = params.location.substring(7);
|
|
288
|
+
}
|
|
289
|
+
const db = OPSQLite.open(params);
|
|
290
|
+
const enhancedDb = enhanceDB(db, params);
|
|
288
291
|
return enhancedDb;
|
|
289
292
|
};
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Moves the database from the assets folder to the default path (check the docs) or to a custom path
|
|
296
|
+
* It DOES NOT OVERWRITE the database if it already exists in the destination path
|
|
297
|
+
* if you want to overwrite the database, you need to pass the overwrite flag as true
|
|
298
|
+
* @param args object with the parameters for the operaiton
|
|
299
|
+
* @returns promise, rejects if failed to move the database, resolves if the operation was successful
|
|
300
|
+
*/
|
|
290
301
|
exports.open = open;
|
|
291
302
|
const moveAssetsDatabase = async args => {
|
|
292
303
|
return _reactNative.NativeModules.OPSQLite.moveAssetsDatabase(args);
|
|
293
304
|
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Used to load a dylib file that contains a sqlite 3 extension/plugin
|
|
308
|
+
* It returns the raw path to the actual file which then needs to be passed to the loadExtension function
|
|
309
|
+
* Check the docs for more information
|
|
310
|
+
* @param bundle the iOS bundle identifier of the .framework
|
|
311
|
+
* @param name the file name of the dylib file
|
|
312
|
+
* @returns
|
|
313
|
+
*/
|
|
294
314
|
exports.moveAssetsDatabase = moveAssetsDatabase;
|
|
295
315
|
const getDylibPath = (bundle, name) => {
|
|
296
316
|
return _reactNative.NativeModules.OPSQLite.getDylibPath(bundle, name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","global","__OPSQLiteProxy","NativeModules","OPSQLite","Error","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","global","__OPSQLiteProxy","NativeModules","OPSQLite","Error","installed","install","proxy","exports","IOS_DOCUMENT_PATH","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","ANDROID_FILES_PATH","ANDROID_EXTERNAL_FILES_PATH","getConstants","enhanceDB","db","options","lock","queue","inProgress","startNextTransaction","length","tx","shift","setImmediate","start","enhancedDb","delete","attach","detach","executeBatch","loadFile","updateHook","commitHook","rollbackHook","loadExtension","executeRaw","getDbPath","reactiveExecute","sync","close","executeWithHostObjects","query","params","sanitizedParams","map","p","ArrayBuffer","isView","buffer","executeSync","intermediateResult","rows","i","rawRows","row","rawRow","j","columnNames","columnName","value","push","res","execute","prepareStatement","stmt","bind","transaction","fn","isFinalized","name","url","commit","result","flushPendingReactiveQueries","rollback","run","executionError","rollbackError","Promise","resolve","reject","then","catch","openSync","isLibsql","openRemote","open","location","startsWith","console","warn","substring","moveAssetsDatabase","args","getDylibPath","bundle","isSQLCipher","isIOSEmbeeded","Platform","OS","isIOSEmbedded"],"sourceRoot":"../../src","s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