@capacitor-community/sqlite 6.0.1 → 6.0.2

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.
Files changed (32) hide show
  1. package/README.md +71 -91
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +12 -16
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +2 -1
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +73 -69
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDownloadFromHTTP.java +13 -12
  7. package/dist/esm/definitions.js +1 -3
  8. package/dist/esm/definitions.js.map +1 -1
  9. package/dist/esm/index.js +1 -1
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/web.js.map +1 -1
  12. package/dist/plugin.cjs.js +2 -4
  13. package/dist/plugin.cjs.js.map +1 -1
  14. package/dist/plugin.js +2 -4
  15. package/dist/plugin.js.map +1 -1
  16. package/electron/dist/plugin.js +56 -144
  17. package/electron/dist/plugin.js.map +1 -1
  18. package/electron/rollup.config.js +1 -3
  19. package/ios/Plugin/CapacitorSQLite.swift +5 -5
  20. package/ios/Plugin/Database.swift +1 -1
  21. package/ios/Plugin/ImportExportJson/ExportToJson.swift +7 -7
  22. package/ios/Plugin/Models/KeychainServices.swift +1 -1
  23. package/ios/Plugin/Utils/UtilsBinding.swift +2 -2
  24. package/ios/Plugin/Utils/UtilsDelete.swift +4 -4
  25. package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +2 -2
  26. package/ios/Plugin/Utils/UtilsDrop.swift +1 -1
  27. package/ios/Plugin/Utils/UtilsSQLCipher.swift +17 -17
  28. package/ios/Plugin/Utils/UtilsSQLStatement.swift +120 -121
  29. package/package.json +23 -21
  30. package/src/definitions.ts +44 -128
  31. package/src/index.ts +4 -8
  32. package/src/web.ts +60 -132
@@ -376,18 +376,14 @@ export interface CapacitorSQLitePlugin {
376
376
  * @returns Promise<capSQLiteResult>
377
377
  * @since 3.0.0-beta.11
378
378
  */
379
- checkConnectionsConsistency(
380
- options: capAllConnectionsOptions,
381
- ): Promise<capSQLiteResult>;
379
+ checkConnectionsConsistency(options: capAllConnectionsOptions): Promise<capSQLiteResult>;
382
380
  /**
383
381
  * get a non conformed database path
384
382
  * @param options capNCDatabasePathOptions
385
383
  * @return Promise<capNCDatabasePathResult>
386
384
  * @since 3.3.3-1
387
385
  */
388
- getNCDatabasePath(
389
- options: capNCDatabasePathOptions,
390
- ): Promise<capNCDatabasePathResult>;
386
+ getNCDatabasePath(options: capNCDatabasePathOptions): Promise<capNCDatabasePathResult>;
391
387
  /**
392
388
  * create a non conformed database connection
393
389
  * @param options capNCConnectionOptions
@@ -1117,10 +1113,7 @@ export interface ISQLiteConnection {
1117
1113
  * @returns Promise<void>
1118
1114
  * @since 3.0.0-beta.13
1119
1115
  */
1120
- changeEncryptionSecret(
1121
- passphrase: string,
1122
- oldpassphrase: string,
1123
- ): Promise<void>;
1116
+ changeEncryptionSecret(passphrase: string, oldpassphrase: string): Promise<void>;
1124
1117
  /**
1125
1118
  * Clear the passphrase in a secure store
1126
1119
  * @returns Promise<void>
@@ -1137,14 +1130,11 @@ export interface ISQLiteConnection {
1137
1130
  /**
1138
1131
  * Add the upgrade Statement for database version upgrading
1139
1132
  * @param database
1140
- * @param upgrade @since 5.6.4
1133
+ * @param upgrade @since 5.6.4
1141
1134
  * @returns Promise<void>
1142
1135
  * @since 2.9.0 refactor
1143
1136
  */
1144
- addUpgradeStatement(
1145
- database: string,
1146
- upgrade: capSQLiteVersionUpgrade[]
1147
- ): Promise<void>;
1137
+ addUpgradeStatement(database: string, upgrade: capSQLiteVersionUpgrade[]): Promise<void>;
1148
1138
  /**
1149
1139
  * Create a connection to a database
1150
1140
  * @param database
@@ -1160,7 +1150,7 @@ export interface ISQLiteConnection {
1160
1150
  encrypted: boolean,
1161
1151
  mode: string,
1162
1152
  version: number,
1163
- readonly: boolean,
1153
+ readonly: boolean
1164
1154
  ): Promise<SQLiteDBConnection>;
1165
1155
  /**
1166
1156
  * Check if a connection exists
@@ -1177,10 +1167,7 @@ export interface ISQLiteConnection {
1177
1167
  * @returns Promise<SQLiteDBConnection>
1178
1168
  * @since 2.9.0 refactor
1179
1169
  */
1180
- retrieveConnection(
1181
- database: string,
1182
- readonly: boolean,
1183
- ): Promise<SQLiteDBConnection>;
1170
+ retrieveConnection(database: string, readonly: boolean): Promise<SQLiteDBConnection>;
1184
1171
  /**
1185
1172
  * Retrieve all database connections
1186
1173
  * @returns Promise<Map<string, SQLiteDBConnection>>
@@ -1216,10 +1203,7 @@ export interface ISQLiteConnection {
1216
1203
  * @returns Promise<capNCDatabasePathResult>
1217
1204
  * @since 3.3.3-1
1218
1205
  */
1219
- getNCDatabasePath(
1220
- path: string,
1221
- database: string,
1222
- ): Promise<capNCDatabasePathResult>;
1206
+ getNCDatabasePath(path: string, database: string): Promise<capNCDatabasePathResult>;
1223
1207
  /**
1224
1208
  * Create a non-conformed database connection
1225
1209
  * @param databasePath
@@ -1227,10 +1211,7 @@ export interface ISQLiteConnection {
1227
1211
  * @returns Promise<SQLiteDBConnection>
1228
1212
  * @since 3.3.3-1
1229
1213
  */
1230
- createNCConnection(
1231
- databasePath: string,
1232
- version: number,
1233
- ): Promise<SQLiteDBConnection>;
1214
+ createNCConnection(databasePath: string, version: number): Promise<SQLiteDBConnection>;
1234
1215
  /**
1235
1216
  * Close a non-conformed database connection
1236
1217
  * @param databasePath
@@ -1351,10 +1332,7 @@ export interface ISQLiteConnection {
1351
1332
  * @param folderPath the origin from where to move the databases
1352
1333
  * @param dbNameList the names of the databases to move, check out the getMigratableDbList to get a list, an empty list will result in copying all the databases with '.db' extension.
1353
1334
  */
1354
- moveDatabasesAndAddSuffix(
1355
- folderPath?: string,
1356
- dbNameList?: string[],
1357
- ): Promise<void>;
1335
+ moveDatabasesAndAddSuffix(folderPath?: string, dbNameList?: string[]): Promise<void>;
1358
1336
  }
