@op-engineering/op-sqlite 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -2
- package/cpp/bindings.cpp +11 -2
- package/cpp/bridge.cpp +2 -2
- package/cpp/bridge.h +1 -1
- 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
|
@@ -48,6 +48,8 @@ The library creates/opens databases by appending the passed name plus, the [libr
|
|
|
48
48
|
If you have an existing database file you want to load you can navigate from these directories using dot notation. e.g.:
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
+
import { open } from '@op-engineering/op-sqlite';
|
|
52
|
+
|
|
51
53
|
const largeDb = open({
|
|
52
54
|
name: 'largeDB',
|
|
53
55
|
location: '../files/databases',
|
|
@@ -56,7 +58,20 @@ const largeDb = open({
|
|
|
56
58
|
|
|
57
59
|
Note that on iOS the file system is sand-boxed, so you cannot access files/directories outside your app bundle directories.
|
|
58
60
|
|
|
59
|
-
##
|
|
61
|
+
## In memory
|
|
62
|
+
|
|
63
|
+
Using SQLite in memory mode is supported:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { open } from '@op-engineering/op-sqlite';
|
|
67
|
+
|
|
68
|
+
const largeDb = open({
|
|
69
|
+
name: 'inMemoryDb',
|
|
70
|
+
inMemory: true,
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
# API
|
|
60
75
|
|
|
61
76
|
```typescript
|
|
62
77
|
import {open} from '@op-engineering/op-sqlite'
|
|
@@ -89,7 +104,7 @@ The basic query is **synchronous**, it will block rendering on large operations,
|
|
|
89
104
|
import { open } from '@op-engineering/op-sqlite';
|
|
90
105
|
|
|
91
106
|
try {
|
|
92
|
-
const db = open('myDb.sqlite');
|
|
107
|
+
const db = open({ name: 'myDb.sqlite' });
|
|
93
108
|
|
|
94
109
|
let { rows } = db.execute('SELECT somevalue FROM sometable');
|
|
95
110
|
|
package/cpp/bindings.cpp
CHANGED
|
@@ -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
|
{
|
package/cpp/bridge.cpp
CHANGED
|
@@ -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
|
|
package/cpp/bridge.h
CHANGED
|
@@ -11,7 +11,7 @@ namespace osp {
|
|
|
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
|
|
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
|
+
osp::install(runtime, callInvoker, [documentPath UTF8String]);
|
|
55
|
+
|
|
56
|
+
NSLog(@"OP-SQLite initialized");
|
|
57
|
+
return @true;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
- (void)invalidate {
|
|
60
|
-
|
|
61
|
+
osp::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,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,MAAM,IAAII,KAAK,CACb,yIAAyI,CAC1I;EACH;AACF;AAEA,MAAMI,KAAK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AE,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,MAAM,IAAII,KAAK,CACb,yIAAyI,CAC1I;EACH;AACF;AAEA,MAAMI,KAAK,GAAGT,MAAM,CAACC,eAAe;AAC7B,MAAMG,QAAQ,GAAGK,KAAgB;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AATA;AAyHA,MAAMC,KAGL,GAAG,CAAC,CAAC;;AAEN;;AAEA;AACA,MAAMC,kBAAkB,GAAIH,MAAmB,IAAW;EACxD;EACA,IAAIA,MAAM,CAACI,IAAI,IAAI,IAAI,EAAE;IACvBJ,MAAM,CAACI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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,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,IAAI,EAAE;IAClC,MAAM,IAAIG,KAAK,CACb,yIAAyI,CAC1I;EACH;AACF;AAEA,MAAMI,KAAK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AO,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,IAAI,EAAE;IAClC,MAAM,IAAIG,KAAK,CACb,yIAAyI,CAC1I;EACH;AACF;AAEA,MAAMI,KAAK,GAAGR,MAAM,CAACC,eAAe;AACpC,OAAO,MAAME,QAAQ,GAAGK,KAAgB;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgHA,MAAMC,KAGL,GAAG,CAAC,CAAC;;AAEN;;AAEA;AACA,MAAMC,kBAAkB,GAAIH,MAAmB,IAAW;EACxD;EACA,IAAIA,MAAM,CAACI,IAAI,IAAI,IAAI,EAAE;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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),
|