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