1359
1337
  /**
1360
1338
  * SQLiteConnection Class
@@ -1423,10 +1401,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1423
1401
  return Promise.reject(err);
1424
1402
  }
1425
1403
  }
1426
- async changeEncryptionSecret(
1427
- passphrase: string,
1428
- oldpassphrase: string,
1429
- ): Promise<void> {
1404
+ async changeEncryptionSecret(passphrase: string, oldpassphrase: string): Promise<void> {
1430
1405
  try {
1431
1406
  await this.sqlite.changeEncryptionSecret({
1432
1407
  passphrase: passphrase,
@@ -1455,10 +1430,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1455
1430
  return Promise.reject(err);
1456
1431
  }
1457
1432
  }
1458
- async addUpgradeStatement(
1459
- database: string,
1460
- upgrade: capSQLiteVersionUpgrade[]
1461
- ): Promise<void> {
1433
+ async addUpgradeStatement(database: string, upgrade: capSQLiteVersionUpgrade[]): Promise<void> {
1462
1434
  try {
1463
1435
  if (database.endsWith('.db')) database = database.slice(0, -3);
1464
1436
  await this.sqlite.addUpgradeStatement({
@@ -1475,7 +1447,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1475
1447
  encrypted: boolean,
1476
1448
  mode: string,
1477
1449
  version: number,
1478
- readonly: boolean,
1450
+ readonly: boolean
1479
1451
  ): Promise<SQLiteDBConnection> {
1480
1452
  try {
1481
1453
  if (database.endsWith('.db')) database = database.slice(0, -3);
@@ -1516,20 +1488,14 @@ export class SQLiteConnection implements ISQLiteConnection {
1516
1488
  return Promise.reject(err);
1517
1489
  }
1518
1490
  }
1519
- async isConnection(
1520
- database: string,
1521
- readonly: boolean,
1522
- ): Promise<capSQLiteResult> {
1491
+ async isConnection(database: string, readonly: boolean): Promise<capSQLiteResult> {
1523
1492
  const res: capSQLiteResult = {} as capSQLiteResult;
1524
1493
  if (database.endsWith('.db')) database = database.slice(0, -3);
1525
1494
  const connName = readonly ? `RO_${database}` : `RW_${database}`;
1526
1495
  res.result = this._connectionDict.has(connName);
1527
1496
  return Promise.resolve(res);
1528
1497
  }
1529
- async retrieveConnection(
1530
- database: string,
1531
- readonly: boolean,
1532
- ): Promise<SQLiteDBConnection> {
1498
+ async retrieveConnection(database: string, readonly: boolean): Promise<SQLiteDBConnection> {
1533
1499
  if (database.endsWith('.db')) database = database.slice(0, -3);
1534
1500
  const connName = readonly ? `RO_${database}` : `RW_${database}`;
1535
1501
  if (this._connectionDict.has(connName)) {
@@ -1542,25 +1508,18 @@ export class SQLiteConnection implements ISQLiteConnection {
1542
1508
  return Promise.reject(`Connection ${database} does not exist`);
1543
1509
  }
1544
1510
  }
1545
- async getNCDatabasePath(
1546
- path: string,
1547
- database: string,
1548
- ): Promise<capNCDatabasePathResult> {
1511
+ async getNCDatabasePath(path: string, database: string): Promise<capNCDatabasePathResult> {
1549
1512
  try {
1550
- const databasePath: capNCDatabasePathResult =
1551
- await this.sqlite.getNCDatabasePath({
1552
- path,
1553
- database,
1554
- });
1513
+ const databasePath: capNCDatabasePathResult = await this.sqlite.getNCDatabasePath({
1514
+ path,
1515
+ database,
1516
+ });
1555
1517
  return Promise.resolve(databasePath);
1556
1518
  } catch (err) {
1557
1519
  return Promise.reject(err);
1558
1520
  }
1559
1521
  }
1560
- async createNCConnection(
1561
- databasePath: string,
1562
- version: number,
1563
- ): Promise<SQLiteDBConnection> {
1522
+ async createNCConnection(databasePath: string, version: number): Promise<SQLiteDBConnection> {
1564
1523
  try {
1565
1524
  await this.sqlite.createNCConnection({
1566
1525
  databasePath,
@@ -1590,9 +1549,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1590
1549
  res.result = this._connectionDict.has(connName);
1591
1550
  return Promise.resolve(res);
1592
1551
  }
1593
- async retrieveNCConnection(
1594
- databasePath: string,
1595
- ): Promise<SQLiteDBConnection> {
1552
+ async retrieveNCConnection(databasePath: string): Promise<SQLiteDBConnection> {
1596
1553
  if (this._connectionDict.has(databasePath)) {
1597
1554
  const connName = `RO_${databasePath})`;
1598
1555
  const conn = this._connectionDict.get(connName);
@@ -1648,11 +1605,10 @@ export class SQLiteConnection implements ISQLiteConnection {
1648
1605
  openModes.push(key.substring(0, 2));
1649
1606
  dbNames.push(key.substring(3));
1650
1607
  }
1651
- const res: capSQLiteResult =
1652
- await this.sqlite.checkConnectionsConsistency({
1653
- dbNames: dbNames,
1654
- openModes: openModes,
1655
- });
1608
+ const res: capSQLiteResult = await this.sqlite.checkConnectionsConsistency({
1609
+ dbNames: dbNames,
1610
+ openModes: openModes,
1611
+ });
1656
1612
  if (!res.result) this._connectionDict = new Map();
1657
1613
  return Promise.resolve(res);
1658
1614
  } catch (err) {
@@ -1751,10 +1707,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1751
1707
  return Promise.reject(err);
1752
1708
  }
1753
1709
  }
1754
- async addSQLiteSuffix(
1755
- folderPath?: string,
1756
- dbNameList?: string[],
1757
- ): Promise<void> {
1710
+ async addSQLiteSuffix(folderPath?: string, dbNameList?: string[]): Promise<void> {
1758
1711
  const path: string = folderPath ? folderPath : 'default';
1759
1712
  const dbList: string[] = dbNameList ? dbNameList : [];
1760
1713
  try {
@@ -1767,10 +1720,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1767
1720
  return Promise.reject(err);
1768
1721
  }
1769
1722
  }
1770
- async deleteOldDatabases(
1771
- folderPath?: string,
1772
- dbNameList?: string[],
1773
- ): Promise<void> {
1723
+ async deleteOldDatabases(folderPath?: string, dbNameList?: string[]): Promise<void> {
1774
1724
  const path: string = folderPath ? folderPath : 'default';
1775
1725
  const dbList: string[] = dbNameList ? dbNameList : [];
1776
1726
  try {
@@ -1784,10 +1734,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1784
1734
  }
1785
1735
  }
1786
1736
 
1787
- async moveDatabasesAndAddSuffix(
1788
- folderPath?: string,
1789
- dbNameList?: string[],
1790
- ): Promise<void> {
1737
+ async moveDatabasesAndAddSuffix(folderPath?: string, dbNameList?: string[]): Promise<void> {
1791
1738
  const path: string = folderPath ? folderPath : 'default';
1792
1739
  const dbList: string[] = dbNameList ? dbNameList : [];
1793
1740
  return this.sqlite.moveDatabasesAndAddSuffix({
@@ -1885,11 +1832,7 @@ export interface ISQLiteDBConnection {
1885
1832
  * @returns Promise<capSQLiteChanges>
1886
1833
  * @since 2.9.0 refactor
1887
1834
  */
