@capacitor-community/sqlite 5.0.5-2 → 5.0.6

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 (44) hide show
  1. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +118 -156
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +81 -249
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/NotificationCenter.java +1 -1
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +0 -12
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +184 -40
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +141 -135
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +2 -1
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsEncryption.java +111 -0
  9. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsBiometric.java +0 -4
  10. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +30 -18
  11. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +12 -4
  12. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsNCDatabase.java +4 -1
  13. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java +8 -6
  14. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLite.java +14 -28
  15. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSecret.java +3 -4
  16. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +0 -1
  17. package/dist/esm/definitions.d.ts +91 -4
  18. package/dist/esm/definitions.js +79 -19
  19. package/dist/esm/definitions.js.map +1 -1
  20. package/dist/esm/web.d.ts +3 -1
  21. package/dist/esm/web.js +8 -0
  22. package/dist/esm/web.js.map +1 -1
  23. package/dist/plugin.cjs.js +87 -19
  24. package/dist/plugin.cjs.js.map +1 -1
  25. package/dist/plugin.js +87 -19
  26. package/dist/plugin.js.map +1 -1
  27. package/electron/dist/plugin.js +333 -148
  28. package/electron/dist/plugin.js.map +1 -1
  29. package/electron/rollup.config.js +2 -0
  30. package/ios/Plugin/CapacitorSQLite.swift +125 -92
  31. package/ios/Plugin/CapacitorSQLitePlugin.swift +6 -3
  32. package/ios/Plugin/Database.swift +45 -19
  33. package/ios/Plugin/ImportExportJson/ExportToJson.swift +10 -5
  34. package/ios/Plugin/ImportExportJson/ImportData.swift +434 -0
  35. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +47 -59
  36. package/ios/Plugin/ImportExportJson/JsonSQLite.swift +7 -0
  37. package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +61 -61
  38. package/ios/Plugin/Utils/UtilsDrop.swift +2 -1
  39. package/ios/Plugin/Utils/UtilsJson.swift +123 -1
  40. package/ios/Plugin/Utils/UtilsSQLCipher.swift +254 -23
  41. package/ios/Plugin/Utils/UtilsUpgrade.swift +0 -1
  42. package/package.json +2 -2
  43. package/src/definitions.ts +171 -18
  44. package/src/web.ts +10 -0
@@ -120,6 +120,20 @@ export interface CapacitorSQLitePlugin {
120
120
  * @since 0.0.1
121
121
  */
122
122
  close(options: capSQLiteOptions): Promise<void>;
123
+ /**
124
+ * Load a SQlite extension
125
+ * @param options :capSQLiteExtensionPath
126
+ * @returns Promise<void>
127
+ * @since 5.0.6
128
+ */
129
+ // loadExtension(options: capSQLiteExtensionPath): Promise<void>;
130
+ /**
131
+ * Enable Or Disable Extension Loading
132
+ * @param options
133
+ * @returns Promise<void>
134
+ * @since 5.0.6
135
+ */
136
+ // enableLoadExtension(options: capSQLiteExtensionEnable): Promise<void>;
123
137
  /**
124
138
  * GetUrl get the database Url
125
139
  * @param options: capSQLiteOptions
@@ -391,6 +405,38 @@ export interface capEchoOptions {
391
405
  */
392
406
  value?: string;
393
407
  }
408
+ export interface capSQLiteExtensionPath {
409
+ /**
410
+ * The database name
411
+ */
412
+ database?: string;
413
+ /**
414
+ * The extension path
415
+ */
416
+ path?: string;
417
+ /**
418
+ * ReadOnly / ReadWrite
419
+ * default ReadWrite (false)
420
+ * @since 4.1.0-7
421
+ */
422
+ readonly?: boolean;
423
+ }
424
+ export interface capSQLiteExtensionEnable {
425
+ /**
426
+ * The database name
427
+ */
428
+ database?: string;
429
+ /**
430
+ * The enabling toggle (1: ON, 0: OFF)
431
+ */
432
+ toggle?: boolean;
433
+ /**
434
+ * ReadOnly / ReadWrite
435
+ * default ReadWrite (false)
436
+ * @since 4.1.0-7
437
+ */
438
+ readonly?: boolean;
439
+ }
394
440
  export interface capConnectionOptions {
395
441
  /**
396
442
  * The database name
@@ -436,6 +482,7 @@ export interface capSQLiteOptions {
436
482
  */
437
483
  readonly?: boolean;
438
484
  }
