@capacitor-community/sqlite 4.1.0-8 → 4.1.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/README.md +1 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +7 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +34 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +5 -5
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +2 -1
- package/dist/esm/definitions.d.ts +33 -0
- package/dist/esm/definitions.js +21 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +12 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +33 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +33 -2
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +155 -51
- package/electron/dist/plugin.js.map +1 -1
- package/electron/rollup.config.js +1 -0
- package/ios/Plugin/CapacitorSQLite.swift +16 -8
- package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +27 -2
- package/ios/Plugin/Utils/UtilsUpgrade.swift +3 -1
- package/package.json +2 -2
package/electron/dist/plugin.js
CHANGED
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var require$$0 = require('sqlite3');
|
|
6
6
|
var require$$0$1 = require('path');
|
|
7
7
|
var require$$1 = require('fs');
|
|
8
|
-
var require$$2 = require('
|
|
9
|
-
var require$$3 = require('
|
|
10
|
-
var require$$4 = require('
|
|
8
|
+
var require$$2 = require('node-fetch');
|
|
9
|
+
var require$$3 = require('os');
|
|
10
|
+
var require$$4 = require('jszip');
|
|
11
|
+
var require$$5 = require('electron');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
@@ -17,6 +18,7 @@ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
|
17
18
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
18
19
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
19
20
|
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
21
|
+
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
20
22
|
|
|
21
23
|
var src = {};
|
|
22
24
|
|
|
@@ -2676,6 +2678,7 @@ class UtilsFile {
|
|
|
2676
2678
|
this.pathDB = 'Databases';
|
|
2677
2679
|
this.Path = null;
|
|
2678
2680
|
this.NodeFs = null;
|
|
2681
|
+
this.NodeFetch = null;
|
|
2679
2682
|
this.JSZip = null;
|
|
2680
2683
|
this.Os = null;
|
|
2681
2684
|
this.Electron = null;
|
|
@@ -2684,9 +2687,10 @@ class UtilsFile {
|
|
|
2684
2687
|
this.sep = '/';
|
|
2685
2688
|
this.Path = require$$0__default$1["default"];
|
|
2686
2689
|
this.NodeFs = require$$1__default["default"];
|
|
2687
|
-
this.
|
|
2688
|
-
this.
|
|
2689
|
-
this.
|
|
2690
|
+
this.NodeFetch = require$$2__default["default"];
|
|
2691
|
+
this.Os = require$$3__default["default"];
|
|
2692
|
+
this.JSZip = require$$4__default["default"];
|
|
2693
|
+
this.Electron = require$$5__default["default"];
|
|
2690
2694
|
this.HomeDir = this.Os.homedir();
|
|
2691
2695
|
const dir = __dirname;
|
|
2692
2696
|
const idx = dir.indexOf('\\');
|
|
@@ -2722,6 +2726,17 @@ class UtilsFile {
|
|
|
2722
2726
|
}
|
|
2723
2727
|
console.log(`&&& Databases path: ${this.pathDB}`);
|
|
2724
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* GetExtName
|
|
2731
|
+
* @param filePath
|
|
2732
|
+
* @returns
|
|
2733
|
+
*/
|
|
2734
|
+
getExtName(filePath) {
|
|
2735
|
+
return this.Path.extname(filePath);
|
|
2736
|
+
}
|
|
2737
|
+
getBaseName(filePath) {
|
|
2738
|
+
return this.Path.basename(filePath, this.Path.extname(filePath));
|
|
2739
|
+
}
|
|
2725
2740
|
/**
|
|
2726
2741
|
* IsPathExists
|
|
2727
2742
|
* @param filePath
|
|
@@ -2781,6 +2796,19 @@ class UtilsFile {
|
|
|
2781
2796
|
retPath = '';
|
|
2782
2797
|
return retPath;
|
|
2783
2798
|
}
|
|
2799
|
+
/**
|
|
2800
|
+
* GetCachePath
|
|
2801
|
+
* get the database cache folder path
|
|
2802
|
+
*/
|
|
2803
|
+
getCachePath() {
|
|
2804
|
+
let retPath = '';
|
|
2805
|
+
const databasePath = this.getDatabasesPath();
|
|
2806
|
+
retPath = this.Path.join(databasePath, 'cache');
|
|
2807
|
+
const retB = this._createFolderIfNotExists(retPath);
|
|
2808
|
+
if (!retB)
|
|
2809
|
+
retPath = '';
|
|
2810
|
+
return retPath;
|
|
2811
|
+
}
|
|
2784
2812
|
/**
|
|
2785
2813
|
* GetAssetsDatabasesPath
|
|
2786
2814
|
* get the assets databases folder path
|
|
@@ -2803,10 +2831,12 @@ class UtilsFile {
|
|
|
2803
2831
|
setPathSuffix(db) {
|
|
2804
2832
|
let toDb = db;
|
|
2805
2833
|
const ext = '.db';
|
|
2806
|
-
const
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2834
|
+
const dirName = this.Path.dirname(db);
|
|
2835
|
+
const baseName = this.getBaseName(db);
|
|
2836
|
+
if (this.getExtName(db) === ext) {
|
|
2837
|
+
if (!baseName.includes('SQLite')) {
|
|
2838
|
+
const dbName = `${baseName}SQLite`;
|
|
2839
|
+
toDb = `${this.Path.join(dirName, dbName)}${ext}`;
|
|
2810
2840
|
}
|
|
2811
2841
|
}
|
|
2812
2842
|
return toDb;
|
|
@@ -2820,7 +2850,7 @@ class UtilsFile {
|
|
|
2820
2850
|
const filenames = this.NodeFs.readdirSync(path);
|
|
2821
2851
|
const dbs = [];
|
|
2822
2852
|
filenames.forEach((file) => {
|
|
2823
|
-
if (this.
|
|
2853
|
+
if (this.getExtName(file) == '.db' || this.getExtName(file) == '.zip')
|
|
2824
2854
|
dbs.push(file);
|
|
2825
2855
|
});
|
|
2826
2856
|
return Promise.resolve(dbs);
|
|
@@ -2842,8 +2872,8 @@ class UtilsFile {
|
|
|
2842
2872
|
* @param db
|
|
2843
2873
|
* @param overwrite
|
|
2844
2874
|
*/
|
|
2845
|
-
async unzipDatabase(db, overwrite) {
|
|
2846
|
-
const pZip = this.Path.join(
|
|
2875
|
+
async unzipDatabase(db, fPath, overwrite) {
|
|
2876
|
+
const pZip = this.Path.join(fPath, db);
|
|
2847
2877
|
// Read the Zip file
|
|
2848
2878
|
this.NodeFs.readFile(pZip, (err, data) => {
|
|
2849
2879
|
if (err) {
|
|
@@ -3024,13 +3054,39 @@ class UtilsFile {
|
|
|
3024
3054
|
}
|
|
3025
3055
|
}
|
|
3026
3056
|
else {
|
|
3027
|
-
return Promise.reject(
|
|
3057
|
+
return Promise.reject(`RenameFilePath: ${filePath} does not exist`);
|
|
3028
3058
|
}
|
|
3029
3059
|
}
|
|
3030
3060
|
else {
|
|
3031
3061
|
return Promise.reject('RenameFilePath: filePath not found');
|
|
3032
3062
|
}
|
|
3033
3063
|
}
|
|
3064
|
+
async moveDatabaseFromCache() {
|
|
3065
|
+
const cachePath = this.getCachePath();
|
|
3066
|
+
const databasePath = this.getDatabasesPath();
|
|
3067
|
+
const dbCacheList = await this.getFileList(cachePath);
|
|
3068
|
+
for (const name of dbCacheList) {
|
|
3069
|
+
const ext = this.getExtName(name);
|
|
3070
|
+
const fromDBName = this.Path.join(cachePath, name);
|
|
3071
|
+
if (ext === '.db') {
|
|
3072
|
+
const pDb = this.setPathSuffix(this.Path.join(databasePath, name));
|
|
3073
|
+
try {
|
|
3074
|
+
await this.renameFilePath(fromDBName, pDb);
|
|
3075
|
+
}
|
|
3076
|
+
catch (err) {
|
|
3077
|
+
return Promise.reject('moveDatabaseFromCache: ' + `${err}`);
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
if (ext === '.zip') {
|
|
3081
|
+
try {
|
|
3082
|
+
await this.deleteFilePath(fromDBName);
|
|
3083
|
+
}
|
|
3084
|
+
catch (err) {
|
|
3085
|
+
return Promise.reject('moveDatabaseFromCache: ' + `${err}`);
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3034
3090
|
/**
|
|
3035
3091
|
* RestoreFileName
|
|
3036
3092
|
* @param fileName
|
|
@@ -3060,6 +3116,23 @@ class UtilsFile {
|
|
|
3060
3116
|
return Promise.reject(`RestoreFileName: ${mFileName} ` + 'does not exist');
|
|
3061
3117
|
}
|
|
3062
3118
|
}
|
|
3119
|
+
/**
|
|
3120
|
+
* DownloadFileFromHTTP
|
|
3121
|
+
* @param url
|
|
3122
|
+
* @param path
|
|
3123
|
+
*/
|
|
3124
|
+
async downloadFileFromHTTP(url, pathFolder) {
|
|
3125
|
+
const res = await this.NodeFetch(url);
|
|
3126
|
+
const ext = this.getExtName(url);
|
|
3127
|
+
const dbName = this.getBaseName(url);
|
|
3128
|
+
const filePath = `${this.Path.join(pathFolder, dbName)}${ext}`;
|
|
3129
|
+
const fileStream = this.NodeFs.createWriteStream(filePath);
|
|
3130
|
+
await new Promise((resolve, reject) => {
|
|
3131
|
+
res.body.pipe(fileStream);
|
|
3132
|
+
res.body.on('error', reject);
|
|
3133
|
+
fileStream.on('finish', resolve);
|
|
3134
|
+
});
|
|
3135
|
+
}
|
|
3063
3136
|
/**
|
|
3064
3137
|
* CreateFolderIfNotExists
|
|
3065
3138
|
* Create directory
|
|
@@ -3116,6 +3189,7 @@ class UtilsUpgrade {
|
|
|
3116
3189
|
* @param targetVersion
|
|
3117
3190
|
*/
|
|
3118
3191
|
async onUpgrade(mDB, vUpgDict, curVersion, targetVersion) {
|
|
3192
|
+
let changes;
|
|
3119
3193
|
const sortedKeys = Object.keys(vUpgDict)
|
|
3120
3194
|
.map(item => parseInt(item))
|
|
3121
3195
|
.sort();
|
|
@@ -3133,14 +3207,14 @@ class UtilsUpgrade {
|
|
|
3133
3207
|
await this.sqliteUtil.setVersion(mDB, versionKey);
|
|
3134
3208
|
// set Foreign Keys On
|
|
3135
3209
|
await this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB, true);
|
|
3136
|
-
|
|
3137
|
-
return Promise.resolve(changes);
|
|
3210
|
+
changes = (await this.sqliteUtil.dbChanges(mDB)) - initChanges;
|
|
3138
3211
|
}
|
|
3139
3212
|
catch (err) {
|
|
3140
3213
|
return Promise.reject(`onUpgrade: ${err}`);
|
|
3141
3214
|
}
|
|
3142
3215
|
}
|
|
3143
3216
|
}
|
|
3217
|
+
return Promise.resolve(changes);
|
|
3144
3218
|
}
|
|
3145
3219
|
/**
|
|
3146
3220
|
* ExecuteStatementProcess
|
|
@@ -3712,7 +3786,7 @@ class CapacitorSQLite {
|
|
|
3712
3786
|
versionUpgradeKeys.includes(dbName)) {
|
|
3713
3787
|
upgrades = this.versionUpgrades[dbName];
|
|
3714
3788
|
}
|
|
3715
|
-
const connName = readonly ?
|
|
3789
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3716
3790
|
const databaseConnection = new Database_1.Database(dbName + 'SQLite.db',
|
|
3717
3791
|
/* encrypted,
|
|
3718
3792
|
inMode,
|
|
@@ -3724,7 +3798,7 @@ class CapacitorSQLite {
|
|
|
3724
3798
|
async closeConnection(options) {
|
|
3725
3799
|
const dbName = this.getOptionValue(options, 'database');
|
|
3726
3800
|
const readonly = options.readonly ? options.readonly : false;
|
|
3727
|
-
const connName = readonly ?
|
|
3801
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3728
3802
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3729
3803
|
if (database.isDBOpen()) {
|
|
3730
3804
|
// close the database
|
|
@@ -3747,7 +3821,7 @@ class CapacitorSQLite {
|
|
|
3747
3821
|
async open(options) {
|
|
3748
3822
|
const dbName = this.getOptionValue(options, 'database');
|
|
3749
3823
|
const readonly = options.readonly ? options.readonly : false;
|
|
3750
|
-
const connName = readonly ?
|
|
3824
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3751
3825
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3752
3826
|
try {
|
|
3753
3827
|
await database.open();
|
|
@@ -3760,7 +3834,7 @@ class CapacitorSQLite {
|
|
|
3760
3834
|
async close(options) {
|
|
3761
3835
|
const dbName = this.getOptionValue(options, 'database');
|
|
3762
3836
|
const readonly = options.readonly ? options.readonly : false;
|
|
3763
|
-
const connName = readonly ?
|
|
3837
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3764
3838
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3765
3839
|
if (database.isDBOpen()) {
|
|
3766
3840
|
try {
|
|
@@ -3779,7 +3853,7 @@ class CapacitorSQLite {
|
|
|
3779
3853
|
async getVersion(options) {
|
|
3780
3854
|
const dbName = this.getOptionValue(options, 'database');
|
|
3781
3855
|
const readonly = options.readonly ? options.readonly : false;
|
|
3782
|
-
const connName = readonly ?
|
|
3856
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3783
3857
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3784
3858
|
if (database.isDBOpen()) {
|
|
3785
3859
|
try {
|
|
@@ -3800,7 +3874,7 @@ class CapacitorSQLite {
|
|
|
3800
3874
|
async getTableList(options) {
|
|
3801
3875
|
const dbName = this.getOptionValue(options, 'database');
|
|
3802
3876
|
const readonly = options.readonly ? options.readonly : false;
|
|
3803
|
-
const connName = readonly ?
|
|
3877
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3804
3878
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3805
3879
|
if (database.isDBOpen()) {
|
|
3806
3880
|
try {
|
|
@@ -3823,11 +3897,11 @@ class CapacitorSQLite {
|
|
|
3823
3897
|
const statements = this.getOptionValue(options, 'statements');
|
|
3824
3898
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3825
3899
|
const readonly = options.readonly ? options.readonly : false;
|
|
3826
|
-
const connName =
|
|
3900
|
+
const connName = 'RW_' + dbName;
|
|
3827
3901
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3828
3902
|
if (database.isDBOpen()) {
|
|
3829
3903
|
if (readonly) {
|
|
3830
|
-
const msg =
|
|
3904
|
+
const msg = 'not allowed in read-only mode ';
|
|
3831
3905
|
throw new Error(`Execute: ${msg}`);
|
|
3832
3906
|
}
|
|
3833
3907
|
try {
|
|
@@ -3853,7 +3927,7 @@ class CapacitorSQLite {
|
|
|
3853
3927
|
const setOfStatements = this.getOptionValue(options, 'set');
|
|
3854
3928
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3855
3929
|
const readonly = options.readonly ? options.readonly : false;
|
|
3856
|
-
const connName =
|
|
3930
|
+
const connName = 'RW_' + dbName;
|
|
3857
3931
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3858
3932
|
for (const sStmt of setOfStatements) {
|
|
3859
3933
|
if (!('statement' in sStmt) || !('values' in sStmt)) {
|
|
@@ -3862,7 +3936,7 @@ class CapacitorSQLite {
|
|
|
3862
3936
|
}
|
|
3863
3937
|
if (database.isDBOpen()) {
|
|
3864
3938
|
if (readonly) {
|
|
3865
|
-
const msg =
|
|
3939
|
+
const msg = 'not allowed in read-only mode ';
|
|
3866
3940
|
throw new Error(`ExecuteSet failed: ${msg}`);
|
|
3867
3941
|
}
|
|
3868
3942
|
try {
|
|
@@ -3889,11 +3963,11 @@ class CapacitorSQLite {
|
|
|
3889
3963
|
const values = this.getOptionValue(options, 'values', []);
|
|
3890
3964
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3891
3965
|
const readonly = options.readonly ? options.readonly : false;
|
|
3892
|
-
const connName =
|
|
3966
|
+
const connName = 'RW_' + dbName;
|
|
3893
3967
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3894
3968
|
if (database.isDBOpen()) {
|
|
3895
3969
|
if (readonly) {
|
|
3896
|
-
const msg =
|
|
3970
|
+
const msg = 'not allowed in read-only mode ';
|
|
3897
3971
|
throw new Error(`Run failed: ${msg}`);
|
|
3898
3972
|
}
|
|
3899
3973
|
try {
|
|
@@ -3917,7 +3991,7 @@ class CapacitorSQLite {
|
|
|
3917
3991
|
throw new Error('Query: Statement may not be an empty string.');
|
|
3918
3992
|
}
|
|
3919
3993
|
const readonly = options.readonly ? options.readonly : false;
|
|
3920
|
-
const connName = readonly ?
|
|
3994
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3921
3995
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3922
3996
|
if (database.isDBOpen()) {
|
|
3923
3997
|
try {
|
|
@@ -3936,7 +4010,7 @@ class CapacitorSQLite {
|
|
|
3936
4010
|
async isDBExists(options) {
|
|
3937
4011
|
const dbName = this.getOptionValue(options, 'database');
|
|
3938
4012
|
const readonly = options.readonly ? options.readonly : false;
|
|
3939
|
-
const connName = readonly ?
|
|
4013
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3940
4014
|
this.getDatabaseConnectionOrThrowError(connName);
|
|
3941
4015
|
// if (database.isDBOpen()) {
|
|
3942
4016
|
const isExists = this.fileUtil.isFileExists(dbName + 'SQLite.db');
|
|
@@ -3949,7 +4023,7 @@ class CapacitorSQLite {
|
|
|
3949
4023
|
async isDBOpen(options) {
|
|
3950
4024
|
const dbName = this.getOptionValue(options, 'database');
|
|
3951
4025
|
const readonly = options.readonly ? options.readonly : false;
|
|
3952
|
-
const connName = readonly ?
|
|
4026
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3953
4027
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3954
4028
|
const isOpen = database.isDBOpen();
|
|
3955
4029
|
return { result: isOpen };
|
|
@@ -3963,7 +4037,7 @@ class CapacitorSQLite {
|
|
|
3963
4037
|
const dbName = this.getOptionValue(options, 'database');
|
|
3964
4038
|
const tableName = this.getOptionValue(options, 'table');
|
|
3965
4039
|
const readonly = options.readonly ? options.readonly : false;
|
|
3966
|
-
const connName = readonly ?
|
|
4040
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
3967
4041
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3968
4042
|
if (database.isDBOpen()) {
|
|
3969
4043
|
try {
|
|
@@ -3982,10 +4056,10 @@ class CapacitorSQLite {
|
|
|
3982
4056
|
async deleteDatabase(options) {
|
|
3983
4057
|
const dbName = this.getOptionValue(options, 'database');
|
|
3984
4058
|
const readonly = options.readonly ? options.readonly : false;
|
|
3985
|
-
const connName =
|
|
4059
|
+
const connName = 'RW_' + dbName;
|
|
3986
4060
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3987
4061
|
if (readonly) {
|
|
3988
|
-
const msg =
|
|
4062
|
+
const msg = 'not allowed in read-only mode ';
|
|
3989
4063
|
throw new Error(`DeleteDatabase failed: ${msg}`);
|
|
3990
4064
|
}
|
|
3991
4065
|
try {
|
|
@@ -4059,7 +4133,7 @@ class CapacitorSQLite {
|
|
|
4059
4133
|
const dbName = this.getOptionValue(options, 'database');
|
|
4060
4134
|
const exportMode = this.getOptionValue(options, 'jsonexportmode');
|
|
4061
4135
|
const readonly = options.readonly ? options.readonly : false;
|
|
4062
|
-
const connName = readonly ?
|
|
4136
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
4063
4137
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4064
4138
|
if (database.isDBOpen()) {
|
|
4065
4139
|
try {
|
|
@@ -4084,11 +4158,11 @@ class CapacitorSQLite {
|
|
|
4084
4158
|
async createSyncTable(options) {
|
|
4085
4159
|
const dbName = this.getOptionValue(options, 'database');
|
|
4086
4160
|
const readonly = options.readonly ? options.readonly : false;
|
|
4087
|
-
const connName =
|
|
4161
|
+
const connName = 'RW_' + dbName;
|
|
4088
4162
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4089
4163
|
if (database.isDBOpen()) {
|
|
4090
4164
|
if (readonly) {
|
|
4091
|
-
const msg =
|
|
4165
|
+
const msg = 'not allowed in read-only mode ';
|
|
4092
4166
|
throw new Error(`CreateSyncTable failed: ${msg}`);
|
|
4093
4167
|
}
|
|
4094
4168
|
try {
|
|
@@ -4110,11 +4184,11 @@ class CapacitorSQLite {
|
|
|
4110
4184
|
const dbName = this.getOptionValue(options, 'database');
|
|
4111
4185
|
const syncDate = this.getOptionValue(options, 'syncdate');
|
|
4112
4186
|
const readonly = options.readonly ? options.readonly : false;
|
|
4113
|
-
const connName =
|
|
4187
|
+
const connName = 'RW_' + dbName;
|
|
4114
4188
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4115
4189
|
if (database.isDBOpen()) {
|
|
4116
4190
|
if (readonly) {
|
|
4117
|
-
const msg =
|
|
4191
|
+
const msg = 'not allowed in read-only mode ';
|
|
4118
4192
|
throw new Error(`SetSyncDate failed: ${msg}`);
|
|
4119
4193
|
}
|
|
4120
4194
|
try {
|
|
@@ -4133,7 +4207,7 @@ class CapacitorSQLite {
|
|
|
4133
4207
|
async getSyncDate(options) {
|
|
4134
4208
|
const dbName = this.getOptionValue(options, 'database');
|
|
4135
4209
|
const readonly = options.readonly ? options.readonly : false;
|
|
4136
|
-
const connName = readonly ?
|
|
4210
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
4137
4211
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4138
4212
|
if (database.isDBOpen()) {
|
|
4139
4213
|
try {
|
|
@@ -4152,11 +4226,11 @@ class CapacitorSQLite {
|
|
|
4152
4226
|
async deleteExportedRows(options) {
|
|
4153
4227
|
const dbName = this.getOptionValue(options, 'database');
|
|
4154
4228
|
const readonly = options.readonly ? options.readonly : false;
|
|
4155
|
-
const connName =
|
|
4229
|
+
const connName = 'RW_' + dbName;
|
|
4156
4230
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4157
4231
|
if (database.isDBOpen()) {
|
|
4158
4232
|
if (readonly) {
|
|
4159
|
-
const msg =
|
|
4233
|
+
const msg = 'not allowed in read-only mode ';
|
|
4160
4234
|
throw new Error(`DeleteExportedRows: ${msg}`);
|
|
4161
4235
|
}
|
|
4162
4236
|
try {
|
|
@@ -4184,9 +4258,14 @@ class CapacitorSQLite {
|
|
|
4184
4258
|
if (typeof firstUpgrade.toVersion != 'number') {
|
|
4185
4259
|
throw new Error('upgrade.toVersion must be a number');
|
|
4186
4260
|
}
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4261
|
+
if (this.versionUpgrades[dbName]) {
|
|
4262
|
+
this.versionUpgrades[dbName][firstUpgrade.toVersion] = firstUpgrade;
|
|
4263
|
+
}
|
|
4264
|
+
else {
|
|
4265
|
+
const upgradeVersionDict = {};
|
|
4266
|
+
upgradeVersionDict[firstUpgrade.toVersion] = firstUpgrade;
|
|
4267
|
+
this.versionUpgrades[dbName] = upgradeVersionDict;
|
|
4268
|
+
}
|
|
4190
4269
|
return;
|
|
4191
4270
|
}
|
|
4192
4271
|
async copyFromAssets(options) {
|
|
@@ -4199,12 +4278,13 @@ class CapacitorSQLite {
|
|
|
4199
4278
|
const dbList = await this.fileUtil.getFileList(assetsDbPath);
|
|
4200
4279
|
// loop through the database files
|
|
4201
4280
|
dbList.forEach(async (db) => {
|
|
4202
|
-
if (
|
|
4281
|
+
if (this.fileUtil.getExtName(db) === '.db') {
|
|
4203
4282
|
// for each copy the file to the Application database folder
|
|
4204
4283
|
await this.fileUtil.copyFromAssetToDatabase(db, overwrite);
|
|
4205
4284
|
}
|
|
4206
|
-
if (
|
|
4207
|
-
|
|
4285
|
+
if (this.fileUtil.getExtName(db) === '.zip') {
|
|
4286
|
+
const assetPath = this.fileUtil.getAssetsDatabasesPath();
|
|
4287
|
+
await this.fileUtil.unzipDatabase(db, assetPath, overwrite);
|
|
4208
4288
|
}
|
|
4209
4289
|
});
|
|
4210
4290
|
return;
|
|
@@ -4213,6 +4293,25 @@ class CapacitorSQLite {
|
|
|
4213
4293
|
throw new Error(`CopyFromAssets: assets/databases folder does not exist:[${assetsDbPath}]`);
|
|
4214
4294
|
}
|
|
4215
4295
|
}
|
|
4296
|
+
async getFromHTTPRequest(options) {
|
|
4297
|
+
const url = this.getOptionValue(options, 'url', '');
|
|
4298
|
+
const overwrite = this.getOptionValue(options, 'overwrite', false);
|
|
4299
|
+
if (url.length === 0) {
|
|
4300
|
+
throw new Error(`getFromHTTPRequest: You must give a database url`);
|
|
4301
|
+
}
|
|
4302
|
+
const cachePath = this.fileUtil.getCachePath();
|
|
4303
|
+
await this.fileUtil.downloadFileFromHTTP(url, cachePath);
|
|
4304
|
+
if (this.fileUtil.getExtName(url) === '.zip') {
|
|
4305
|
+
const zipName = `${this.fileUtil.getBaseName(url)}.zip`;
|
|
4306
|
+
await this.fileUtil.unzipDatabase(zipName, cachePath, overwrite);
|
|
4307
|
+
}
|
|
4308
|
+
if (overwrite) {
|
|
4309
|
+
await this.fileUtil.moveDatabaseFromCache();
|
|
4310
|
+
}
|
|
4311
|
+
else {
|
|
4312
|
+
throw new Error(`getFromHTTPRequest: cannot move file from cache overwrite: ${overwrite}`);
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4216
4315
|
async getDatabaseList() {
|
|
4217
4316
|
// get the database folder
|
|
4218
4317
|
const pathDatabase = this.fileUtil.getDatabasesPath();
|
|
@@ -4227,11 +4326,16 @@ class CapacitorSQLite {
|
|
|
4227
4326
|
}
|
|
4228
4327
|
async checkConnectionsConsistency(options) {
|
|
4229
4328
|
const dbNames = this.getOptionValue(options, 'dbNames');
|
|
4329
|
+
const openModes = this.getOptionValue(options, 'openModes');
|
|
4230
4330
|
const checkConsistencyResult = {};
|
|
4231
4331
|
checkConsistencyResult.result = false;
|
|
4332
|
+
const dbConns = [];
|
|
4333
|
+
dbNames.forEach((value, i) => {
|
|
4334
|
+
dbConns.push(`${openModes[i]}_${value}`);
|
|
4335
|
+
});
|
|
4232
4336
|
try {
|
|
4233
4337
|
let inConnectionsSet = new Set(Object.keys(this.databases));
|
|
4234
|
-
const outConnectionSet = new Set(
|
|
4338
|
+
const outConnectionSet = new Set(dbConns);
|
|
4235
4339
|
if (outConnectionSet.size === 0) {
|
|
4236
4340
|
await this.resetDbDict(Object.keys(this.databases));
|
|
4237
4341
|
return Promise.resolve(checkConsistencyResult);
|
|
@@ -4245,7 +4349,7 @@ class CapacitorSQLite {
|
|
|
4245
4349
|
if (!Array.from(outConnectionSet.keys()).includes(key)) {
|
|
4246
4350
|
const opt = {};
|
|
4247
4351
|
let readonly = false;
|
|
4248
|
-
if (key.substring(0, 3) ===
|
|
4352
|
+
if (key.substring(0, 3) === 'RO_') {
|
|
4249
4353
|
readonly = true;
|
|
4250
4354
|
}
|
|
4251
4355
|
opt.database = key.substring(3);
|
|
@@ -4280,7 +4384,7 @@ class CapacitorSQLite {
|
|
|
4280
4384
|
for (const key of keys) {
|
|
4281
4385
|
const opt = {};
|
|
4282
4386
|
let readonly = false;
|
|
4283
|
-
if (key.substring(0, 3) ===
|
|
4387
|
+
if (key.substring(0, 3) === 'RO_') {
|
|
4284
4388
|
readonly = true;
|
|
4285
4389
|
}
|
|
4286
4390
|
opt.database = key.substring(3);
|