1888
- execute(
1889
- statements: string,
1890
- transaction?: boolean,
1891
- isSQL92?: boolean,
1892
- ): Promise<capSQLiteChanges>;
1835
+ execute(statements: string, transaction?: boolean, isSQL92?: boolean): Promise<capSQLiteChanges>;
1893
1836
  /**
1894
1837
  * Execute SQLite DB Connection Query
1895
1838
  * @param statement
@@ -1898,11 +1841,7 @@ export interface ISQLiteDBConnection {
1898
1841
  * @returns Promise<Promise<DBSQLiteValues>
1899
1842
  * @since 2.9.0 refactor
1900
1843
  */
1901
- query(
1902
- statement: string,
1903
- values?: any[],
1904
- isSQL92?: boolean,
1905
- ): Promise<DBSQLiteValues>;
1844
+ query(statement: string, values?: any[], isSQL92?: boolean): Promise<DBSQLiteValues>;
1906
1845
  /**
1907
1846
  * Execute SQLite DB Connection Raw Statement
1908
1847
  * @param statement
@@ -1918,7 +1857,7 @@ export interface ISQLiteDBConnection {
1918
1857
  values?: any[],
1919
1858
  transaction?: boolean,
1920
1859
  returnMode?: string,
1921
- isSQL92?: boolean,
1860
+ isSQL92?: boolean
1922
1861
  ): Promise<capSQLiteChanges>;
1923
1862
  /**
1924
1863
  * Execute SQLite DB Connection Set
@@ -1933,7 +1872,7 @@ export interface ISQLiteDBConnection {
1933
1872
  set: capSQLiteSet[],
1934
1873
  transaction?: boolean,
1935
1874
  returnMode?: string,
1936
- isSQL92?: boolean,
1875
+ isSQL92?: boolean
1937
1876
  ): Promise<capSQLiteChanges>;
1938
1877
  /**
1939
1878
  * Check if a SQLite DB Connection exists
@@ -2005,20 +1944,13 @@ export interface ISQLiteDBConnection {
2005
1944
  * @returns Promise<capSQLiteChanges> since 5.0.7
2006
1945
  * @since 3.4.0
2007
1946
  */
