@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/src/web.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { WebPlugin } from '@capacitor/core';
|
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
CapacitorSQLitePlugin,
|
|
5
|
+
capConnectionOptions,
|
|
5
6
|
capAllConnectionsOptions,
|
|
6
7
|
capChangeSecretOptions,
|
|
7
8
|
capEchoOptions,
|
|
@@ -35,6 +36,7 @@ import type {
|
|
|
35
36
|
capSQLiteExtensionPath,
|
|
36
37
|
capSQLiteExtensionEnable,
|
|
37
38
|
} from './definitions';
|
|
39
|
+
import { Database } from './web-typeorm-utils/database';
|
|
38
40
|
|
|
39
41
|
export class CapacitorSQLiteWeb
|
|
40
42
|
extends WebPlugin
|
|
@@ -42,6 +44,7 @@ export class CapacitorSQLiteWeb
|
|
|
42
44
|
{
|
|
43
45
|
private jeepSqliteElement: any = null;
|
|
44
46
|
private isWebStoreOpen = false;
|
|
47
|
+
private databases: { [databasename: string]: Database } = {};
|
|
45
48
|
|
|
46
49
|
async initWebStore(): Promise<void> {
|
|
47
50
|
await customElements.whenDefined('jeep-sqlite');
|
|
@@ -131,39 +134,88 @@ export class CapacitorSQLiteWeb
|
|
|
131
134
|
return echoResult;
|
|
132
135
|
}
|
|
133
136
|
|
|
134
|
-
async createConnection(options:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
async createConnection(options: capConnectionOptions): Promise<void> {
|
|
138
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
139
|
+
this.ensureJeepSqliteIsAvailable();
|
|
140
|
+
this.ensureWebstoreIsOpen();
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
await this.jeepSqliteElement.createConnection(options);
|
|
144
|
+
return;
|
|
145
|
+
} catch (err) {
|
|
146
|
+
throw new Error(`${err}`);
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
// Only for typeOrm to run migration:generate
|
|
150
|
+
const optionKeys = Object.keys(options);
|
|
151
|
+
let dbName: string | undefined;
|
|
152
|
+
if (!optionKeys.includes('database')) {
|
|
153
|
+
throw new Error('Must provide a database name');
|
|
154
|
+
} else {
|
|
155
|
+
dbName = options.database;
|
|
156
|
+
}
|
|
157
|
+
const connName: string = 'RW_' + dbName;
|
|
158
|
+
const databaseConnection: Database = new Database();
|
|
159
|
+
this.databases[connName] = databaseConnection;
|
|
143
160
|
}
|
|
144
161
|
}
|
|
145
162
|
|
|
146
163
|
async open(options: capSQLiteOptions): Promise<void> {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
164
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
165
|
+
this.ensureJeepSqliteIsAvailable();
|
|
166
|
+
this.ensureWebstoreIsOpen();
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
await this.jeepSqliteElement.open(options);
|
|
170
|
+
return;
|
|
171
|
+
} catch (err) {
|
|
172
|
+
throw new Error(`${err}`);
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
// Only for typeOrm to run migration:generate
|
|
176
|
+
|
|
177
|
+
const dbName = options.database ? options.database : '';
|
|
178
|
+
if (dbName.length === 0) {
|
|
179
|
+
throw new Error('Must provide a database name');
|
|
180
|
+
}
|
|
181
|
+
const readonly = false;
|
|
182
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
183
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
184
|
+
try {
|
|
185
|
+
await database.open(dbName);
|
|
186
|
+
} catch (err) {
|
|
187
|
+
throw new Error(`### open ${err}`);
|
|
188
|
+
}
|
|
155
189
|
}
|
|
156
190
|
}
|
|
157
191
|
|
|
158
192
|
async closeConnection(options: capSQLiteOptions): Promise<void> {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
193
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
194
|
+
this.ensureJeepSqliteIsAvailable();
|
|
195
|
+
this.ensureWebstoreIsOpen();
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
await this.jeepSqliteElement.closeConnection(options);
|
|
199
|
+
return;
|
|
200
|
+
} catch (err) {
|
|
201
|
+
throw new Error(`${err}`);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
// Only for typeOrm to run migration:generate
|
|
205
|
+
const dbName = options.database ? options.database : '';
|
|
206
|
+
if (dbName.length === 0) {
|
|
207
|
+
throw new Error('Must provide a database name');
|
|
208
|
+
}
|
|
209
|
+
const readonly = false;
|
|
210
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
211
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
212
|
+
try {
|
|
213
|
+
await database.close();
|
|
214
|
+
// remove the connection from dictionary
|
|
215
|
+
delete this.databases[connName];
|
|
216
|
+
} catch (err) {
|
|
217
|
+
throw new Error(`### closeConnection ${err}`);
|
|
218
|
+
}
|
|
167
219
|
}
|
|
168
220
|
}
|
|
169
221
|
|
|
@@ -195,14 +247,31 @@ export class CapacitorSQLiteWeb
|
|
|
195
247
|
}
|
|
196
248
|
|
|
197
249
|
async close(options: capSQLiteOptions): Promise<void> {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
250
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
251
|
+
this.ensureJeepSqliteIsAvailable();
|
|
252
|
+
this.ensureWebstoreIsOpen();
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
await this.jeepSqliteElement.close(options);
|
|
256
|
+
return;
|
|
257
|
+
} catch (err) {
|
|
258
|
+
throw new Error(`${err}`);
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
// Only for typeOrm to run migration:generate
|
|
262
|
+
|
|
263
|
+
const dbName = options.database ? options.database : '';
|
|
264
|
+
if (dbName.length === 0) {
|
|
265
|
+
throw new Error('Must provide a database name');
|
|
266
|
+
}
|
|
267
|
+
const readonly = false;
|
|
268
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
269
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
270
|
+
try {
|
|
271
|
+
await database.close();
|
|
272
|
+
} catch (err) {
|
|
273
|
+
throw new Error(`### close ${err}`);
|
|
274
|
+
}
|
|
206
275
|
}
|
|
207
276
|
}
|
|
208
277
|
async beginTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges> {
|
|
@@ -274,15 +343,38 @@ export class CapacitorSQLiteWeb
|
|
|
274
343
|
}
|
|
275
344
|
|
|
276
345
|
async execute(options: capSQLiteExecuteOptions): Promise<capSQLiteChanges> {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
346
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
347
|
+
this.ensureJeepSqliteIsAvailable();
|
|
348
|
+
this.ensureWebstoreIsOpen();
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
const executeResult: capSQLiteChanges =
|
|
352
|
+
await this.jeepSqliteElement.execute(options);
|
|
353
|
+
return executeResult;
|
|
354
|
+
} catch (err) {
|
|
355
|
+
throw new Error(`${err}`);
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
// Only for typeOrm to run migration:generate
|
|
359
|
+
|
|
360
|
+
const dbName = options.database ? options.database : '';
|
|
361
|
+
if (dbName.length === 0) {
|
|
362
|
+
throw new Error('Must provide a database name');
|
|
363
|
+
}
|
|
364
|
+
const statements = options.statements ? options.statements : '';
|
|
365
|
+
if (statements.length === 0) {
|
|
366
|
+
return Promise.reject('Must provide raw SQL statements');
|
|
367
|
+
}
|
|
368
|
+
const readonly = false;
|
|
369
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
370
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
371
|
+
try {
|
|
372
|
+
const ret = await database.executeSQL(statements);
|
|
373
|
+
const executeResult: capSQLiteChanges = { changes: { changes: ret } };
|
|
374
|
+
return executeResult;
|
|
375
|
+
} catch (err) {
|
|
376
|
+
throw new Error(`${err}`);
|
|
377
|
+
}
|
|
286
378
|
}
|
|
287
379
|
}
|
|
288
380
|
|
|
@@ -300,29 +392,79 @@ export class CapacitorSQLiteWeb
|
|
|
300
392
|
}
|
|
301
393
|
|
|
302
394
|
async run(options: capSQLiteRunOptions): Promise<capSQLiteChanges> {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
395
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
396
|
+
this.ensureJeepSqliteIsAvailable();
|
|
397
|
+
this.ensureWebstoreIsOpen();
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
const runResult: capSQLiteChanges = await this.jeepSqliteElement.run(
|
|
401
|
+
options,
|
|
402
|
+
);
|
|
403
|
+
return runResult;
|
|
404
|
+
} catch (err) {
|
|
405
|
+
throw new Error(`${err}`);
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
// Only for typeOrm to run migration:generate
|
|
409
|
+
|
|
410
|
+
const dbName = options.database ? options.database : '';
|
|
411
|
+
if (dbName.length === 0) {
|
|
412
|
+
throw new Error('Must provide a database name');
|
|
413
|
+
}
|
|
414
|
+
const statement = options.statement ? options.statement : '';
|
|
415
|
+
if (statement.length === 0) {
|
|
416
|
+
return Promise.reject('Must provide raw SQL statement');
|
|
417
|
+
}
|
|
418
|
+
const values = options.values ? options.values : [];
|
|
419
|
+
const readonly = false;
|
|
420
|
+
const returnMode = options.returnMode ? options.returnMode : 'no';
|
|
421
|
+
|
|
422
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
423
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
424
|
+
try {
|
|
425
|
+
const runResult = await database.run(statement, values, returnMode);
|
|
426
|
+
return runResult;
|
|
427
|
+
} catch (err) {
|
|
428
|
+
throw new Error(`${err}`);
|
|
429
|
+
}
|
|
313
430
|
}
|
|
314
431
|
}
|
|
315
432
|
async query(options: capSQLiteQueryOptions): Promise<capSQLiteValues> {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
433
|
+
if (typeof window !== 'undefined' && window.document) {
|
|
434
|
+
this.ensureJeepSqliteIsAvailable();
|
|
435
|
+
this.ensureWebstoreIsOpen();
|
|
436
|
+
|
|
437
|
+
try {
|
|
438
|
+
const queryResult: capSQLiteValues = await this.jeepSqliteElement.query(
|
|
439
|
+
options,
|
|
440
|
+
);
|
|
441
|
+
return queryResult;
|
|
442
|
+
} catch (err) {
|
|
443
|
+
throw new Error(`${err}`);
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
// Only for typeOrm to run migration:generate
|
|
447
|
+
const dbName = options.database ? options.database : '';
|
|
448
|
+
if (dbName.length === 0) {
|
|
449
|
+
throw new Error('Must provide a database name');
|
|
450
|
+
}
|
|
451
|
+
const statement = options.statement ? options.statement : '';
|
|
452
|
+
if (statement.length === 0) {
|
|
453
|
+
return Promise.reject('Must provide raw SQL statement');
|
|
454
|
+
}
|
|
455
|
+
const values = options.values ? options.values : [];
|
|
456
|
+
const readonly = false;
|
|
457
|
+
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
458
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
459
|
+
try {
|
|
460
|
+
const queryResult: capSQLiteValues = await database.selectSQL(
|
|
461
|
+
statement,
|
|
462
|
+
values,
|
|
463
|
+
);
|
|
464
|
+
return queryResult;
|
|
465
|
+
} catch (err) {
|
|
466
|
+
throw new Error(`${err}`);
|
|
467
|
+
}
|
|
326
468
|
}
|
|
327
469
|
}
|
|
328
470
|
async isDBExists(options: capSQLiteOptions): Promise<capSQLiteResult> {
|
|
@@ -552,6 +694,14 @@ export class CapacitorSQLiteWeb
|
|
|
552
694
|
);
|
|
553
695
|
}
|
|
554
696
|
}
|
|
697
|
+
private getDatabaseConnectionOrThrowError(dbName: string): Database {
|
|
698
|
+
const databaseNames = Object.keys(this.databases);
|
|
699
|
+
if (!databaseNames.includes(dbName)) {
|
|
700
|
+
throw new Error(`No connection available for database "${dbName}"`);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
return this.databases[dbName];
|
|
704
|
+
}
|
|
555
705
|
|
|
556
706
|
////////////////////////////////////
|
|
557
707
|
////// UNIMPLEMENTED METHODS
|