@op-engineering/op-sqlite 14.1.4 → 15.0.1
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/android/CMakeLists.txt +23 -62
- package/android/build.gradle +103 -163
- package/android/gradle.properties +5 -1
- package/android/src/main/AndroidManifest.xml +2 -1
- package/cpp/DBHostObject.cpp +17 -0
- package/lib/module/Storage.js +9 -2
- package/lib/module/Storage.js.map +1 -1
- package/lib/{commonjs/index.js → module/functions.js} +20 -82
- package/lib/module/functions.js.map +1 -0
- package/lib/module/index.js +3 -319
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Storage.d.ts +4 -0
- package/lib/typescript/src/Storage.d.ts.map +1 -1
- package/lib/typescript/src/functions.d.ts +61 -0
- package/lib/typescript/src/functions.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +14 -62
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/op-sqlite.podspec +2 -11
- package/package.json +48 -19
- package/src/Storage.ts +10 -2
- package/src/functions.ts +456 -0
- package/src/index.ts +14 -445
- package/android/.project +0 -17
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/android/src/paper/java/com/op/sqlite/NativeOPSQLiteSpec.java +0 -77
- package/lib/commonjs/NativeOPSQLite.js +0 -9
- package/lib/commonjs/NativeOPSQLite.js.map +0 -1
- package/lib/commonjs/Storage.js +0 -60
- package/lib/commonjs/Storage.js.map +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { NativeModules
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
|
|
2
3
|
export { Storage } from './Storage';
|
|
4
|
+
export * from './functions';
|
|
3
5
|
|
|
4
6
|
export type Scalar =
|
|
5
7
|
| string
|
|
@@ -82,7 +84,7 @@ export type Transaction = {
|
|
|
82
84
|
rollback: () => QueryResult;
|
|
83
85
|
};
|
|
84
86
|
|
|
85
|
-
type
|
|
87
|
+
export type _PendingTransaction = {
|
|
86
88
|
/*
|
|
87
89
|
* The start function should not throw or return a promise because the
|
|
88
90
|
* queue just calls it and does not monitor for failures or completions.
|
|
@@ -101,7 +103,7 @@ export type PreparedStatement = {
|
|
|
101
103
|
execute: () => Promise<QueryResult>;
|
|
102
104
|
};
|
|
103
105
|
|
|
104
|
-
type
|
|
106
|
+
export type _InternalDB = {
|
|
105
107
|
close: () => void;
|
|
106
108
|
delete: (location?: string) => void;
|
|
107
109
|
attach: (params: {
|
|
@@ -134,6 +136,7 @@ type InternalDB = {
|
|
|
134
136
|
prepareStatement: (query: string) => PreparedStatement;
|
|
135
137
|
loadExtension: (path: string, entryPoint?: string) => void;
|
|
136
138
|
executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
|
|
139
|
+
executeRawSync: (query: string, params?: Scalar[]) => any[];
|
|
137
140
|
getDbPath: (location?: string) => string;
|
|
138
141
|
reactiveExecute: (params: {
|
|
139
142
|
query: string;
|
|
@@ -262,6 +265,11 @@ export type DB = {
|
|
|
262
265
|
* It will be faster since a lot of repeated work is skipped and only the values you care about are returned
|
|
263
266
|
*/
|
|
264
267
|
executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
|
|
268
|
+
/**
|
|
269
|
+
* Same as `executeRaw` but it will block the JS thread and therefore your UI and should be used with caution
|
|
270
|
+
* It will return an array of arrays with just the values and not the keys
|
|
271
|
+
*/
|
|
272
|
+
executeRawSync: (query: string, params?: Scalar[]) => any[];
|
|
265
273
|
/**
|
|
266
274
|
* Get's the absolute path to the db file. Useful for debugging on local builds and for attaching the DB from users devices
|
|
267
275
|
*/
|
|
@@ -301,44 +309,14 @@ export type OPSQLiteProxy = {
|
|
|
301
309
|
name: string;
|
|
302
310
|
location?: string;
|
|
303
311
|
encryptionKey?: string;
|
|
304
|
-
}) =>
|
|
305
|
-
openRemote: (options: { url: string; authToken: string }) =>
|
|
306
|
-
openSync: (options: DBParams) =>
|
|
312
|
+
}) => _InternalDB;
|
|
313
|
+
openRemote: (options: { url: string; authToken: string }) => _InternalDB;
|
|
314
|
+
openSync: (options: DBParams) => _InternalDB;
|
|
307
315
|
isSQLCipher: () => boolean;
|
|
308
316
|
isLibsql: () => boolean;
|
|
309
317
|
isIOSEmbedded: () => boolean;
|
|
310
318
|
};
|
|
311
319
|
|
|
312
|
-
declare global {
|
|
313
|
-
var __OPSQLiteProxy: object | undefined;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (global.__OPSQLiteProxy == null) {
|
|
317
|
-
if (NativeModules.OPSQLite == null) {
|
|
318
|
-
throw new Error(
|
|
319
|
-
'Base module not found. Did you do a pod install/clear the gradle cache?'
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Call the synchronous blocking install() function
|
|
324
|
-
const installed = NativeModules.OPSQLite.install();
|
|
325
|
-
if (!installed) {
|
|
326
|
-
throw new Error(
|
|
327
|
-
`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`
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// Check again if the constructor now exists. If not, throw an error.
|
|
332
|
-
if (global.__OPSQLiteProxy == null) {
|
|
333
|
-
throw new Error(
|
|
334
|
-
'OPSqlite native object is not available. Something is wrong. Check the native logs for more information.'
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
const proxy = global.__OPSQLiteProxy;
|
|
340
|
-
const OPSQLite = proxy as OPSQLiteProxy;
|
|
341
|
-
|
|
342
320
|
export const {
|
|
343
321
|
IOS_DOCUMENT_PATH,
|
|
344
322
|
IOS_LIBRARY_PATH,
|
|
@@ -348,412 +326,3 @@ export const {
|
|
|
348
326
|
} = !!NativeModules.OPSQLite.getConstants
|
|
349
327
|
? NativeModules.OPSQLite.getConstants()
|
|
350
328
|
: NativeModules.OPSQLite;
|
|
351
|
-
|
|
352
|
-
function enhanceDB(db: InternalDB, options: DBParams): DB {
|
|
353
|
-
const lock = {
|
|
354
|
-
queue: [] as PendingTransaction[],
|
|
355
|
-
inProgress: false,
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
const startNextTransaction = () => {
|
|
359
|
-
if (lock.inProgress) {
|
|
360
|
-
// Transaction is already in process bail out
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (lock.queue.length) {
|
|
365
|
-
lock.inProgress = true;
|
|
366
|
-
const tx = lock.queue.shift();
|
|
367
|
-
|
|
368
|
-
if (!tx) {
|
|
369
|
-
throw new Error('Could not get a operation on database');
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
setImmediate(() => {
|
|
373
|
-
tx.start();
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
function sanitizeArrayBuffersInArray(
|
|
379
|
-
params?: any[] | any[][]
|
|
380
|
-
): any[] | undefined {
|
|
381
|
-
if (!params) {
|
|
382
|
-
return params;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return params.map((p) => {
|
|
386
|
-
if (Array.isArray(p)) {
|
|
387
|
-
return sanitizeArrayBuffersInArray(p);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
if (ArrayBuffer.isView(p)) {
|
|
391
|
-
return p.buffer;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return p;
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// spreading the object does not work with HostObjects (db)
|
|
399
|
-
// We need to manually assign the fields
|
|
400
|
-
let enhancedDb = {
|
|
401
|
-
delete: db.delete,
|
|
402
|
-
attach: db.attach,
|
|
403
|
-
detach: db.detach,
|
|
404
|
-
executeBatch: async (
|
|
405
|
-
commands: SQLBatchTuple[]
|
|
406
|
-
): Promise<BatchQueryResult> => {
|
|
407
|
-
const sanitizedCommands = commands.map(([query, params]) => {
|
|
408
|
-
if (params) {
|
|
409
|
-
return [query, sanitizeArrayBuffersInArray(params)];
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return [query];
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
async function run() {
|
|
416
|
-
try {
|
|
417
|
-
enhancedDb.executeSync('BEGIN TRANSACTION;');
|
|
418
|
-
|
|
419
|
-
let res = await db.executeBatch(sanitizedCommands as any[]);
|
|
420
|
-
|
|
421
|
-
enhancedDb.executeSync('COMMIT;');
|
|
422
|
-
|
|
423
|
-
return res;
|
|
424
|
-
} catch (executionError) {
|
|
425
|
-
try {
|
|
426
|
-
enhancedDb.executeSync('ROLLBACK;');
|
|
427
|
-
} catch (rollbackError) {
|
|
428
|
-
throw rollbackError;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
throw executionError;
|
|
432
|
-
} finally {
|
|
433
|
-
lock.inProgress = false;
|
|
434
|
-
startNextTransaction();
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return await new Promise((resolve, reject) => {
|
|
439
|
-
const tx: PendingTransaction = {
|
|
440
|
-
start: () => {
|
|
441
|
-
run().then(resolve).catch(reject);
|
|
442
|
-
},
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
lock.queue.push(tx);
|
|
446
|
-
startNextTransaction();
|
|
447
|
-
});
|
|
448
|
-
},
|
|
449
|
-
loadFile: db.loadFile,
|
|
450
|
-
updateHook: db.updateHook,
|
|
451
|
-
commitHook: db.commitHook,
|
|
452
|
-
rollbackHook: db.rollbackHook,
|
|
453
|
-
loadExtension: db.loadExtension,
|
|
454
|
-
getDbPath: db.getDbPath,
|
|
455
|
-
reactiveExecute: db.reactiveExecute,
|
|
456
|
-
sync: db.sync,
|
|
457
|
-
close: db.close,
|
|
458
|
-
executeWithHostObjects: async (
|
|
459
|
-
query: string,
|
|
460
|
-
params?: Scalar[]
|
|
461
|
-
): Promise<QueryResult> => {
|
|
462
|
-
const sanitizedParams = sanitizeArrayBuffersInArray(params);
|
|
463
|
-
|
|
464
|
-
return sanitizedParams
|
|
465
|
-
? await db.executeWithHostObjects(query, sanitizedParams as Scalar[])
|
|
466
|
-
: await db.executeWithHostObjects(query);
|
|
467
|
-
},
|
|
468
|
-
executeRaw: async (query: string, params?: Scalar[]) => {
|
|
469
|
-
const sanitizedParams = sanitizeArrayBuffersInArray(params);
|
|
470
|
-
|
|
471
|
-
return db.executeRaw(query, sanitizedParams as Scalar[]);
|
|
472
|
-
},
|
|
473
|
-
// Wrapper for executeRaw, drizzleORM uses this function
|
|
474
|
-
// at some point I changed the API but they did not pin their dependency to a specific version
|
|
475
|
-
// so re-inserting this so it starts working again
|
|
476
|
-
executeRawAsync: async (query: string, params?: Scalar[]) => {
|
|
477
|
-
const sanitizedParams = sanitizeArrayBuffersInArray(params);
|
|
478
|
-
|
|
479
|
-
return db.executeRaw(query, sanitizedParams as Scalar[]);
|
|
480
|
-
},
|
|
481
|
-
executeSync: (query: string, params?: Scalar[]): QueryResult => {
|
|
482
|
-
const sanitizedParams = sanitizeArrayBuffersInArray(params);
|
|
483
|
-
|
|
484
|
-
let intermediateResult = sanitizedParams
|
|
485
|
-
? db.executeSync(query, sanitizedParams as Scalar[])
|
|
486
|
-
: db.executeSync(query);
|
|
487
|
-
|
|
488
|
-
let rows: Record<string, Scalar>[] = [];
|
|
489
|
-
for (let i = 0; i < (intermediateResult.rawRows?.length ?? 0); i++) {
|
|
490
|
-
let row: Record<string, Scalar> = {};
|
|
491
|
-
let rawRow = intermediateResult.rawRows![i]!;
|
|
492
|
-
for (let j = 0; j < intermediateResult.columnNames!.length; j++) {
|
|
493
|
-
let columnName = intermediateResult.columnNames![j]!;
|
|
494
|
-
let value = rawRow[j]!;
|
|
495
|
-
|
|
496
|
-
row[columnName] = value;
|
|
497
|
-
}
|
|
498
|
-
rows.push(row);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
let res = {
|
|
502
|
-
...intermediateResult,
|
|
503
|
-
rows,
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
delete res.rawRows;
|
|
507
|
-
|
|
508
|
-
return res;
|
|
509
|
-
},
|
|
510
|
-
executeAsync: async (
|
|
511
|
-
query: string,
|
|
512
|
-
params?: Scalar[] | undefined
|
|
513
|
-
): Promise<QueryResult> => {
|
|
514
|
-
return db.execute(query, params);
|
|
515
|
-
},
|
|
516
|
-
execute: async (
|
|
517
|
-
query: string,
|
|
518
|
-
params?: Scalar[] | undefined
|
|
519
|
-
): Promise<QueryResult> => {
|
|
520
|
-
const sanitizedParams = sanitizeArrayBuffersInArray(params);
|
|
521
|
-
|
|
522
|
-
let intermediateResult = await db.execute(
|
|
523
|
-
query,
|
|
524
|
-
sanitizedParams as Scalar[]
|
|
525
|
-
);
|
|
526
|
-
|
|
527
|
-
let rows: Record<string, Scalar>[] = [];
|
|
528
|
-
for (let i = 0; i < (intermediateResult.rawRows?.length ?? 0); i++) {
|
|
529
|
-
let row: Record<string, Scalar> = {};
|
|
530
|
-
let rawRow = intermediateResult.rawRows![i]!;
|
|
531
|
-
for (let j = 0; j < intermediateResult.columnNames!.length; j++) {
|
|
532
|
-
let columnName = intermediateResult.columnNames![j]!;
|
|
533
|
-
let value = rawRow[j]!;
|
|
534
|
-
|
|
535
|
-
row[columnName] = value;
|
|
536
|
-
}
|
|
537
|
-
rows.push(row);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
let res = {
|
|
541
|
-
...intermediateResult,
|
|
542
|
-
rows,
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
delete res.rawRows;
|
|
546
|
-
|
|
547
|
-
return res;
|
|
548
|
-
},
|
|
549
|
-
prepareStatement: (query: string) => {
|
|
550
|
-
const stmt = db.prepareStatement(query);
|
|
551
|
-
|
|
552
|
-
return {
|
|
553
|
-
bindSync: (params: Scalar[]) => {
|
|
554
|
-
const sanitizedParams = sanitizeArrayBuffersInArray(params);
|
|
555
|
-
|
|
556
|
-
stmt.bindSync(sanitizedParams!);
|
|
557
|
-
},
|
|
558
|
-
bind: async (params: Scalar[]) => {
|
|
559
|
-
const sanitizedParams = sanitizeArrayBuffersInArray(params);
|
|
560
|
-
|
|
561
|
-
await stmt.bind(sanitizedParams!);
|
|
562
|
-
},
|
|
563
|
-
execute: stmt.execute,
|
|
564
|
-
};
|
|
565
|
-
},
|
|
566
|
-
transaction: async (
|
|
567
|
-
fn: (tx: Transaction) => Promise<void>
|
|
568
|
-
): Promise<void> => {
|
|
569
|
-
let isFinalized = false;
|
|
570
|
-
|
|
571
|
-
const execute = async (query: string, params?: Scalar[]) => {
|
|
572
|
-
if (isFinalized) {
|
|
573
|
-
throw Error(
|
|
574
|
-
`OP-Sqlite Error: Database: ${
|
|
575
|
-
options.name || options.url
|
|
576
|
-
}. Cannot execute query on finalized transaction`
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
return await enhancedDb.execute(query, params);
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
const commit = async (): Promise<QueryResult> => {
|
|
583
|
-
if (isFinalized) {
|
|
584
|
-
throw Error(
|
|
585
|
-
`OP-Sqlite Error: Database: ${
|
|
586
|
-
options.name || options.url
|
|
587
|
-
}. Cannot execute query on finalized transaction`
|
|
588
|
-
);
|
|
589
|
-
}
|
|
590
|
-
const result = enhancedDb.executeSync('COMMIT;');
|
|
591
|
-
|
|
592
|
-
await db.flushPendingReactiveQueries();
|
|
593
|
-
|
|
594
|
-
isFinalized = true;
|
|
595
|
-
return result;
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
const rollback = (): QueryResult => {
|
|
599
|
-
if (isFinalized) {
|
|
600
|
-
throw Error(
|
|
601
|
-
`OP-Sqlite Error: Database: ${
|
|
602
|
-
options.name || options.url
|
|
603
|
-
}. Cannot execute query on finalized transaction`
|
|
604
|
-
);
|
|
605
|
-
}
|
|
606
|
-
const result = enhancedDb.executeSync('ROLLBACK;');
|
|
607
|
-
isFinalized = true;
|
|
608
|
-
return result;
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
async function run() {
|
|
612
|
-
try {
|
|
613
|
-
enhancedDb.executeSync('BEGIN TRANSACTION;');
|
|
614
|
-
|
|
615
|
-
await fn({
|
|
616
|
-
commit,
|
|
617
|
-
execute,
|
|
618
|
-
rollback,
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
if (!isFinalized) {
|
|
622
|
-
commit();
|
|
623
|
-
}
|
|
624
|
-
} catch (executionError) {
|
|
625
|
-
if (!isFinalized) {
|
|
626
|
-
try {
|
|
627
|
-
rollback();
|
|
628
|
-
} catch (rollbackError) {
|
|
629
|
-
throw rollbackError;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
throw executionError;
|
|
634
|
-
} finally {
|
|
635
|
-
lock.inProgress = false;
|
|
636
|
-
isFinalized = false;
|
|
637
|
-
startNextTransaction();
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
return await new Promise((resolve, reject) => {
|
|
642
|
-
const tx: PendingTransaction = {
|
|
643
|
-
start: () => {
|
|
644
|
-
run().then(resolve).catch(reject);
|
|
645
|
-
},
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
lock.queue.push(tx);
|
|
649
|
-
startNextTransaction();
|
|
650
|
-
});
|
|
651
|
-
},
|
|
652
|
-
};
|
|
653
|
-
|
|
654
|
-
return enhancedDb;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* Open a replicating connection via libsql to a turso db
|
|
659
|
-
* libsql needs to be enabled on your package.json
|
|
660
|
-
*/
|
|
661
|
-
export const openSync = (params: {
|
|
662
|
-
url: string;
|
|
663
|
-
authToken: string;
|
|
664
|
-
name: string;
|
|
665
|
-
location?: string;
|
|
666
|
-
libsqlSyncInterval?: number;
|
|
667
|
-
libsqlOffline?: boolean;
|
|
668
|
-
encryptionKey?: string;
|
|
669
|
-
remoteEncryptionKey?: string;
|
|
670
|
-
}): DB => {
|
|
671
|
-
if (!isLibsql()) {
|
|
672
|
-
throw new Error('This function is only available for libsql');
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const db = OPSQLite.openSync(params);
|
|
676
|
-
const enhancedDb = enhanceDB(db, params);
|
|
677
|
-
|
|
678
|
-
return enhancedDb;
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Open a remote connection via libsql to a turso db
|
|
683
|
-
* libsql needs to be enabled on your package.json
|
|
684
|
-
*/
|
|
685
|
-
export const openRemote = (params: { url: string; authToken: string }): DB => {
|
|
686
|
-
if (!isLibsql()) {
|
|
687
|
-
throw new Error('This function is only available for libsql');
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
const db = OPSQLite.openRemote(params);
|
|
691
|
-
const enhancedDb = enhanceDB(db, params);
|
|
692
|
-
|
|
693
|
-
return enhancedDb;
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* Open a connection to a local sqlite or sqlcipher database
|
|
698
|
-
* If you want libsql remote or sync connections, use openSync or openRemote
|
|
699
|
-
*/
|
|
700
|
-
export const open = (params: {
|
|
701
|
-
name: string;
|
|
702
|
-
location?: string;
|
|
703
|
-
encryptionKey?: string;
|
|
704
|
-
}): DB => {
|
|
705
|
-
if (params.location?.startsWith('file://')) {
|
|
706
|
-
console.warn(
|
|
707
|
-
"[op-sqlite] You are passing a path with 'file://' prefix, it's automatically removed"
|
|
708
|
-
);
|
|
709
|
-
params.location = params.location.substring(7);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
const db = OPSQLite.open(params);
|
|
713
|
-
const enhancedDb = enhanceDB(db, params);
|
|
714
|
-
|
|
715
|
-
return enhancedDb;
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
* Moves the database from the assets folder to the default path (check the docs) or to a custom path
|
|
720
|
-
* It DOES NOT OVERWRITE the database if it already exists in the destination path
|
|
721
|
-
* if you want to overwrite the database, you need to pass the overwrite flag as true
|
|
722
|
-
* @param args object with the parameters for the operaiton
|
|
723
|
-
* @returns promise, rejects if failed to move the database, resolves if the operation was successful
|
|
724
|
-
*/
|
|
725
|
-
export const moveAssetsDatabase = async (args: {
|
|
726
|
-
filename: string;
|
|
727
|
-
path?: string;
|
|
728
|
-
overwrite?: boolean;
|
|
729
|
-
}): Promise<boolean> => {
|
|
730
|
-
return NativeModules.OPSQLite.moveAssetsDatabase(args);
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
* Used to load a dylib file that contains a sqlite 3 extension/plugin
|
|
735
|
-
* It returns the raw path to the actual file which then needs to be passed to the loadExtension function
|
|
736
|
-
* Check the docs for more information
|
|
737
|
-
* @param bundle the iOS bundle identifier of the .framework
|
|
738
|
-
* @param name the file name of the dylib file
|
|
739
|
-
* @returns
|
|
740
|
-
*/
|
|
741
|
-
export const getDylibPath = (bundle: string, name: string): string => {
|
|
742
|
-
return NativeModules.OPSQLite.getDylibPath(bundle, name);
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
export const isSQLCipher = (): boolean => {
|
|
746
|
-
return OPSQLite.isSQLCipher();
|
|
747
|
-
};
|
|
748
|
-
|
|
749
|
-
export const isLibsql = (): boolean => {
|
|
750
|
-
return OPSQLite.isLibsql();
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
export const isIOSEmbeeded = (): boolean => {
|
|
754
|
-
if (Platform.OS !== 'ios') {
|
|
755
|
-
return false;
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
return OPSQLite.isIOSEmbedded();
|
|
759
|
-
};
|
package/android/.project
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<projectDescription>
|
|
3
|
-
<name>android_</name>
|
|
4
|
-
<comment>Project android_ created by Buildship.</comment>
|
|
5
|
-
<projects>
|
|
6
|
-
</projects>
|
|
7
|
-
<buildSpec>
|
|
8
|
-
<buildCommand>
|
|
9
|
-
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
|
10
|
-
<arguments>
|
|
11
|
-
</arguments>
|
|
12
|
-
</buildCommand>
|
|
13
|
-
</buildSpec>
|
|
14
|
-
<natures>
|
|
15
|
-
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
|
16
|
-
</natures>
|
|
17
|
-
</projectDescription>
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
arguments=
|
|
2
|
-
auto.sync=false
|
|
3
|
-
build.scans.enabled=false
|
|
4
|
-
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0))
|
|
5
|
-
connection.project.dir=
|
|
6
|
-
eclipse.preferences.version=1
|
|
7
|
-
gradle.user.home=
|
|
8
|
-
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
|
|
9
|
-
jvm.arguments=
|
|
10
|
-
offline.mode=false
|
|
11
|
-
override.workspace.settings=true
|
|
12
|
-
show.console.view=true
|
|
13
|
-
show.executions.view=true
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
-
*
|
|
5
|
-
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
-
* once the code is regenerated.
|
|
7
|
-
*
|
|
8
|
-
* @generated by codegen project: GenerateModuleJavaSpec.js
|
|
9
|
-
*
|
|
10
|
-
* @nolint
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
package com.op.sqlite;
|
|
14
|
-
|
|
15
|
-
import com.facebook.proguard.annotations.DoNotStrip;
|
|
16
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
17
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
18
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
19
|
-
import com.facebook.react.common.build.ReactBuildConfig;
|
|
20
|
-
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
21
|
-
import java.util.Arrays;
|
|
22
|
-
import java.util.HashSet;
|
|
23
|
-
import java.util.Map;
|
|
24
|
-
import java.util.Set;
|
|
25
|
-
import javax.annotation.Nonnull;
|
|
26
|
-
import javax.annotation.Nullable;
|
|
27
|
-
|
|
28
|
-
public abstract class NativeOPSQLiteSpec extends ReactContextBaseJavaModule implements TurboModule {
|
|
29
|
-
public static final String NAME = "OPSQLite";
|
|
30
|
-
|
|
31
|
-
public NativeOPSQLiteSpec(ReactApplicationContext reactContext) {
|
|
32
|
-
super(reactContext);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Override
|
|
36
|
-
public @Nonnull String getName() {
|
|
37
|
-
return NAME;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected abstract Map<String, Object> getTypedExportedConstants();
|
|
41
|
-
|
|
42
|
-
@Override
|
|
43
|
-
@DoNotStrip
|
|
44
|
-
public final @Nullable Map<String, Object> getConstants() {
|
|
45
|
-
Map<String, Object> constants = getTypedExportedConstants();
|
|
46
|
-
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
|
|
47
|
-
Set<String> obligatoryFlowConstants = new HashSet<>(Arrays.asList(
|
|
48
|
-
"ANDROID_DATABASE_PATH",
|
|
49
|
-
"ANDROID_EXTERNAL_FILES_PATH",
|
|
50
|
-
"ANDROID_FILES_PATH",
|
|
51
|
-
"IOS_DOCUMENT_PATH",
|
|
52
|
-
"IOS_LIBRARY_PATH"
|
|
53
|
-
));
|
|
54
|
-
Set<String> optionalFlowConstants = new HashSet<>();
|
|
55
|
-
Set<String> undeclaredConstants = new HashSet<>(constants.keySet());
|
|
56
|
-
undeclaredConstants.removeAll(obligatoryFlowConstants);
|
|
57
|
-
undeclaredConstants.removeAll(optionalFlowConstants);
|
|
58
|
-
if (!undeclaredConstants.isEmpty()) {
|
|
59
|
-
throw new IllegalStateException(String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
|
|
60
|
-
}
|
|
61
|
-
undeclaredConstants = obligatoryFlowConstants;
|
|
62
|
-
undeclaredConstants.removeAll(constants.keySet());
|
|
63
|
-
if (!undeclaredConstants.isEmpty()) {
|
|
64
|
-
throw new IllegalStateException(String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return constants;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
71
|
-
@DoNotStrip
|
|
72
|
-
public abstract boolean install();
|
|
73
|
-
|
|
74
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
75
|
-
@DoNotStrip
|
|
76
|
-
public abstract boolean moveAssetsDatabase(String name, String extension);
|
|
77
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
|
-
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('OPSQLite');
|
|
9
|
-
//# sourceMappingURL=NativeOPSQLite.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOPSQLite.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAqE,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAgBtDC,gCAAmB,CAACC,YAAY,CAAO,UAAU,CAAC","ignoreList":[]}
|
package/lib/commonjs/Storage.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Storage = void 0;
|
|
7
|
-
var _index = require("./index");
|
|
8
|
-
/**
|
|
9
|
-
* Creates a new async-storage api compatible instance.
|
|
10
|
-
* The encryption key is only used when compiled against the SQLCipher version of op-sqlite.
|
|
11
|
-
*/
|
|
12
|
-
class Storage {
|
|
13
|
-
constructor(options) {
|
|
14
|
-
this.db = (0, _index.open)({
|
|
15
|
-
...options,
|
|
16
|
-
name: '__opsqlite_storage'
|
|
17
|
-
});
|
|
18
|
-
this.db.executeSync('PRAGMA mmap_size=268435456');
|
|
19
|
-
this.db.executeSync('CREATE TABLE IF NOT EXISTS storage (key TEXT PRIMARY KEY, value TEXT) WITHOUT ROWID');
|
|
20
|
-
}
|
|
21
|
-
async getItem(key) {
|
|
22
|
-
const result = await this.db.execute('SELECT value FROM storage WHERE key = ?', [key]);
|
|
23
|
-
let value = result.rows[0]?.value;
|
|
24
|
-
if (typeof value !== 'undefined' && typeof value !== 'string') {
|
|
25
|
-
throw new Error('Value must be a string or undefined');
|
|
26
|
-
}
|
|
27
|
-
return value;
|
|
28
|
-
}
|
|
29
|
-
getItemSync(key) {
|
|
30
|
-
const result = this.db.executeSync('SELECT value FROM storage WHERE key = ?', [key]);
|
|
31
|
-
let value = result.rows[0]?.value;
|
|
32
|
-
if (typeof value !== 'undefined' && typeof value !== 'string') {
|
|
33
|
-
throw new Error('Value must be a string or undefined');
|
|
34
|
-
}
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
async setItem(key, value) {
|
|
38
|
-
await this.db.execute('INSERT OR REPLACE INTO storage (key, value) VALUES (?, ?)', [key, value.toString()]);
|
|
39
|
-
}
|
|
40
|
-
setItemSync(key, value) {
|
|
41
|
-
this.db.executeSync('INSERT OR REPLACE INTO storage (key, value) VALUES (?, ?)', [key, value.toString()]);
|
|
42
|
-
}
|
|
43
|
-
async removeItem(key) {
|
|
44
|
-
await this.db.execute('DELETE FROM storage WHERE key = ?', [key]);
|
|
45
|
-
}
|
|
46
|
-
removeItemSync(key) {
|
|
47
|
-
this.db.executeSync('DELETE FROM storage WHERE key = ?', [key]);
|
|
48
|
-
}
|
|
49
|
-
async clear() {
|
|
50
|
-
await this.db.execute('DELETE FROM storage');
|
|
51
|
-
}
|
|
52
|
-
clearSync() {
|
|
53
|
-
this.db.executeSync('DELETE FROM storage');
|
|
54
|
-
}
|
|
55
|
-
getAllKeys() {
|
|
56
|
-
return this.db.executeSync('SELECT key FROM storage').rows.map(row => row.key);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.Storage = Storage;
|
|
60
|
-
//# sourceMappingURL=Storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_index","require","Storage","constructor","options","db","open","name","executeSync","getItem","key","result","execute","value","rows","Error","getItemSync","setItem","toString","setItemSync","removeItem","removeItemSync","clear","clearSync","getAllKeys","map","row","exports"],"sourceRoot":"../../src","sources":["Storage.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAOA;AACA;AACA;AACA;AACO,MAAMC,OAAO,CAAC;EAGnBC,WAAWA,CAACC,OAAuB,EAAE;IACnC,IAAI,CAACC,EAAE,GAAG,IAAAC,WAAI,EAAC;MAAE,GAAGF,OAAO;MAAEG,IAAI,EAAE;IAAqB,CAAC,CAAC;IAC1D,IAAI,CAACF,EAAE,CAACG,WAAW,CAAC,4BAA4B,CAAC;IACjD,IAAI,CAACH,EAAE,CAACG,WAAW,CACjB,qFACF,CAAC;EACH;EAEA,MAAMC,OAAOA,CAACC,GAAW,EAA+B;IACtD,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACN,EAAE,CAACO,OAAO,CAClC,yCAAyC,EACzC,CAACF,GAAG,CACN,CAAC;IAED,IAAIG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAAC,CAAC,CAAC,EAAED,KAAK;IACjC,IAAI,OAAOA,KAAK,KAAK,WAAW,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7D,MAAM,IAAIE,KAAK,CAAC,qCAAqC,CAAC;IACxD;IACA,OAAOF,KAAK;EACd;EAEAG,WAAWA,CAACN,GAAW,EAAsB;IAC3C,MAAMC,MAAM,GAAG,IAAI,CAACN,EAAE,CAACG,WAAW,CAChC,yCAAyC,EACzC,CAACE,GAAG,CACN,CAAC;IAED,IAAIG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAAC,CAAC,CAAC,EAAED,KAAK;IACjC,IAAI,OAAOA,KAAK,KAAK,WAAW,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7D,MAAM,IAAIE,KAAK,CAAC,qCAAqC,CAAC;IACxD;IAEA,OAAOF,KAAK;EACd;EAEA,MAAMI,OAAOA,CAACP,GAAW,EAAEG,KAAa,EAAE;IACxC,MAAM,IAAI,CAACR,EAAE,CAACO,OAAO,CACnB,2DAA2D,EAC3D,CAACF,GAAG,EAAEG,KAAK,CAACK,QAAQ,CAAC,CAAC,CACxB,CAAC;EACH;EAEAC,WAAWA,CAACT,GAAW,EAAEG,KAAa,EAAE;IACtC,IAAI,CAACR,EAAE,CAACG,WAAW,CACjB,2DAA2D,EAC3D,CAACE,GAAG,EAAEG,KAAK,CAACK,QAAQ,CAAC,CAAC,CACxB,CAAC;EACH;EAEA,MAAME,UAAUA,CAACV,GAAW,EAAE;IAC5B,MAAM,IAAI,CAACL,EAAE,CAACO,OAAO,CAAC,mCAAmC,EAAE,CAACF,GAAG,CAAC,CAAC;EACnE;EAEAW,cAAcA,CAACX,GAAW,EAAE;IAC1B,IAAI,CAACL,EAAE,CAACG,WAAW,CAAC,mCAAmC,EAAE,CAACE,GAAG,CAAC,CAAC;EACjE;EAEA,MAAMY,KAAKA,CAAA,EAAG;IACZ,MAAM,IAAI,CAACjB,EAAE,CAACO,OAAO,CAAC,qBAAqB,CAAC;EAC9C;EAEAW,SAASA,CAAA,EAAG;IACV,IAAI,CAAClB,EAAE,CAACG,WAAW,CAAC,qBAAqB,CAAC;EAC5C;EAEAgB,UAAUA,CAAA,EAAG;IACX,OAAO,IAAI,CAACnB,EAAE,CACXG,WAAW,CAAC,yBAAyB,CAAC,CACtCM,IAAI,CAACW,GAAG,CAAEC,GAAQ,IAAKA,GAAG,CAAChB,GAAG,CAAC;EACpC;AACF;AAACiB,OAAA,CAAAzB,OAAA,GAAAA,OAAA","ignoreList":[]}
|