@capacitor-community/sqlite 5.5.1 → 5.6.0
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 +2 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +217 -218
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +103 -102
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web-typeorm-utils/database.d.ts +21 -0
- package/dist/esm/web-typeorm-utils/database.js +91 -0
- package/dist/esm/web-typeorm-utils/database.js.map +1 -0
- package/dist/esm/web-typeorm-utils/utilsSQLite.d.ts +28 -0
- package/dist/esm/web-typeorm-utils/utilsSQLite.js +233 -0
- package/dist/esm/web-typeorm-utils/utilsSQLite.js.map +1 -0
- package/dist/esm/web.d.ts +4 -2
- package/dist/esm/web.js +210 -56
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +519 -49
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +519 -49
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +14 -6
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +3 -4
- package/ios/Plugin/Database.swift +3 -1
- package/ios/Plugin/Utils/UtilsDelete.swift +1 -1
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +1 -2
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +35 -37
- package/package.json +6 -6
- package/src/definitions.ts +0 -1
- package/src/web-typeorm-utils/database.ts +111 -0
- package/src/web-typeorm-utils/utilsSQLite.ts +249 -0
- package/src/web.ts +212 -62
package/dist/plugin.js
CHANGED
|
@@ -947,11 +947,335 @@ var capacitorCapacitorSQLite = (function (exports, core) {
|
|
|
947
947
|
electron: () => window.CapacitorCustomPlatform.plugins.CapacitorSQLite,
|
|
948
948
|
});
|
|
949
949
|
|
|
950
|
+
/************************************************
|
|
951
|
+
* Only to be used to run TypeOrm Cli
|
|
952
|
+
* migration:generate
|
|
953
|
+
* A in-memory database is used
|
|
954
|
+
************************************************
|
|
955
|
+
*/
|
|
956
|
+
class UtilsSQLite {
|
|
957
|
+
constructor() {
|
|
958
|
+
this.isExists = false;
|
|
959
|
+
this.retExists = { isExists: false, pathWasm: '' };
|
|
960
|
+
this.initSqlJs = require('sql.js');
|
|
961
|
+
this.OS = require('os');
|
|
962
|
+
this.FS = require('fs');
|
|
963
|
+
this.Path = require('path');
|
|
964
|
+
}
|
|
965
|
+
getTypeOrmDBFolder() {
|
|
966
|
+
// Find the index of the "node_modules" string in the path
|
|
967
|
+
const nodeModulesIndex = __dirname.indexOf('node_modules');
|
|
968
|
+
// Extract the part of the path before "node_modules"
|
|
969
|
+
const outputPath = __dirname.slice(0, nodeModulesIndex);
|
|
970
|
+
// Extract the App name
|
|
971
|
+
const appName = this.Path.basename(outputPath);
|
|
972
|
+
// Get the Documents path
|
|
973
|
+
const documentsDirectory = this.Path.join(this.OS.homedir(), 'Documents');
|
|
974
|
+
// Add "CapacitorSQLite" and appName
|
|
975
|
+
const outputFolderPath = this.Path.join(documentsDirectory, 'CapacitorSQLite', appName);
|
|
976
|
+
// Ensure the output folder exists
|
|
977
|
+
this.FS.mkdirSync(outputFolderPath, { recursive: true });
|
|
978
|
+
return outputFolderPath;
|
|
979
|
+
}
|
|
980
|
+
getTypeOrmDBPath(outputFolderPath, dbName) {
|
|
981
|
+
return this.Path.resolve(outputFolderPath, dbName);
|
|
982
|
+
}
|
|
983
|
+
async checkFileExistence(wasmPath) {
|
|
984
|
+
// check if a public folder exists
|
|
985
|
+
const folder = (await this.checkFolderExistence('public'))
|
|
986
|
+
? 'public'
|
|
987
|
+
: 'src';
|
|
988
|
+
const pathWasm = this.Path.join(folder, wasmPath);
|
|
989
|
+
const retObj = {};
|
|
990
|
+
retObj.pathWasm = pathWasm;
|
|
991
|
+
try {
|
|
992
|
+
if (this.FS.existsSync(pathWasm)) {
|
|
993
|
+
retObj.isExists = true;
|
|
994
|
+
return Promise.resolve(retObj);
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
retObj.isExists = false;
|
|
998
|
+
return Promise.resolve(retObj);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
catch (err) {
|
|
1002
|
+
retObj.isExists = false;
|
|
1003
|
+
return Promise.resolve(retObj);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
async checkFolderExistence(folder) {
|
|
1007
|
+
try {
|
|
1008
|
+
if (this.FS.existsSync(folder)) {
|
|
1009
|
+
return Promise.resolve(true);
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
return Promise.resolve(false);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
catch (err) {
|
|
1016
|
+
return Promise.resolve(false);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
async openOrCreateDatabase(wasmPath, databasePath) {
|
|
1020
|
+
let mDB;
|
|
1021
|
+
const msg = 'OpenOrCreateDatabase';
|
|
1022
|
+
try {
|
|
1023
|
+
this.retExists = await this.checkFileExistence(wasmPath);
|
|
1024
|
+
this.isExists = this.retExists.isExists;
|
|
1025
|
+
}
|
|
1026
|
+
catch (err) {
|
|
1027
|
+
this.isExists = false;
|
|
1028
|
+
}
|
|
1029
|
+
if (!this.isExists) {
|
|
1030
|
+
return Promise.reject(msg + ' No sql-wasm.wasm found in ' + wasmPath);
|
|
1031
|
+
}
|
|
1032
|
+
try {
|
|
1033
|
+
const config = {
|
|
1034
|
+
locateFile: (file) => `${this.retExists.pathWasm}/${file}`,
|
|
1035
|
+
};
|
|
1036
|
+
const SQL = await this.initSqlJs(config);
|
|
1037
|
+
// Check if the database exists
|
|
1038
|
+
if (!this.FS.existsSync(databasePath)) {
|
|
1039
|
+
mDB = new SQL.Database();
|
|
1040
|
+
}
|
|
1041
|
+
else {
|
|
1042
|
+
// Read the database file from the local disk
|
|
1043
|
+
const fileBuffer = this.FS.readFileSync(databasePath);
|
|
1044
|
+
// Create a new database instance
|
|
1045
|
+
mDB = new SQL.Database(fileBuffer);
|
|
1046
|
+
}
|
|
1047
|
+
return Promise.resolve(mDB);
|
|
1048
|
+
}
|
|
1049
|
+
catch (err) {
|
|
1050
|
+
return Promise.reject(msg + ' open database failed');
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
async saveDatabase(mDb, outputPath) {
|
|
1054
|
+
try {
|
|
1055
|
+
// Export the modified database to a Uint8Array
|
|
1056
|
+
const data = mDb.export();
|
|
1057
|
+
// Write the Uint8Array to a file on the local disk
|
|
1058
|
+
this.FS.writeFileSync(outputPath, Buffer.from(data));
|
|
1059
|
+
return Promise.resolve();
|
|
1060
|
+
}
|
|
1061
|
+
catch (error) {
|
|
1062
|
+
return Promise.reject(error);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
closeDB(mDB) {
|
|
1066
|
+
const msg = 'closeDB';
|
|
1067
|
+
try {
|
|
1068
|
+
mDB.close();
|
|
1069
|
+
return Promise.resolve();
|
|
1070
|
+
}
|
|
1071
|
+
catch (err) {
|
|
1072
|
+
const errmsg = err.message ? err.message : err;
|
|
1073
|
+
return Promise.reject(`${msg} ${errmsg}`);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
async dbChanges(mDB) {
|
|
1077
|
+
const SELECT_CHANGE = 'SELECT total_changes()';
|
|
1078
|
+
let changes = 0;
|
|
1079
|
+
try {
|
|
1080
|
+
const res = mDB.exec(SELECT_CHANGE);
|
|
1081
|
+
// process the row here
|
|
1082
|
+
changes = res[0].values[0][0];
|
|
1083
|
+
return Promise.resolve(changes);
|
|
1084
|
+
}
|
|
1085
|
+
catch (err) {
|
|
1086
|
+
const errmsg = err.message ? err.message : err;
|
|
1087
|
+
return Promise.reject(`DbChanges failed: ${errmsg}`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
async getLastId(mDB) {
|
|
1091
|
+
const SELECT_LAST_ID = 'SELECT last_insert_rowid()';
|
|
1092
|
+
let lastId = -1;
|
|
1093
|
+
try {
|
|
1094
|
+
const res = mDB.exec(SELECT_LAST_ID);
|
|
1095
|
+
// process the row here
|
|
1096
|
+
lastId = res[0].values[0][0];
|
|
1097
|
+
return Promise.resolve(lastId);
|
|
1098
|
+
}
|
|
1099
|
+
catch (err) {
|
|
1100
|
+
const errmsg = err.message ? err.message : err;
|
|
1101
|
+
return Promise.reject(new Error(`GetLastId failed: ${errmsg}`));
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
async execute(mDB, sql) {
|
|
1105
|
+
try {
|
|
1106
|
+
mDB.exec(sql);
|
|
1107
|
+
const changes = await this.dbChanges(mDB);
|
|
1108
|
+
return Promise.resolve(changes);
|
|
1109
|
+
}
|
|
1110
|
+
catch (err) {
|
|
1111
|
+
const errmsg = err.message ? err.message : err;
|
|
1112
|
+
return Promise.reject(new Error(`Execute failed: ${errmsg}`));
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
async run(mDB, statement, values, returnMode) {
|
|
1116
|
+
let res;
|
|
1117
|
+
let retValues = [];
|
|
1118
|
+
const retObj = {};
|
|
1119
|
+
try {
|
|
1120
|
+
if (values.length > 0) {
|
|
1121
|
+
res = mDB.exec(statement, values);
|
|
1122
|
+
}
|
|
1123
|
+
else {
|
|
1124
|
+
res = mDB.exec(statement);
|
|
1125
|
+
}
|
|
1126
|
+
if (returnMode === 'all' || returnMode === 'one') {
|
|
1127
|
+
if (res && res.length > 0) {
|
|
1128
|
+
retValues = this.getReturnedValues(res[0], returnMode);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
const lastId = await this.getLastId(mDB);
|
|
1132
|
+
retObj['lastId'] = lastId;
|
|
1133
|
+
if (retValues != null && retValues.length > 0)
|
|
1134
|
+
retObj['values'] = retValues;
|
|
1135
|
+
return Promise.resolve(retObj);
|
|
1136
|
+
}
|
|
1137
|
+
catch (err) {
|
|
1138
|
+
const errmsg = err.message ? err.message : err;
|
|
1139
|
+
return Promise.reject(new Error(`Run failed: ${errmsg}`));
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
getReturnedValues(result, returnMode) {
|
|
1143
|
+
const retValues = [];
|
|
1144
|
+
for (const values of result.values) {
|
|
1145
|
+
const row = {};
|
|
1146
|
+
for (let j = 0; j < result.columns.length; j++) {
|
|
1147
|
+
row[result.columns[j]] = values[j];
|
|
1148
|
+
}
|
|
1149
|
+
retValues.push(row);
|
|
1150
|
+
if (returnMode === 'one') {
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return retValues;
|
|
1155
|
+
}
|
|
1156
|
+
async queryAll(mDB, sql, values) {
|
|
1157
|
+
try {
|
|
1158
|
+
let retArr = [];
|
|
1159
|
+
if (values != null && values.length > 0) {
|
|
1160
|
+
retArr = mDB.exec(sql, values);
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
retArr = mDB.exec(sql);
|
|
1164
|
+
}
|
|
1165
|
+
if (retArr.length == 0)
|
|
1166
|
+
return Promise.resolve([]);
|
|
1167
|
+
const result = retArr[0].values.map((entry) => {
|
|
1168
|
+
const obj = {};
|
|
1169
|
+
retArr[0].columns.forEach((column, index) => {
|
|
1170
|
+
obj[`${column}`] = entry[index];
|
|
1171
|
+
});
|
|
1172
|
+
return obj;
|
|
1173
|
+
});
|
|
1174
|
+
return Promise.resolve(result);
|
|
1175
|
+
}
|
|
1176
|
+
catch (err) {
|
|
1177
|
+
const errmsg = err.message ? err.message : err;
|
|
1178
|
+
return Promise.reject(new Error(`queryAll: ${errmsg}`));
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
/************************************************
|
|
1184
|
+
* Only to be used to run TypeOrm Cli
|
|
1185
|
+
* migration:generate
|
|
1186
|
+
* A in-memory database is used
|
|
1187
|
+
************************************************
|
|
1188
|
+
*/
|
|
1189
|
+
class Database {
|
|
1190
|
+
constructor() {
|
|
1191
|
+
this.wasmPath = 'assets';
|
|
1192
|
+
this.sqliteUtil = new UtilsSQLite();
|
|
1193
|
+
this.typeOrmDBFolder = this.sqliteUtil.getTypeOrmDBFolder();
|
|
1194
|
+
this.dbPath = '';
|
|
1195
|
+
this.mDb = null;
|
|
1196
|
+
this._isDBOpen = false;
|
|
1197
|
+
}
|
|
1198
|
+
async open(dbName) {
|
|
1199
|
+
try {
|
|
1200
|
+
this.dbPath = this.sqliteUtil.getTypeOrmDBPath(this.typeOrmDBFolder, `${dbName}SQLite.db`);
|
|
1201
|
+
this.mDb = await this.sqliteUtil.openOrCreateDatabase(this.wasmPath, this.dbPath);
|
|
1202
|
+
this._isDBOpen = true;
|
|
1203
|
+
return Promise.resolve();
|
|
1204
|
+
}
|
|
1205
|
+
catch (err) {
|
|
1206
|
+
return Promise.reject(`Open: ${err}`);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
async close() {
|
|
1210
|
+
try {
|
|
1211
|
+
if (this._isDBOpen) {
|
|
1212
|
+
await this.sqliteUtil.saveDatabase(this.mDb, this.dbPath);
|
|
1213
|
+
await this.mDb.close();
|
|
1214
|
+
}
|
|
1215
|
+
return Promise.resolve();
|
|
1216
|
+
}
|
|
1217
|
+
catch (err) {
|
|
1218
|
+
return Promise.reject(`Close: ${err}`);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
async executeSQL(statements) {
|
|
1222
|
+
let changes = -1;
|
|
1223
|
+
try {
|
|
1224
|
+
if (this._isDBOpen) {
|
|
1225
|
+
const initChanges = await this.sqliteUtil.dbChanges(this.mDb);
|
|
1226
|
+
changes = await this.sqliteUtil.execute(this.mDb, statements);
|
|
1227
|
+
if (changes < 0) {
|
|
1228
|
+
return Promise.reject(new Error('ExecuteSQL: changes < 0'));
|
|
1229
|
+
}
|
|
1230
|
+
changes = (await this.sqliteUtil.dbChanges(this.mDb)) - initChanges;
|
|
1231
|
+
}
|
|
1232
|
+
return Promise.resolve(changes);
|
|
1233
|
+
}
|
|
1234
|
+
catch (err) {
|
|
1235
|
+
return Promise.reject(`ExecuteSQL: ${err}`);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
async run(statement, values, returnMode) {
|
|
1239
|
+
const retRes = { changes: -1, lastId: -1 };
|
|
1240
|
+
try {
|
|
1241
|
+
if (this._isDBOpen) {
|
|
1242
|
+
const initChanges = await this.sqliteUtil.dbChanges(this.mDb);
|
|
1243
|
+
const retObj = await this.sqliteUtil.run(this.mDb, statement, values, returnMode);
|
|
1244
|
+
const lastId = retObj['lastId'];
|
|
1245
|
+
if (lastId < 0) {
|
|
1246
|
+
return Promise.reject(new Error('RunSQL: lastId < 0'));
|
|
1247
|
+
}
|
|
1248
|
+
const changes = (await this.sqliteUtil.dbChanges(this.mDb)) - initChanges;
|
|
1249
|
+
retRes.changes = changes;
|
|
1250
|
+
retRes.lastId = lastId;
|
|
1251
|
+
retRes.values = retObj['values'] ? retObj['values'] : [];
|
|
1252
|
+
}
|
|
1253
|
+
return Promise.resolve({ changes: retRes });
|
|
1254
|
+
}
|
|
1255
|
+
catch (err) {
|
|
1256
|
+
return Promise.reject(`Run: ${err}`);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
async selectSQL(sql, values) {
|
|
1260
|
+
let retArr = [];
|
|
1261
|
+
try {
|
|
1262
|
+
if (this._isDBOpen) {
|
|
1263
|
+
retArr = await this.sqliteUtil.queryAll(this.mDb, sql, values);
|
|
1264
|
+
}
|
|
1265
|
+
return Promise.resolve({ values: retArr });
|
|
1266
|
+
}
|
|
1267
|
+
catch (err) {
|
|
1268
|
+
return Promise.reject(`SelectSQL: ${err}`);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
950
1273
|
class CapacitorSQLiteWeb extends core.WebPlugin {
|
|
951
1274
|
constructor() {
|
|
952
1275
|
super(...arguments);
|
|
953
1276
|
this.jeepSqliteElement = null;
|
|
954
1277
|
this.isWebStoreOpen = false;
|
|
1278
|
+
this.databases = {};
|
|
955
1279
|
}
|
|
956
1280
|
async initWebStore() {
|
|
957
1281
|
await customElements.whenDefined('jeep-sqlite');
|
|
@@ -1016,36 +1340,88 @@ var capacitorCapacitorSQLite = (function (exports, core) {
|
|
|
1016
1340
|
return echoResult;
|
|
1017
1341
|
}
|
|
1018
1342
|
async createConnection(options) {
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1343
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
1344
|
+
this.ensureJeepSqliteIsAvailable();
|
|
1345
|
+
this.ensureWebstoreIsOpen();
|
|
1346
|
+
try {
|
|
1347
|
+
await this.jeepSqliteElement.createConnection(options);
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
catch (err) {
|
|
1351
|
+
throw new Error(`${err}`);
|
|
1352
|
+
}
|
|
1024
1353
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1354
|
+
else {
|
|
1355
|
+
// Only for typeOrm to run migration:generate
|
|
1356
|
+
const optionKeys = Object.keys(options);
|
|
1357
|
+
let dbName;
|
|
1358
|
+
if (!optionKeys.includes('database')) {
|
|
1359
|
+
throw new Error('Must provide a database name');
|
|
1360
|
+
}
|
|
1361
|
+
else {
|
|
1362
|
+
dbName = options.database;
|
|
1363
|
+
}
|
|
1364
|
+
const connName = 'RW_' + dbName;
|
|
1365
|
+
const databaseConnection = new Database();
|
|
1366
|
+
this.databases[connName] = databaseConnection;
|
|
1027
1367
|
}
|
|
1028
1368
|
}
|
|
1029
1369
|
async open(options) {
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1370
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
1371
|
+
this.ensureJeepSqliteIsAvailable();
|
|
1372
|
+
this.ensureWebstoreIsOpen();
|
|
1373
|
+
try {
|
|
1374
|
+
await this.jeepSqliteElement.open(options);
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
catch (err) {
|
|
1378
|
+
throw new Error(`${err}`);
|
|
1379
|
+
}
|
|
1035
1380
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1381
|
+
else {
|
|
1382
|
+
// Only for typeOrm to run migration:generate
|
|
1383
|
+
const dbName = options.database ? options.database : '';
|
|
1384
|
+
if (dbName.length === 0) {
|
|
1385
|
+
throw new Error('Must provide a database name');
|
|
1386
|
+
}
|
|
1387
|
+
const connName = 'RW_' + dbName;
|
|
1388
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
1389
|
+
try {
|
|
1390
|
+
await database.open(dbName);
|
|
1391
|
+
}
|
|
1392
|
+
catch (err) {
|
|
1393
|
+
throw new Error(`### open ${err}`);
|
|
1394
|
+
}
|
|
1038
1395
|
}
|
|
1039
1396
|
}
|
|
1040
1397
|
async closeConnection(options) {
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1398
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
1399
|
+
this.ensureJeepSqliteIsAvailable();
|
|
1400
|
+
this.ensureWebstoreIsOpen();
|
|
1401
|
+
try {
|
|
1402
|
+
await this.jeepSqliteElement.closeConnection(options);
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
catch (err) {
|
|
1406
|
+
throw new Error(`${err}`);
|
|
1407
|
+
}
|
|
1046
1408
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1409
|
+
else {
|
|
1410
|
+
// Only for typeOrm to run migration:generate
|
|
1411
|
+
const dbName = options.database ? options.database : '';
|
|
1412
|
+
if (dbName.length === 0) {
|
|
1413
|
+
throw new Error('Must provide a database name');
|
|
1414
|
+
}
|
|
1415
|
+
const connName = 'RW_' + dbName;
|
|
1416
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
1417
|
+
try {
|
|
1418
|
+
await database.close();
|
|
1419
|
+
// remove the connection from dictionary
|
|
1420
|
+
delete this.databases[connName];
|
|
1421
|
+
}
|
|
1422
|
+
catch (err) {
|
|
1423
|
+
throw new Error(`### closeConnection ${err}`);
|
|
1424
|
+
}
|
|
1049
1425
|
}
|
|
1050
1426
|
}
|
|
1051
1427
|
async getVersion(options) {
|
|
@@ -1070,14 +1446,31 @@ var capacitorCapacitorSQLite = (function (exports, core) {
|
|
|
1070
1446
|
}
|
|
1071
1447
|
}
|
|
1072
1448
|
async close(options) {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1449
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
1450
|
+
this.ensureJeepSqliteIsAvailable();
|
|
1451
|
+
this.ensureWebstoreIsOpen();
|
|
1452
|
+
try {
|
|
1453
|
+
await this.jeepSqliteElement.close(options);
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
catch (err) {
|
|
1457
|
+
throw new Error(`${err}`);
|
|
1458
|
+
}
|
|
1078
1459
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1460
|
+
else {
|
|
1461
|
+
// Only for typeOrm to run migration:generate
|
|
1462
|
+
const dbName = options.database ? options.database : '';
|
|
1463
|
+
if (dbName.length === 0) {
|
|
1464
|
+
throw new Error('Must provide a database name');
|
|
1465
|
+
}
|
|
1466
|
+
const connName = 'RW_' + dbName;
|
|
1467
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
1468
|
+
try {
|
|
1469
|
+
await database.close();
|
|
1470
|
+
}
|
|
1471
|
+
catch (err) {
|
|
1472
|
+
throw new Error(`### close ${err}`);
|
|
1473
|
+
}
|
|
1081
1474
|
}
|
|
1082
1475
|
}
|
|
1083
1476
|
async beginTransaction(options) {
|
|
@@ -1136,14 +1529,37 @@ var capacitorCapacitorSQLite = (function (exports, core) {
|
|
|
1136
1529
|
}
|
|
1137
1530
|
}
|
|
1138
1531
|
async execute(options) {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1532
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
1533
|
+
this.ensureJeepSqliteIsAvailable();
|
|
1534
|
+
this.ensureWebstoreIsOpen();
|
|
1535
|
+
try {
|
|
1536
|
+
const executeResult = await this.jeepSqliteElement.execute(options);
|
|
1537
|
+
return executeResult;
|
|
1538
|
+
}
|
|
1539
|
+
catch (err) {
|
|
1540
|
+
throw new Error(`${err}`);
|
|
1541
|
+
}
|
|
1144
1542
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1543
|
+
else {
|
|
1544
|
+
// Only for typeOrm to run migration:generate
|
|
1545
|
+
const dbName = options.database ? options.database : '';
|
|
1546
|
+
if (dbName.length === 0) {
|
|
1547
|
+
throw new Error('Must provide a database name');
|
|
1548
|
+
}
|
|
1549
|
+
const statements = options.statements ? options.statements : '';
|
|
1550
|
+
if (statements.length === 0) {
|
|
1551
|
+
return Promise.reject('Must provide raw SQL statements');
|
|
1552
|
+
}
|
|
1553
|
+
const connName = 'RW_' + dbName;
|
|
1554
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
1555
|
+
try {
|
|
1556
|
+
const ret = await database.executeSQL(statements);
|
|
1557
|
+
const executeResult = { changes: { changes: ret } };
|
|
1558
|
+
return executeResult;
|
|
1559
|
+
}
|
|
1560
|
+
catch (err) {
|
|
1561
|
+
throw new Error(`${err}`);
|
|
1562
|
+
}
|
|
1147
1563
|
}
|
|
1148
1564
|
}
|
|
1149
1565
|
async executeSet(options) {
|
|
@@ -1158,25 +1574,72 @@ var capacitorCapacitorSQLite = (function (exports, core) {
|
|
|
1158
1574
|
}
|
|
1159
1575
|
}
|
|
1160
1576
|
async run(options) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1577
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
1578
|
+
this.ensureJeepSqliteIsAvailable();
|
|
1579
|
+
this.ensureWebstoreIsOpen();
|
|
1580
|
+
try {
|
|
1581
|
+
const runResult = await this.jeepSqliteElement.run(options);
|
|
1582
|
+
return runResult;
|
|
1583
|
+
}
|
|
1584
|
+
catch (err) {
|
|
1585
|
+
throw new Error(`${err}`);
|
|
1586
|
+
}
|
|
1166
1587
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1588
|
+
else {
|
|
1589
|
+
// Only for typeOrm to run migration:generate
|
|
1590
|
+
const dbName = options.database ? options.database : '';
|
|
1591
|
+
if (dbName.length === 0) {
|
|
1592
|
+
throw new Error('Must provide a database name');
|
|
1593
|
+
}
|
|
1594
|
+
const statement = options.statement ? options.statement : '';
|
|
1595
|
+
if (statement.length === 0) {
|
|
1596
|
+
return Promise.reject('Must provide raw SQL statement');
|
|
1597
|
+
}
|
|
1598
|
+
const values = options.values ? options.values : [];
|
|
1599
|
+
const returnMode = options.returnMode ? options.returnMode : 'no';
|
|
1600
|
+
const connName = 'RW_' + dbName;
|
|
1601
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
1602
|
+
try {
|
|
1603
|
+
const runResult = await database.run(statement, values, returnMode);
|
|
1604
|
+
return runResult;
|
|
1605
|
+
}
|
|
1606
|
+
catch (err) {
|
|
1607
|
+
throw new Error(`${err}`);
|
|
1608
|
+
}
|
|
1169
1609
|
}
|
|
1170
1610
|
}
|
|
1171
1611
|
async query(options) {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1612
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
1613
|
+
this.ensureJeepSqliteIsAvailable();
|
|
1614
|
+
this.ensureWebstoreIsOpen();
|
|
1615
|
+
try {
|
|
1616
|
+
const queryResult = await this.jeepSqliteElement.query(options);
|
|
1617
|
+
return queryResult;
|
|
1618
|
+
}
|
|
1619
|
+
catch (err) {
|
|
1620
|
+
throw new Error(`${err}`);
|
|
1621
|
+
}
|
|
1177
1622
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1623
|
+
else {
|
|
1624
|
+
// Only for typeOrm to run migration:generate
|
|
1625
|
+
const dbName = options.database ? options.database : '';
|
|
1626
|
+
if (dbName.length === 0) {
|
|
1627
|
+
throw new Error('Must provide a database name');
|
|
1628
|
+
}
|
|
1629
|
+
const statement = options.statement ? options.statement : '';
|
|
1630
|
+
if (statement.length === 0) {
|
|
1631
|
+
return Promise.reject('Must provide raw SQL statement');
|
|
1632
|
+
}
|
|
1633
|
+
const values = options.values ? options.values : [];
|
|
1634
|
+
const connName = 'RW_' + dbName;
|
|
1635
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
1636
|
+
try {
|
|
1637
|
+
const queryResult = await database.selectSQL(statement, values);
|
|
1638
|
+
return queryResult;
|
|
1639
|
+
}
|
|
1640
|
+
catch (err) {
|
|
1641
|
+
throw new Error(`${err}`);
|
|
1642
|
+
}
|
|
1180
1643
|
}
|
|
1181
1644
|
}
|
|
1182
1645
|
async isDBExists(options) {
|
|
@@ -1375,6 +1838,13 @@ var capacitorCapacitorSQLite = (function (exports, core) {
|
|
|
1375
1838
|
throw new Error('WebStore is not open yet. You have to call "initWebStore()" first.');
|
|
1376
1839
|
}
|
|
1377
1840
|
}
|
|
1841
|
+
getDatabaseConnectionOrThrowError(dbName) {
|
|
1842
|
+
const databaseNames = Object.keys(this.databases);
|
|
1843
|
+
if (!databaseNames.includes(dbName)) {
|
|
1844
|
+
throw new Error(`No connection available for database "${dbName}"`);
|
|
1845
|
+
}
|
|
1846
|
+
return this.databases[dbName];
|
|
1847
|
+
}
|
|
1378
1848
|
////////////////////////////////////
|
|
1379
1849
|
////// UNIMPLEMENTED METHODS
|
|
1380
1850
|
////////////////////////////////////
|