485
+
439
486
  export interface capNCDatabasePathOptions {
440
487
  /**
441
488
  * the database path
@@ -506,6 +553,14 @@ export interface capSQLiteSetOptions {
506
553
  * @since 4.1.0-7
507
554
  */
508
555
  readonly?: boolean;
556
+ /**
557
+ * return mode
558
+ * default 'no'
559
+ * value 'all'
560
+ * value 'one' for Electron platform
561
+ * @since 5.0.5-3
562
+ */
563
+ returnMode?: string;
509
564
  }
510
565
  export interface capSQLiteRunOptions {
511
566
  /**
@@ -532,6 +587,14 @@ export interface capSQLiteRunOptions {
532
587
  * @since 4.1.0-7
533
588
  */
534
589
  readonly?: boolean;
590
+ /**
591
+ * return mode
592
+ * default 'no'
593
+ * value 'all'
594
+ * value 'one' for Electron platform
595
+ * @since 5.0.5-3
596
+ */
597
+ returnMode?: string;
535
598
  }
536
599
  export interface capSQLiteQueryOptions {
537
600
  /**
@@ -721,6 +784,10 @@ export interface Changes {
721
784
  * the lastId created from a run command
722
785
  */
723
786
  lastId?: number;
787
+ /**
788
+ * values when RETURNING
789
+ */
790
+ values?: any[];
724
791
  }