2008
- executeTransaction(
2009
- txn: capTask[],
2010
- isSQL92: boolean,
2011
- ): Promise<capSQLiteChanges>;
1947
+ executeTransaction(txn: capTask[], isSQL92: boolean): Promise<capSQLiteChanges>;
2012
1948
  }
2013
1949
  /**
2014
1950
  * SQLiteDBConnection Class
2015
1951
  */
2016
1952
  export class SQLiteDBConnection implements ISQLiteDBConnection {
2017
- constructor(
2018
- private dbName: string,
2019
- private readonly: boolean,
2020
- private sqlite: any,
2021
- ) {}
1953
+ constructor(private dbName: string, private readonly: boolean, private sqlite: any) {}
2022
1954
 
2023
1955
  getConnectionDBName(): string {
2024
1956
  return this.dbName;
@@ -2148,11 +2080,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2148
2080
  return Promise.reject(err);
2149
2081
  }
2150
2082
  }
2151
- async execute(
2152
- statements: string,
2153
- transaction = true,
2154
- isSQL92 = true,
2155
- ): Promise<capSQLiteChanges> {
2083
+ async execute(statements: string, transaction = true, isSQL92 = true): Promise<capSQLiteChanges> {
2156
2084
  try {
2157
2085
  if (!this.readonly) {
2158
2086
  const res: any = await this.sqlite.execute({
@@ -2170,11 +2098,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2170
2098
  return Promise.reject(err);
2171
2099
  }
2172
2100
  }
2173
- async query(
2174
- statement: string,
2175
- values?: any[],
2176
- isSQL92 = true,
2177
- ): Promise<DBSQLiteValues> {
2101
+ async query(statement: string, values?: any[], isSQL92 = true): Promise<DBSQLiteValues> {
2178
2102
  let res: any;
2179
2103
  try {
2180
2104
  if (values && values.length > 0) {
@@ -2207,7 +2131,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2207
2131
  values?: any[],
2208
2132
  transaction = true,
2209
2133
  returnMode = 'no',
2210
- isSQL92 = true,
2134
+ isSQL92 = true
2211
2135
  ): Promise<capSQLiteChanges> {
2212
2136
  let res: any;
2213
2137
  try {
@@ -2247,7 +2171,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2247
2171
  set: capSQLiteSet[],
2248
2172
  transaction = true,
2249
2173
  returnMode = 'no',
2250
- isSQL92 = true,
2174
+ isSQL92 = true
2251
2175
  ): Promise<capSQLiteChanges> {
2252
2176
  let res: any;
2253
2177
  try {
@@ -2358,8 +2282,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2358
2282
  readonly: this.readonly,
2359
2283
  });
2360
2284
  let retDate = '';
2361
- if (res.syncDate > 0)
2362
- retDate = new Date(res.syncDate * 1000).toISOString();
2285
+ if (res.syncDate > 0) retDate = new Date(res.syncDate * 1000).toISOString();
2363
2286
  return Promise.resolve(retDate);
2364
2287
  } catch (err) {
2365
2288
  return Promise.reject(err);
@@ -2394,10 +2317,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2394
2317
  }
2395
2318
  }
2396
2319
 
2397
- async executeTransaction(
2398
- txn: capTask[],
2399
- isSQL92 = true,
2400
- ): Promise<capSQLiteChanges> {
2320
+ async executeTransaction(txn: capTask[], isSQL92 = true): Promise<capSQLiteChanges> {
2401
2321
  let changes = 0;
2402
2322
  let isActive = false;
2403
2323
  if (!this.readonly) {
@@ -2408,19 +2328,15 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2408
2328
  database: this.dbName,
2409
2329
  });
2410
2330
  if (!isActive) {
2411
- return Promise.reject(
2412
- 'After Begin Transaction, no transaction active',
2413
- );
2331
+ return Promise.reject('After Begin Transaction, no transaction active');
2414
2332
  }
2415
2333
  try {
2416
2334
  for (const task of txn) {
2417
- if(typeof task !== 'object' || !('statement' in task)) {
2335
+ if (typeof task !== 'object' || !('statement' in task)) {
2418
2336
  throw new Error('Error a task.statement must be provided');
2419
2337
  }
2420
2338
  if ('values' in task && task.values && task.values.length > 0) {
2421
- const retMode = task.statement.toUpperCase().includes('RETURNING')
2422
- ? 'all'
2423
- : 'no';
2339
+ const retMode = task.statement.toUpperCase().includes('RETURNING') ? 'all' : 'no';
2424
2340
  const ret = await this.sqlite.run({
2425
2341
  database: this.dbName,
2426
2342
  statement: task.statement,
package/src/index.ts CHANGED
@@ -2,14 +2,10 @@ import { registerPlugin } from '@capacitor/core';
2
2
 
3
3
  import type { CapacitorSQLitePlugin } from './definitions';
4
4
 
5
- const CapacitorSQLite = registerPlugin<CapacitorSQLitePlugin>(
6
- 'CapacitorSQLite',
7
- {
8
- web: () => import('./web').then(m => new m.CapacitorSQLiteWeb()),
9
- electron: () =>
10
- (window as any).CapacitorCustomPlatform.plugins.CapacitorSQLite,
11
- },
12
- );
5
+ const CapacitorSQLite = registerPlugin<CapacitorSQLitePlugin>('CapacitorSQLite', {
6
+ web: () => import('./web').then((m) => new m.CapacitorSQLiteWeb()),
7
+ electron: () => (window as any).CapacitorCustomPlatform.plugins.CapacitorSQLite,
8
+ });
13
9
 
14
10
  export { CapacitorSQLite };
15
11
  export * from './definitions';