@capacitor-community/sqlite 4.1.0-6 → 4.1.0-8
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 +6 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +144 -83
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +41 -21
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +67 -67
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +5 -14
- package/dist/esm/definitions.d.ts +71 -9
- package/dist/esm/definitions.js +189 -101
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +189 -101
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +189 -101
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +300 -130
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +118 -52
- package/ios/Plugin/CapacitorSQLitePlugin.swift +53 -20
- package/ios/Plugin/Database.swift +7 -4
- package/ios/Plugin/Utils/UtilsUpgrade.swift +13 -22
- package/package.json +1 -1
package/electron/dist/plugin.js
CHANGED
|
@@ -28,6 +28,7 @@ var utilsSQLite = {};
|
|
|
28
28
|
|
|
29
29
|
Object.defineProperty(utilsSQLite, "__esModule", { value: true });
|
|
30
30
|
utilsSQLite.UtilsSQLite = void 0;
|
|
31
|
+
const SQLITE_OPEN_READONLY = 1;
|
|
31
32
|
class UtilsSQLite {
|
|
32
33
|
constructor() {
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
@@ -40,12 +41,20 @@ class UtilsSQLite {
|
|
|
40
41
|
* @param password
|
|
41
42
|
*/
|
|
42
43
|
async openOrCreateDatabase(pathDB /*,
|
|
43
|
-
password: string
|
|
44
|
+
password: string,*/, readonly) {
|
|
44
45
|
const msg = 'OpenOrCreateDatabase: ';
|
|
45
46
|
// open sqlite3 database
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
let mDB;
|
|
48
|
+
if (!readonly) {
|
|
49
|
+
mDB = new this.SQLite3.Database(pathDB, {
|
|
50
|
+
verbose: console.log,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
mDB = new this.SQLite3.Database(pathDB, SQLITE_OPEN_READONLY, {
|
|
55
|
+
verbose: console.log,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
49
58
|
if (mDB != null) {
|
|
50
59
|
try {
|
|
51
60
|
await this.dbChanges(mDB);
|
|
@@ -2781,7 +2790,7 @@ class UtilsFile {
|
|
|
2781
2790
|
const webDir = this.capConfig.webDir;
|
|
2782
2791
|
const dir = webDir === 'www' ? 'src' : 'public';
|
|
2783
2792
|
let mAppPath = this.appPath;
|
|
2784
|
-
if (this.Path.basename(this.appPath) ===
|
|
2793
|
+
if (this.Path.basename(this.appPath) === 'electron') {
|
|
2785
2794
|
mAppPath = this.Path.dirname(this.appPath);
|
|
2786
2795
|
}
|
|
2787
2796
|
retPath = this.Path.resolve(mAppPath, dir, 'assets', 'databases');
|
|
@@ -3168,7 +3177,7 @@ class Database {
|
|
|
3168
3177
|
constructor(dbName,
|
|
3169
3178
|
// encrypted: boolean,
|
|
3170
3179
|
// mode: string,
|
|
3171
|
-
version, upgDict) {
|
|
3180
|
+
version, readonly, upgDict) {
|
|
3172
3181
|
this.fileUtil = new utilsFile_1$1.UtilsFile();
|
|
3173
3182
|
this.sqliteUtil = new utilsSQLite_1.UtilsSQLite();
|
|
3174
3183
|
this.jsonUtil = new utilsJson_1$1.UtilsJson();
|
|
@@ -3182,6 +3191,7 @@ class Database {
|
|
|
3182
3191
|
// this._encrypted = encrypted;
|
|
3183
3192
|
// this._mode = mode;
|
|
3184
3193
|
this.version = version;
|
|
3194
|
+
this.readonly = readonly;
|
|
3185
3195
|
this.upgradeVersionDict = upgDict;
|
|
3186
3196
|
this.pathDB = this.fileUtil.getFilePath(dbName);
|
|
3187
3197
|
this._isDbOpen = false;
|
|
@@ -3227,25 +3237,27 @@ class Database {
|
|
|
3227
3237
|
}
|
|
3228
3238
|
*/
|
|
3229
3239
|
this.database = await this.sqliteUtil.openOrCreateDatabase(this.pathDB /*,
|
|
3230
|
-
password
|
|
3231
|
-
const curVersion = await this.sqliteUtil.getVersion(this.database);
|
|
3240
|
+
password,*/, this.readonly);
|
|
3232
3241
|
this._isDbOpen = true;
|
|
3233
|
-
if (this.
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
// execute the upgrade flow process
|
|
3238
|
-
await this.upgradeUtil.onUpgrade(this.database, this.upgradeVersionDict, curVersion, this.version);
|
|
3239
|
-
// delete the backup database
|
|
3240
|
-
await this.fileUtil.deleteFileName(`backup-${this.dbName}`);
|
|
3241
|
-
}
|
|
3242
|
-
catch (err) {
|
|
3243
|
-
// restore the database from backup
|
|
3242
|
+
if (!this.readonly) {
|
|
3243
|
+
const curVersion = await this.sqliteUtil.getVersion(this.database);
|
|
3244
|
+
if (this.version > curVersion &&
|
|
3245
|
+
Object.keys(this.upgradeVersionDict).length > 0) {
|
|
3244
3246
|
try {
|
|
3245
|
-
await this.fileUtil.
|
|
3247
|
+
await this.fileUtil.copyFileName(this.dbName, `backup-${this.dbName}`);
|
|
3248
|
+
// execute the upgrade flow process
|
|
3249
|
+
await this.upgradeUtil.onUpgrade(this.database, this.upgradeVersionDict, curVersion, this.version);
|
|
3250
|
+
// delete the backup database
|
|
3251
|
+
await this.fileUtil.deleteFileName(`backup-${this.dbName}`);
|
|
3246
3252
|
}
|
|
3247
3253
|
catch (err) {
|
|
3248
|
-
|
|
3254
|
+
// restore the database from backup
|
|
3255
|
+
try {
|
|
3256
|
+
await this.fileUtil.restoreFileName(this.dbName, 'backup');
|
|
3257
|
+
}
|
|
3258
|
+
catch (err) {
|
|
3259
|
+
throw new Error(`Open: ${err}`);
|
|
3260
|
+
}
|
|
3249
3261
|
}
|
|
3250
3262
|
}
|
|
3251
3263
|
}
|
|
@@ -3693,23 +3705,27 @@ class CapacitorSQLite {
|
|
|
3693
3705
|
? options.mode
|
|
3694
3706
|
: 'no-encryption';
|
|
3695
3707
|
*/
|
|
3708
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3696
3709
|
let upgrades = {};
|
|
3697
3710
|
const versionUpgradeKeys = Object.keys(this.versionUpgrades);
|
|
3698
3711
|
if (versionUpgradeKeys.length !== 0 &&
|
|
3699
3712
|
versionUpgradeKeys.includes(dbName)) {
|
|
3700
3713
|
upgrades = this.versionUpgrades[dbName];
|
|
3701
3714
|
}
|
|
3715
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3702
3716
|
const databaseConnection = new Database_1.Database(dbName + 'SQLite.db',
|
|
3703
3717
|
/* encrypted,
|
|
3704
3718
|
inMode,
|
|
3705
3719
|
*/
|
|
3706
|
-
version, upgrades);
|
|
3707
|
-
this.databases[
|
|
3720
|
+
version, readonly, upgrades);
|
|
3721
|
+
this.databases[connName] = databaseConnection;
|
|
3708
3722
|
return;
|
|
3709
3723
|
}
|
|
3710
3724
|
async closeConnection(options) {
|
|
3711
3725
|
const dbName = this.getOptionValue(options, 'database');
|
|
3712
|
-
const
|
|
3726
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3727
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3728
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3713
3729
|
if (database.isDBOpen()) {
|
|
3714
3730
|
// close the database
|
|
3715
3731
|
try {
|
|
@@ -3720,7 +3736,7 @@ class CapacitorSQLite {
|
|
|
3720
3736
|
}
|
|
3721
3737
|
}
|
|
3722
3738
|
// remove the connection from dictionary
|
|
3723
|
-
delete this.databases[
|
|
3739
|
+
delete this.databases[connName];
|
|
3724
3740
|
}
|
|
3725
3741
|
async echo(options) {
|
|
3726
3742
|
const echoValue = this.getOptionValue(options, 'value');
|
|
@@ -3730,7 +3746,9 @@ class CapacitorSQLite {
|
|
|
3730
3746
|
}
|
|
3731
3747
|
async open(options) {
|
|
3732
3748
|
const dbName = this.getOptionValue(options, 'database');
|
|
3733
|
-
const
|
|
3749
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3750
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3751
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3734
3752
|
try {
|
|
3735
3753
|
await database.open();
|
|
3736
3754
|
return;
|
|
@@ -3741,80 +3759,128 @@ class CapacitorSQLite {
|
|
|
3741
3759
|
}
|
|
3742
3760
|
async close(options) {
|
|
3743
3761
|
const dbName = this.getOptionValue(options, 'database');
|
|
3744
|
-
const
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3762
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3763
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3764
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3765
|
+
if (database.isDBOpen()) {
|
|
3766
|
+
try {
|
|
3767
|
+
await database.close();
|
|
3768
|
+
return;
|
|
3769
|
+
}
|
|
3770
|
+
catch (err) {
|
|
3771
|
+
throw new Error(`Close: ${err}`);
|
|
3772
|
+
}
|
|
3748
3773
|
}
|
|
3749
|
-
|
|
3750
|
-
|
|
3774
|
+
else {
|
|
3775
|
+
const msg = `Database ${dbName} not opened`;
|
|
3776
|
+
throw new Error(`Close: ${msg}`);
|
|
3751
3777
|
}
|
|
3752
3778
|
}
|
|
3753
3779
|
async getVersion(options) {
|
|
3754
3780
|
const dbName = this.getOptionValue(options, 'database');
|
|
3755
|
-
const
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3781
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3782
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3783
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3784
|
+
if (database.isDBOpen()) {
|
|
3785
|
+
try {
|
|
3786
|
+
const version = await database.getVersion();
|
|
3787
|
+
const versionResult = {};
|
|
3788
|
+
versionResult.version = version;
|
|
3789
|
+
return versionResult;
|
|
3790
|
+
}
|
|
3791
|
+
catch (err) {
|
|
3792
|
+
throw new Error(`GetVersion: ${err}`);
|
|
3793
|
+
}
|
|
3761
3794
|
}
|
|
3762
|
-
|
|
3763
|
-
|
|
3795
|
+
else {
|
|
3796
|
+
const msg = `Database ${dbName} not opened`;
|
|
3797
|
+
throw new Error(`GetVersion: ${msg}`);
|
|
3764
3798
|
}
|
|
3765
3799
|
}
|
|
3766
3800
|
async getTableList(options) {
|
|
3767
3801
|
const dbName = this.getOptionValue(options, 'database');
|
|
3768
|
-
const
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3802
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3803
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3804
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3805
|
+
if (database.isDBOpen()) {
|
|
3806
|
+
try {
|
|
3807
|
+
const tableList = await database.getTableList();
|
|
3808
|
+
const tableListResult = {};
|
|
3809
|
+
tableListResult.values = tableList;
|
|
3810
|
+
return tableListResult;
|
|
3811
|
+
}
|
|
3812
|
+
catch (err) {
|
|
3813
|
+
throw new Error(`GetTableList: ${err}`);
|
|
3814
|
+
}
|
|
3774
3815
|
}
|
|
3775
|
-
|
|
3776
|
-
|
|
3816
|
+
else {
|
|
3817
|
+
const msg = `Database ${dbName} not opened`;
|
|
3818
|
+
throw new Error(`GetTableList: ${msg}`);
|
|
3777
3819
|
}
|
|
3778
3820
|
}
|
|
3779
3821
|
async execute(options) {
|
|
3780
3822
|
const dbName = this.getOptionValue(options, 'database');
|
|
3781
3823
|
const statements = this.getOptionValue(options, 'statements');
|
|
3782
3824
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3783
|
-
const
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3825
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3826
|
+
const connName = "RW_" + dbName;
|
|
3827
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3828
|
+
if (database.isDBOpen()) {
|
|
3829
|
+
if (readonly) {
|
|
3830
|
+
const msg = "not allowed in read-only mode ";
|
|
3831
|
+
throw new Error(`Execute: ${msg}`);
|
|
3788
3832
|
}
|
|
3789
|
-
|
|
3790
|
-
|
|
3833
|
+
try {
|
|
3834
|
+
const executeResult = await database.executeSQL(statements, transaction);
|
|
3835
|
+
if (executeResult < 0) {
|
|
3836
|
+
throw new Error('Execute changes < 0');
|
|
3837
|
+
}
|
|
3838
|
+
else {
|
|
3839
|
+
return { changes: { changes: executeResult } };
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
catch (err) {
|
|
3843
|
+
throw new Error(`Execute: ${err}`);
|
|
3791
3844
|
}
|
|
3792
3845
|
}
|
|
3793
|
-
|
|
3794
|
-
|
|
3846
|
+
else {
|
|
3847
|
+
const msg = `Database ${dbName} not opened`;
|
|
3848
|
+
throw new Error(`Execute: ${msg}`);
|
|
3795
3849
|
}
|
|
3796
3850
|
}
|
|
3797
3851
|
async executeSet(options) {
|
|
3798
3852
|
const dbName = this.getOptionValue(options, 'database');
|
|
3799
3853
|
const setOfStatements = this.getOptionValue(options, 'set');
|
|
3800
3854
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3801
|
-
const
|
|
3855
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3856
|
+
const connName = "RW_" + dbName;
|
|
3857
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3802
3858
|
for (const sStmt of setOfStatements) {
|
|
3803
3859
|
if (!('statement' in sStmt) || !('values' in sStmt)) {
|
|
3804
3860
|
throw new Error('ExecuteSet: Must provide a set as ' + 'Array of {statement,values}');
|
|
3805
3861
|
}
|
|
3806
3862
|
}
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
throw new Error(`ExecuteSet failed
|
|
3863
|
+
if (database.isDBOpen()) {
|
|
3864
|
+
if (readonly) {
|
|
3865
|
+
const msg = "not allowed in read-only mode ";
|
|
3866
|
+
throw new Error(`ExecuteSet failed: ${msg}`);
|
|
3811
3867
|
}
|
|
3812
|
-
|
|
3813
|
-
|
|
3868
|
+
try {
|
|
3869
|
+
const execSetResult = await database.execSet(setOfStatements, transaction);
|
|
3870
|
+
if (execSetResult < 0) {
|
|
3871
|
+
throw new Error(`ExecuteSet failed changes <0`);
|
|
3872
|
+
}
|
|
3873
|
+
else {
|
|
3874
|
+
return { changes: execSetResult };
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
catch (err) {
|
|
3878
|
+
throw new Error(`ExecuteSet failed: ${err}`);
|
|
3814
3879
|
}
|
|
3815
3880
|
}
|
|
3816
|
-
|
|
3817
|
-
|
|
3881
|
+
else {
|
|
3882
|
+
const msg = `Database ${dbName} not opened`;
|
|
3883
|
+
throw new Error(`ExecuteSet failed: ${msg}`);
|
|
3818
3884
|
}
|
|
3819
3885
|
}
|
|
3820
3886
|
async run(options) {
|
|
@@ -3822,13 +3888,25 @@ class CapacitorSQLite {
|
|
|
3822
3888
|
const statement = this.getOptionValue(options, 'statement');
|
|
3823
3889
|
const values = this.getOptionValue(options, 'values', []);
|
|
3824
3890
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
3825
|
-
const
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3891
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3892
|
+
const connName = "RW_" + dbName;
|
|
3893
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3894
|
+
if (database.isDBOpen()) {
|
|
3895
|
+
if (readonly) {
|
|
3896
|
+
const msg = "not allowed in read-only mode ";
|
|
3897
|
+
throw new Error(`Run failed: ${msg}`);
|
|
3898
|
+
}
|
|
3899
|
+
try {
|
|
3900
|
+
const runResult = await database.runSQL(statement, values, transaction);
|
|
3901
|
+
return { changes: runResult };
|
|
3902
|
+
}
|
|
3903
|
+
catch (err) {
|
|
3904
|
+
throw new Error(`RUN failed: ${err} `);
|
|
3905
|
+
}
|
|
3829
3906
|
}
|
|
3830
|
-
|
|
3831
|
-
|
|
3907
|
+
else {
|
|
3908
|
+
const msg = `Database ${dbName} not opened`;
|
|
3909
|
+
throw new Error(`Run failed: ${msg}`);
|
|
3832
3910
|
}
|
|
3833
3911
|
}
|
|
3834
3912
|
async query(options) {
|
|
@@ -3836,28 +3914,44 @@ class CapacitorSQLite {
|
|
|
3836
3914
|
const statement = this.getOptionValue(options, 'statement');
|
|
3837
3915
|
const values = this.getOptionValue(options, 'values', []);
|
|
3838
3916
|
if (statement.length === 0) {
|
|
3839
|
-
throw new Error('Statement may not be an empty string.');
|
|
3917
|
+
throw new Error('Query: Statement may not be an empty string.');
|
|
3840
3918
|
}
|
|
3841
|
-
const
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3919
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3920
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3921
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3922
|
+
if (database.isDBOpen()) {
|
|
3923
|
+
try {
|
|
3924
|
+
const queryResult = await database.selectSQL(statement, values);
|
|
3925
|
+
return { values: queryResult };
|
|
3926
|
+
}
|
|
3927
|
+
catch (err) {
|
|
3928
|
+
throw new Error(`Query: ${err}`);
|
|
3929
|
+
}
|
|
3845
3930
|
}
|
|
3846
|
-
|
|
3847
|
-
|
|
3931
|
+
else {
|
|
3932
|
+
const msg = `Database ${dbName} not opened`;
|
|
3933
|
+
throw new Error(`Query: ${msg}`);
|
|
3848
3934
|
}
|
|
3849
3935
|
}
|
|
3850
3936
|
async isDBExists(options) {
|
|
3851
3937
|
const dbName = this.getOptionValue(options, 'database');
|
|
3852
|
-
|
|
3853
|
-
|
|
3938
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3939
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3940
|
+
this.getDatabaseConnectionOrThrowError(connName);
|
|
3941
|
+
// if (database.isDBOpen()) {
|
|
3854
3942
|
const isExists = this.fileUtil.isFileExists(dbName + 'SQLite.db');
|
|
3855
3943
|
return { result: isExists };
|
|
3944
|
+
// } else {
|
|
3945
|
+
// const msg = `Database ${dbName} not opened`;
|
|
3946
|
+
// throw new Error(`isDBExists: ${msg}`);
|
|
3947
|
+
// }
|
|
3856
3948
|
}
|
|
3857
3949
|
async isDBOpen(options) {
|
|
3858
3950
|
const dbName = this.getOptionValue(options, 'database');
|
|
3859
|
-
const
|
|
3860
|
-
const
|
|
3951
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3952
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3953
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3954
|
+
const isOpen = database.isDBOpen();
|
|
3861
3955
|
return { result: isOpen };
|
|
3862
3956
|
}
|
|
3863
3957
|
async isDatabase(options) {
|
|
@@ -3868,24 +3962,38 @@ class CapacitorSQLite {
|
|
|
3868
3962
|
async isTableExists(options) {
|
|
3869
3963
|
const dbName = this.getOptionValue(options, 'database');
|
|
3870
3964
|
const tableName = this.getOptionValue(options, 'table');
|
|
3871
|
-
const
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3965
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3966
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
3967
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3968
|
+
if (database.isDBOpen()) {
|
|
3969
|
+
try {
|
|
3970
|
+
const isTableExistsResult = await database.isTableExists(tableName);
|
|
3971
|
+
return { result: isTableExistsResult };
|
|
3972
|
+
}
|
|
3973
|
+
catch (err) {
|
|
3974
|
+
throw new Error(`isTableExists: ${err}`);
|
|
3975
|
+
}
|
|
3875
3976
|
}
|
|
3876
|
-
|
|
3877
|
-
|
|
3977
|
+
else {
|
|
3978
|
+
const msg = `Database ${dbName} not opened`;
|
|
3979
|
+
throw new Error(`isTableExists: ${msg}`);
|
|
3878
3980
|
}
|
|
3879
3981
|
}
|
|
3880
3982
|
async deleteDatabase(options) {
|
|
3881
3983
|
const dbName = this.getOptionValue(options, 'database');
|
|
3882
|
-
const
|
|
3984
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
3985
|
+
const connName = "RW_" + dbName;
|
|
3986
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
3987
|
+
if (readonly) {
|
|
3988
|
+
const msg = "not allowed in read-only mode ";
|
|
3989
|
+
throw new Error(`DeleteDatabase failed: ${msg}`);
|
|
3990
|
+
}
|
|
3883
3991
|
try {
|
|
3884
3992
|
await database.deleteDB(dbName + 'SQLite.db');
|
|
3885
3993
|
return;
|
|
3886
3994
|
}
|
|
3887
3995
|
catch (err) {
|
|
3888
|
-
throw new Error(`
|
|
3996
|
+
throw new Error(`DeleteDatabase: ${err}`);
|
|
3889
3997
|
}
|
|
3890
3998
|
}
|
|
3891
3999
|
async isJsonValid(options) {
|
|
@@ -3917,7 +4025,7 @@ class CapacitorSQLite {
|
|
|
3917
4025
|
// Create the database
|
|
3918
4026
|
const database = new Database_1.Database(dbName,
|
|
3919
4027
|
/*encrypted, mode, */
|
|
3920
|
-
targetDbVersion, {});
|
|
4028
|
+
targetDbVersion, false, {});
|
|
3921
4029
|
try {
|
|
3922
4030
|
if (overwrite && mode === 'full') {
|
|
3923
4031
|
const isExists = this.fileUtil.isFileExists(dbName);
|
|
@@ -3950,66 +4058,118 @@ class CapacitorSQLite {
|
|
|
3950
4058
|
async exportToJson(options) {
|
|
3951
4059
|
const dbName = this.getOptionValue(options, 'database');
|
|
3952
4060
|
const exportMode = this.getOptionValue(options, 'jsonexportmode');
|
|
3953
|
-
const
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
4061
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
4062
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
4063
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4064
|
+
if (database.isDBOpen()) {
|
|
4065
|
+
try {
|
|
4066
|
+
const exportJsonResult = await database.exportJson(exportMode);
|
|
4067
|
+
const resultKeys = Object.keys(exportJsonResult);
|
|
4068
|
+
if (resultKeys.includes('message')) {
|
|
4069
|
+
throw new Error(`exportToJson: ${exportJsonResult.message}`);
|
|
4070
|
+
}
|
|
4071
|
+
else {
|
|
4072
|
+
return { export: exportJsonResult };
|
|
4073
|
+
}
|
|
3959
4074
|
}
|
|
3960
|
-
|
|
3961
|
-
|
|
4075
|
+
catch (err) {
|
|
4076
|
+
throw new Error(`ExportToJson: ${err}`);
|
|
3962
4077
|
}
|
|
3963
4078
|
}
|
|
3964
|
-
|
|
3965
|
-
|
|
4079
|
+
else {
|
|
4080
|
+
const msg = `Database ${dbName} not opened`;
|
|
4081
|
+
throw new Error(`ExportToJson: ${msg}`);
|
|
3966
4082
|
}
|
|
3967
4083
|
}
|
|
3968
4084
|
async createSyncTable(options) {
|
|
3969
4085
|
const dbName = this.getOptionValue(options, 'database');
|
|
3970
|
-
const
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
4086
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
4087
|
+
const connName = "RW_" + dbName;
|
|
4088
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4089
|
+
if (database.isDBOpen()) {
|
|
4090
|
+
if (readonly) {
|
|
4091
|
+
const msg = "not allowed in read-only mode ";
|
|
4092
|
+
throw new Error(`CreateSyncTable failed: ${msg}`);
|
|
4093
|
+
}
|
|
4094
|
+
try {
|
|
4095
|
+
const createTableSyncResult = await database.createSyncTable();
|
|
4096
|
+
return {
|
|
4097
|
+
changes: { changes: createTableSyncResult },
|
|
4098
|
+
};
|
|
4099
|
+
}
|
|
4100
|
+
catch (err) {
|
|
4101
|
+
throw new Error(`CreateSyncTable: ${err}`);
|
|
4102
|
+
}
|
|
3976
4103
|
}
|
|
3977
|
-
|
|
3978
|
-
|
|
4104
|
+
else {
|
|
4105
|
+
const msg = `Database ${dbName} not opened`;
|
|
4106
|
+
throw new Error(`CreateSyncTable: ${msg}`);
|
|
3979
4107
|
}
|
|
3980
4108
|
}
|
|
3981
4109
|
async setSyncDate(options) {
|
|
3982
4110
|
const dbName = this.getOptionValue(options, 'database');
|
|
3983
4111
|
const syncDate = this.getOptionValue(options, 'syncdate');
|
|
3984
|
-
const
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
4112
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
4113
|
+
const connName = "RW_" + dbName;
|
|
4114
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4115
|
+
if (database.isDBOpen()) {
|
|
4116
|
+
if (readonly) {
|
|
4117
|
+
const msg = "not allowed in read-only mode ";
|
|
4118
|
+
throw new Error(`SetSyncDate failed: ${msg}`);
|
|
4119
|
+
}
|
|
4120
|
+
try {
|
|
4121
|
+
await database.setSyncDate(syncDate);
|
|
4122
|
+
return;
|
|
4123
|
+
}
|
|
4124
|
+
catch (err) {
|
|
4125
|
+
throw new Error(`SetSyncDate: ${err}`);
|
|
4126
|
+
}
|
|
3988
4127
|
}
|
|
3989
|
-
|
|
3990
|
-
|
|
4128
|
+
else {
|
|
4129
|
+
const msg = `Database ${dbName} not opened`;
|
|
4130
|
+
throw new Error(`SetSyncDate: ${msg}`);
|
|
3991
4131
|
}
|
|
3992
4132
|
}
|
|
3993
4133
|
async getSyncDate(options) {
|
|
3994
4134
|
const dbName = this.getOptionValue(options, 'database');
|
|
3995
|
-
const
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
4135
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
4136
|
+
const connName = readonly ? "RO_" + dbName : "RW_" + dbName;
|
|
4137
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4138
|
+
if (database.isDBOpen()) {
|
|
4139
|
+
try {
|
|
4140
|
+
const ret = await database.getSyncDate();
|
|
4141
|
+
return Promise.resolve(ret);
|
|
4142
|
+
}
|
|
4143
|
+
catch (err) {
|
|
4144
|
+
throw new Error(`GetSyncDate: ${err}`);
|
|
4145
|
+
}
|
|
3999
4146
|
}
|
|
4000
|
-
|
|
4001
|
-
|
|
4147
|
+
else {
|
|
4148
|
+
const msg = `Database ${dbName} not opened`;
|
|
4149
|
+
throw new Error(`GetSyncDate: ${msg}`);
|
|
4002
4150
|
}
|
|
4003
4151
|
}
|
|
4004
4152
|
async deleteExportedRows(options) {
|
|
4005
4153
|
const dbName = this.getOptionValue(options, 'database');
|
|
4006
|
-
const
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4154
|
+
const readonly = options.readonly ? options.readonly : false;
|
|
4155
|
+
const connName = "RW_" + dbName;
|
|
4156
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4157
|
+
if (database.isDBOpen()) {
|
|
4158
|
+
if (readonly) {
|
|
4159
|
+
const msg = "not allowed in read-only mode ";
|
|
4160
|
+
throw new Error(`DeleteExportedRows: ${msg}`);
|
|
4161
|
+
}
|
|
4162
|
+
try {
|
|
4163
|
+
await database.deleteExportedRows();
|
|
4164
|
+
return Promise.resolve();
|
|
4165
|
+
}
|
|
4166
|
+
catch (err) {
|
|
4167
|
+
throw new Error(`DeleteExportedRows: ${err}`);
|
|
4168
|
+
}
|
|
4010
4169
|
}
|
|
4011
|
-
|
|
4012
|
-
|
|
4170
|
+
else {
|
|
4171
|
+
const msg = `Database ${dbName} not opened`;
|
|
4172
|
+
throw new Error(`DeleteExportedRows: ${msg}`);
|
|
4013
4173
|
}
|
|
4014
4174
|
}
|
|
4015
4175
|
async addUpgradeStatement(options) {
|
|
@@ -4084,7 +4244,12 @@ class CapacitorSQLite {
|
|
|
4084
4244
|
for (const key of inConnectionsSet) {
|
|
4085
4245
|
if (!Array.from(outConnectionSet.keys()).includes(key)) {
|
|
4086
4246
|
const opt = {};
|
|
4087
|
-
|
|
4247
|
+
let readonly = false;
|
|
4248
|
+
if (key.substring(0, 3) === "RO_") {
|
|
4249
|
+
readonly = true;
|
|
4250
|
+
}
|
|
4251
|
+
opt.database = key.substring(3);
|
|
4252
|
+
opt.readonly = readonly;
|
|
4088
4253
|
await this.closeConnection(opt);
|
|
4089
4254
|
}
|
|
4090
4255
|
}
|
|
@@ -4114,7 +4279,12 @@ class CapacitorSQLite {
|
|
|
4114
4279
|
try {
|
|
4115
4280
|
for (const key of keys) {
|
|
4116
4281
|
const opt = {};
|
|
4117
|
-
|
|
4282
|
+
let readonly = false;
|
|
4283
|
+
if (key.substring(0, 3) === "RO_") {
|
|
4284
|
+
readonly = true;
|
|
4285
|
+
}
|
|
4286
|
+
opt.database = key.substring(3);
|
|
4287
|
+
opt.readonly = readonly;
|
|
4118
4288
|
await this.closeConnection(opt);
|
|
4119
4289
|
}
|
|
4120
4290
|
}
|