725
792
  export interface capSQLiteValues {
726
793
  /**
@@ -749,6 +816,12 @@ export interface capSQLiteSyncDate {
749
816
  }
750
817
 
751
818
  /* JSON Types */
819
+ export interface EncryptJson {
820
+ /**
821
+ * The encrypted JsonSQLite base64 string
822
+ */
823
+ expData: string;
824
+ }
752
825
  export interface JsonSQLite {
753
826
  /**
754
827
  * The database name
@@ -1572,7 +1645,7 @@ export class SQLiteConnection implements ISQLiteConnection {
1572
1645
  const res = await this.sqlite.getDatabaseList();
1573
1646
  const values: string[] = res.values;
1574
1647
  values.sort();
1575
- const ret = {values: values};
1648
+ const ret = { values: values };
1576
1649
  return Promise.resolve(ret);
1577
1650
  } catch (err) {
1578
1651
  return Promise.reject(err);
@@ -1679,6 +1752,20 @@ export interface ISQLiteDBConnection {
1679
1752
  * @since 3.2.0
1680
1753
  */
1681
1754
  getVersion(): Promise<capVersionResult>;
1755
+ /**
1756
+ * Load a SQlite extension
1757
+ * @param path :SQlite extension path
1758
+ * @returns Promise<void>
1759
+ * @since 5.0.6
1760
+ */
1761
+ loadExtension(path: string): Promise<void>;
1762
+ /**
1763
+ * Enable Or Disable Extension Loading
1764
+ * @param toggle true:on false:off
1765
+ * @returns Promise<void>
1766
+ * @since 5.0.6
1767
+ */
1768
+ enableLoadExtension(toggle: boolean): Promise<void>;
1682
1769
  /**
1683
1770
  * Execute SQLite DB Connection Statements
1684
1771
  * @param statements
@@ -1705,6 +1792,7 @@ export interface ISQLiteDBConnection {
1705
1792
  statement: string,
1706
1793
  values?: any[],
1707
1794
  transaction?: boolean,
1795
+ returnMode?: string,
1708
1796
  ): Promise<capSQLiteChanges>;
1709
1797
  /**
1710
1798
  * Execute SQLite DB Connection Set
@@ -1715,6 +1803,7 @@ export interface ISQLiteDBConnection {
1715
1803
  executeSet(
1716
1804
  set: capSQLiteSet[],
1717
1805
  transaction?: boolean,
1806
+ returnMode?: string,
1718
1807
  ): Promise<capSQLiteChanges>;
1719
1808
  /**
1720
1809
  * Check if a SQLite DB Connection exists
@@ -1827,6 +1916,43 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
1827
1916
  return Promise.reject(err);
1828
1917
  }
1829
1918
  }
1919
+
1920
+ async loadExtension(path: string): Promise<void> {
1921
+ try {
1922
+ console.log(`database: ${this.dbName}`);
1923
+ console.log(`readonly: ${this.readonly}}`);
1924
+ console.log(`path: ${path}}`);
1925
+ await this.sqlite.loadExtension({
1926
+ database: this.dbName,
1927
+ path: path,
1928
+ readonly: this.readonly,
1929
+ });
1930
+ console.log(`loadExtension successful`);
1931
+ return Promise.resolve();
1932
+ } catch (err) {
1933
+ console.log(`loadExtension failed `);
1934
+ return Promise.reject(err);
1935
+ }
1936
+ }
1937
+ async enableLoadExtension(toggle: boolean): Promise<void> {
1938
+ try {
1939
+ console.log(`database: ${this.dbName}`);
1940
+ console.log(`readonly: ${this.readonly}`);
1941
+ console.log(`toggle: ${toggle}`);
1942
+ await this.sqlite.enableLoadExtension({
1943
+ database: this.dbName,
1944
+ toggle: toggle,
1945
+ readonly: this.readonly,
1946
+ });
1947
+ console.log(`enableLoadExtension successful`);
1948
+ return Promise.resolve();
1949
+ } catch (err) {
1950
+ console.log(err);
1951
+ console.log(`enableLoadExtension failed `);
1952
+ return Promise.reject(err);
1953
+ }
1954
+ }
1955
+
1830
1956
  async getUrl(): Promise<capSQLiteUrl> {
1831
1957
  try {
1832
1958
  const res: capSQLiteUrl = await this.sqlite.getUrl({
@@ -1898,22 +2024,9 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
1898
2024
  readonly: this.readonly,
1899
2025
  });
1900
2026
  }
1901
- if (res && typeof res.values[0] === 'object') {
1902
- if (Object.keys(res.values[0]).includes('ios_columns')) {
1903
- const columnList: string[] = res.values[0]['ios_columns'];
1904
- const iosRes: any[] = [];
1905
- for (let i = 1; i < res.values.length; i++) {
1906
- const rowJson: any = res.values[i];
1907
- const resRowJson: any = {};
1908
- for (const item of columnList) {
1909
- resRowJson[item] = rowJson[item];
1910
- }
1911
- iosRes.push(resRowJson);
1912
- }
1913
- res = {};
1914
- res['values'] = iosRes;
1915
- }
1916
- }
2027
+
2028
+ // reorder rows for ios
2029
+ res = await this.reorderRows(res);
1917
2030
  return Promise.resolve(res);
1918
2031
  } catch (err) {
1919
2032
  return Promise.reject(err);
@@ -1923,28 +2036,39 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
1923
2036
  statement: string,
1924
2037
  values?: any[],
1925
2038
  transaction = true,
2039
+ returnMode = 'no',
1926
2040
  ): Promise<capSQLiteChanges> {
1927
2041
  let res: any;
1928
2042
  try {
1929
2043
  if (!this.readonly) {
1930
2044
  if (values && values.length > 0) {
2045
+ const mRetMode = statement.toUpperCase().includes('RETURNING')
2046
+ ? returnMode
2047
+ : 'no';
1931
2048
  res = await this.sqlite.run({
1932
2049
  database: this.dbName,
1933
2050
  statement: statement,
1934
2051
  values: values,
1935
2052
  transaction: transaction,
1936
2053
  readonly: false,
2054
+ returnMode: mRetMode,
1937
2055
  });
1938
2056
  // }
1939
2057
  } else {
2058
+ const mRetMode = statement.toUpperCase().includes('RETURNING')
2059
+ ? returnMode
2060
+ : 'no';
1940
2061
  res = await this.sqlite.run({
1941
2062
  database: this.dbName,
1942
2063
  statement: statement,
1943
2064
  values: [],
1944
2065
  transaction: transaction,
1945
2066
  readonly: false,
2067
+ returnMode: mRetMode,
1946
2068
  });
1947
2069
  }
2070
+ // reorder rows for ios
2071
+ res.changes = await this.reorderRows(res.changes);
1948
2072
  return Promise.resolve(res);
1949
2073
  } else {
1950
2074
  return Promise.reject('not allowed in read-only mode');
@@ -1956,16 +2080,21 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
1956
2080
  async executeSet(
1957
2081
  set: capSQLiteSet[],
1958
2082
  transaction = true,
2083
+ returnMode = 'no',
1959
2084
  ): Promise<capSQLiteChanges> {
2085
+ let res: any;
1960
2086
  try {
1961
2087
  if (!this.readonly) {
1962
- const res: any = await this.sqlite.executeSet({
2088
+ res = await this.sqlite.executeSet({
1963
2089
  database: this.dbName,
1964
2090
  set: set,
1965
2091
  transaction: transaction,
1966
2092
  readonly: false,
2093
+ returnMode: returnMode,
1967
2094
  });
1968
2095
  // }
2096
+ // reorder rows for ios
2097
+ res.changes = await this.reorderRows(res.changes);
1969
2098
  return Promise.resolve(res);
1970
2099
  } else {
1971
2100
  return Promise.reject('not allowed in read-only mode');
@@ -2111,12 +2240,16 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2111
2240
  }
2112
2241
  for (const task of txn) {
2113
2242
  if (task.values && task.values.length > 0) {
2243
+ const retMode = task.statement.toUpperCase().includes('RETURNING')
2244
+ ? 'all'
2245
+ : 'no';
2114
2246
  const ret = await this.sqlite.run({
2115
2247
  database: this.dbName,
2116
2248
  statement: task.statement,
2117
2249
  values: task.values,
2118
2250
  transaction: false,
2119
2251
  readonly: false,
2252
+ returnMode: retMode,
2120
2253
  });
2121
2254
  if (ret.changes.lastId === -1) {
2122
2255
  await this.execute('ROLLBACK;', false);
@@ -2160,4 +2293,24 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2160
2293
  return Promise.reject(err);
2161
2294
  }
2162
2295
  }
2296
+ private async reorderRows(res: any): Promise<any> {
2297
+ const retRes: any = res;
2298
+ if (res?.values && typeof res.values[0] === 'object') {
2299
+ if (Object.keys(res.values[0]).includes('ios_columns')) {
2300
+ const columnList: string[] = res.values[0]['ios_columns'];
2301
+ const iosRes: any[] = [];
2302
+ for (let i = 1; i < res.values.length; i++) {
2303
+ const rowJson: any = res.values[i];
2304
+ const resRowJson: any = {};
2305
+ for (const item of columnList) {
2306
+ resRowJson[item] = rowJson[item];
2307
+ }
2308
+ iosRes.push(resRowJson);
2309
+ }
2310
+ retRes['values'] = iosRes;
2311
+ }
2312
+ }
2313
+
2314
+ return Promise.resolve(retRes);
2315
+ }
2163
2316
  }
package/src/web.ts CHANGED
@@ -32,6 +32,8 @@ import type {
32
32
  capSQLiteUrl,
33
33
  capSQLiteValues,
34
34
  capVersionResult,
35
+ capSQLiteExtensionPath,
36
+ capSQLiteExtensionEnable,
35
37
  } from './definitions';
36
38
 
37
39
  export class CapacitorSQLiteWeb
@@ -591,4 +593,12 @@ export class CapacitorSQLiteWeb
591
593
  async isInConfigBiometricAuth(): Promise<capSQLiteResult> {
592
594
  throw this.unimplemented('Not implemented on web.');
593
595
  }
596
+ async loadExtension(options: capSQLiteExtensionPath): Promise<void> {
597
+ console.log('loadExtension', options);
598
+ throw this.unimplemented('Not implemented on web.');
599
+ }
600
+ async enableLoadExtension(options: capSQLiteExtensionEnable): Promise<void> {
601
+ console.log('enableLoadExtension', options);
602
+ throw this.unimplemented('Not implemented on web.');
603
+ }
594
604
  }