@capacitor-community/sqlite 4.6.1 → 4.6.2-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/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+
3
+ import type { CapacitorSQLitePlugin } from './definitions';
4
+
5
+ const CapacitorSQLite = registerPlugin<CapacitorSQLitePlugin>(
6
+ 'CapacitorSQLite',
7
+ {
8
+ web: () => import('./web').then(m => new m.CapacitorSQLiteWeb()),
9
+ electron: () =>
10
+ (window as any).CapacitorCustomPlatform.plugins.CapacitorSQLite,
11
+ },
12
+ );
13
+
14
+ export { CapacitorSQLite };
15
+ export * from './definitions';
package/src/web.ts ADDED
@@ -0,0 +1,539 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+
3
+ import type {
4
+ CapacitorSQLitePlugin,
5
+ capAllConnectionsOptions,
6
+ capChangeSecretOptions,
7
+ capEchoOptions,
8
+ capEchoResult,
9
+ capNCConnectionOptions,
10
+ capNCDatabasePathOptions,
11
+ capNCDatabasePathResult,
12
+ capNCOptions,
13
+ capSetSecretOptions,
14
+ capSQLiteChanges,
15
+ capSQLiteExecuteOptions,
16
+ capSQLiteExportOptions,
17
+ capSQLiteFromAssetsOptions,
18
+ capSQLiteHTTPOptions,
19
+ capSQLiteImportOptions,
20
+ capSQLiteJson,
21
+ capSQLiteOptions,
22
+ capSQLitePathOptions,
23
+ capSQLiteQueryOptions,
24
+ capSQLiteResult,
25
+ capSQLiteRunOptions,
26
+ capSQLiteSetOptions,
27
+ capSQLiteSyncDate,
28
+ capSQLiteSyncDateOptions,
29
+ capSQLiteTableOptions,
30
+ capSQLiteUpgradeOptions,
31
+ capSQLiteUrl,
32
+ capSQLiteValues,
33
+ capVersionResult,
34
+ } from './definitions';
35
+
36
+ export class CapacitorSQLiteWeb
37
+ extends WebPlugin
38
+ implements CapacitorSQLitePlugin
39
+ {
40
+ private jeepSqliteElement: any = null;
41
+ private isWebStoreOpen = false;
42
+
43
+ async initWebStore(): Promise<void> {
44
+ await customElements.whenDefined('jeep-sqlite');
45
+
46
+ this.jeepSqliteElement = document.querySelector('jeep-sqlite');
47
+
48
+ this.ensureJeepSqliteIsAvailable();
49
+
50
+ this.jeepSqliteElement.addEventListener(
51
+ 'jeepSqliteImportProgress',
52
+ (event: CustomEvent) => {
53
+ this.notifyListeners('sqliteImportProgressEvent', event.detail);
54
+ },
55
+ );
56
+ this.jeepSqliteElement.addEventListener(
57
+ 'jeepSqliteExportProgress',
58
+ (event: CustomEvent) => {
59
+ this.notifyListeners('sqliteExportProgressEvent', event.detail);
60
+ },
61
+ );
62
+
63
+ if (!this.isWebStoreOpen) {
64
+ this.isWebStoreOpen = await this.jeepSqliteElement.isStoreOpen();
65
+ }
66
+
67
+ return;
68
+ }
69
+
70
+ async saveToStore(options: capSQLiteOptions): Promise<void> {
71
+ this.ensureJeepSqliteIsAvailable();
72
+ this.ensureWebstoreIsOpen();
73
+
74
+ try {
75
+ await this.jeepSqliteElement.saveToStore(options);
76
+ return;
77
+ } catch (err) {
78
+ throw new Error(`${err}`);
79
+ }
80
+ }
81
+
82
+ async echo(options: capEchoOptions): Promise<capEchoResult> {
83
+ this.ensureJeepSqliteIsAvailable();
84
+
85
+ const echoResult = await this.jeepSqliteElement.echo(options);
86
+ return echoResult;
87
+ }
88
+
89
+ async createConnection(options: capSQLiteOptions): Promise<void> {
90
+ this.ensureJeepSqliteIsAvailable();
91
+ this.ensureWebstoreIsOpen();
92
+
93
+ try {
94
+ await this.jeepSqliteElement.createConnection(options);
95
+ return;
96
+ } catch (err) {
97
+ throw new Error(`${err}`);
98
+ }
99
+ }
100
+
101
+ async open(options: capSQLiteOptions): Promise<void> {
102
+ this.ensureJeepSqliteIsAvailable();
103
+ this.ensureWebstoreIsOpen();
104
+
105
+ try {
106
+ await this.jeepSqliteElement.open(options);
107
+ return;
108
+ } catch (err) {
109
+ throw new Error(`${err}`);
110
+ }
111
+ }
112
+
113
+ async closeConnection(options: capSQLiteOptions): Promise<void> {
114
+ this.ensureJeepSqliteIsAvailable();
115
+ this.ensureWebstoreIsOpen();
116
+
117
+ try {
118
+ await this.jeepSqliteElement.closeConnection(options);
119
+ return;
120
+ } catch (err) {
121
+ throw new Error(`${err}`);
122
+ }
123
+ }
124
+
125
+ async getVersion(options: capSQLiteOptions): Promise<capVersionResult> {
126
+ this.ensureJeepSqliteIsAvailable();
127
+ this.ensureWebstoreIsOpen();
128
+
129
+ try {
130
+ const versionResult: capVersionResult =
131
+ await this.jeepSqliteElement.getVersion(options);
132
+ return versionResult;
133
+ } catch (err) {
134
+ throw new Error(`${err}`);
135
+ }
136
+ }
137
+
138
+ async checkConnectionsConsistency(
139
+ options: capAllConnectionsOptions,
140
+ ): Promise<capSQLiteResult> {
141
+ this.ensureJeepSqliteIsAvailable();
142
+
143
+ try {
144
+ console.log(
145
+ `in web checkConnectionsConsistency: ${JSON.stringify(options)}`,
146
+ );
147
+ const consistencyResult: capSQLiteResult =
148
+ await this.jeepSqliteElement.checkConnectionsConsistency(options);
149
+ return consistencyResult;
150
+ } catch (err) {
151
+ throw new Error(`${err}`);
152
+ }
153
+ }
154
+
155
+ async close(options: capSQLiteOptions): Promise<void> {
156
+ this.ensureJeepSqliteIsAvailable();
157
+ this.ensureWebstoreIsOpen();
158
+
159
+ try {
160
+ await this.jeepSqliteElement.close(options);
161
+ return;
162
+ } catch (err) {
163
+ throw new Error(`${err}`);
164
+ }
165
+ }
166
+
167
+ async getTableList(options: capSQLiteOptions): Promise<capSQLiteValues> {
168
+ this.ensureJeepSqliteIsAvailable();
169
+ this.ensureWebstoreIsOpen();
170
+
171
+ try {
172
+ const tableListResult: capSQLiteValues =
173
+ await this.jeepSqliteElement.getTableList(options);
174
+ return tableListResult;
175
+ } catch (err) {
176
+ throw new Error(`${err}`);
177
+ }
178
+ }
179
+
180
+ async execute(options: capSQLiteExecuteOptions): Promise<capSQLiteChanges> {
181
+ this.ensureJeepSqliteIsAvailable();
182
+ this.ensureWebstoreIsOpen();
183
+
184
+ try {
185
+ const executeResult: capSQLiteChanges =
186
+ await this.jeepSqliteElement.execute(options);
187
+ return executeResult;
188
+ } catch (err) {
189
+ throw new Error(`${err}`);
190
+ }
191
+ }
192
+
193
+ async executeSet(options: capSQLiteSetOptions): Promise<capSQLiteChanges> {
194
+ this.ensureJeepSqliteIsAvailable();
195
+ this.ensureWebstoreIsOpen();
196
+
197
+ try {
198
+ const executeResult: capSQLiteChanges =
199
+ await this.jeepSqliteElement.executeSet(options);
200
+ return executeResult;
201
+ } catch (err) {
202
+ throw new Error(`${err}`);
203
+ }
204
+ }
205
+
206
+ async run(options: capSQLiteRunOptions): Promise<capSQLiteChanges> {
207
+ this.ensureJeepSqliteIsAvailable();
208
+ this.ensureWebstoreIsOpen();
209
+
210
+ try {
211
+ const runResult: capSQLiteChanges = await this.jeepSqliteElement.run(
212
+ options,
213
+ );
214
+ return runResult;
215
+ } catch (err) {
216
+ throw new Error(`${err}`);
217
+ }
218
+ }
219
+ async query(options: capSQLiteQueryOptions): Promise<capSQLiteValues> {
220
+ this.ensureJeepSqliteIsAvailable();
221
+ this.ensureWebstoreIsOpen();
222
+
223
+ try {
224
+ const queryResult: capSQLiteValues = await this.jeepSqliteElement.query(
225
+ options,
226
+ );
227
+ return queryResult;
228
+ } catch (err) {
229
+ throw new Error(`${err}`);
230
+ }
231
+ }
232
+ async isDBExists(options: capSQLiteOptions): Promise<capSQLiteResult> {
233
+ this.ensureJeepSqliteIsAvailable();
234
+ this.ensureWebstoreIsOpen();
235
+
236
+ try {
237
+ const dbExistsResult: capSQLiteResult =
238
+ await this.jeepSqliteElement.isDBExists(options);
239
+ return dbExistsResult;
240
+ } catch (err) {
241
+ throw new Error(`${err}`);
242
+ }
243
+ }
244
+
245
+ async isDBOpen(options: capSQLiteOptions): Promise<capSQLiteResult> {
246
+ this.ensureJeepSqliteIsAvailable();
247
+ this.ensureWebstoreIsOpen();
248
+
249
+ try {
250
+ const isDBOpenResult: capSQLiteResult =
251
+ await this.jeepSqliteElement.isDBOpen(options);
252
+ return isDBOpenResult;
253
+ } catch (err) {
254
+ throw new Error(`${err}`);
255
+ }
256
+ }
257
+
258
+ async isDatabase(options: capSQLiteOptions): Promise<capSQLiteResult> {
259
+ this.ensureJeepSqliteIsAvailable();
260
+ this.ensureWebstoreIsOpen();
261
+
262
+ try {
263
+ const isDatabaseResult: capSQLiteResult =
264
+ await this.jeepSqliteElement.isDatabase(options);
265
+ return isDatabaseResult;
266
+ } catch (err) {
267
+ throw new Error(`${err}`);
268
+ }
269
+ }
270
+
271
+ async isTableExists(
272
+ options: capSQLiteTableOptions,
273
+ ): Promise<capSQLiteResult> {
274
+ this.ensureJeepSqliteIsAvailable();
275
+ this.ensureWebstoreIsOpen();
276
+
277
+ try {
278
+ const tableExistsResult = await this.jeepSqliteElement.isTableExists(
279
+ options,
280
+ );
281
+ return tableExistsResult;
282
+ } catch (err) {
283
+ throw new Error(`${err}`);
284
+ }
285
+ }
286
+ async deleteDatabase(options: capSQLiteOptions): Promise<void> {
287
+ this.ensureJeepSqliteIsAvailable();
288
+ this.ensureWebstoreIsOpen();
289
+
290
+ try {
291
+ await this.jeepSqliteElement.deleteDatabase(options);
292
+ return;
293
+ } catch (err) {
294
+ throw new Error(`${err}`);
295
+ }
296
+ }
297
+ async isJsonValid(options: capSQLiteImportOptions): Promise<capSQLiteResult> {
298
+ this.ensureJeepSqliteIsAvailable();
299
+ this.ensureWebstoreIsOpen();
300
+
301
+ try {
302
+ const isJsonValidResult = await this.jeepSqliteElement.isJsonValid(
303
+ options,
304
+ );
305
+ return isJsonValidResult;
306
+ } catch (err) {
307
+ throw new Error(`${err}`);
308
+ }
309
+ }
310
+
311
+ async importFromJson(
312
+ options: capSQLiteImportOptions,
313
+ ): Promise<capSQLiteChanges> {
314
+ this.ensureJeepSqliteIsAvailable();
315
+ this.ensureWebstoreIsOpen();
316
+
317
+ try {
318
+ const importFromJsonResult: capSQLiteChanges =
319
+ await this.jeepSqliteElement.importFromJson(options);
320
+ return importFromJsonResult;
321
+ } catch (err) {
322
+ throw new Error(`${err}`);
323
+ }
324
+ }
325
+
326
+ async exportToJson(options: capSQLiteExportOptions): Promise<capSQLiteJson> {
327
+ this.ensureJeepSqliteIsAvailable();
328
+ this.ensureWebstoreIsOpen();
329
+
330
+ try {
331
+ const exportToJsonResult: capSQLiteJson =
332
+ await this.jeepSqliteElement.exportToJson(options);
333
+ return exportToJsonResult;
334
+ } catch (err) {
335
+ throw new Error(`${err}`);
336
+ }
337
+ }
338
+ async createSyncTable(options: capSQLiteOptions): Promise<capSQLiteChanges> {
339
+ this.ensureJeepSqliteIsAvailable();
340
+ this.ensureWebstoreIsOpen();
341
+
342
+ try {
343
+ const createSyncTableResult: capSQLiteChanges =
344
+ await this.jeepSqliteElement.createSyncTable(options);
345
+ return createSyncTableResult;
346
+ } catch (err) {
347
+ throw new Error(`${err}`);
348
+ }
349
+ }
350
+
351
+ async setSyncDate(options: capSQLiteSyncDateOptions): Promise<void> {
352
+ this.ensureJeepSqliteIsAvailable();
353
+ this.ensureWebstoreIsOpen();
354
+ try {
355
+ await this.jeepSqliteElement.setSyncDate(options);
356
+ return;
357
+ } catch (err) {
358
+ throw new Error(`${err}`);
359
+ }
360
+ }
361
+
362
+ async getSyncDate(options: capSQLiteOptions): Promise<capSQLiteSyncDate> {
363
+ this.ensureJeepSqliteIsAvailable();
364
+ this.ensureWebstoreIsOpen();
365
+
366
+ try {
367
+ const getSyncDateResult: capSQLiteSyncDate =
368
+ await this.jeepSqliteElement.getSyncDate(options);
369
+ return getSyncDateResult;
370
+ } catch (err) {
371
+ throw new Error(`${err}`);
372
+ }
373
+ }
374
+ async deleteExportedRows(options: capSQLiteOptions): Promise<void> {
375
+ this.ensureJeepSqliteIsAvailable();
376
+ this.ensureWebstoreIsOpen();
377
+ try {
378
+ await this.jeepSqliteElement.deleteExportedRows(options);
379
+ return;
380
+ } catch (err) {
381
+ throw new Error(`${err}`);
382
+ }
383
+ }
384
+
385
+ async addUpgradeStatement(options: capSQLiteUpgradeOptions): Promise<void> {
386
+ this.ensureJeepSqliteIsAvailable();
387
+ this.ensureWebstoreIsOpen();
388
+
389
+ try {
390
+ await this.jeepSqliteElement.addUpgradeStatement(options);
391
+ return;
392
+ } catch (err) {
393
+ throw new Error(`${err}`);
394
+ }
395
+ }
396
+
397
+ async copyFromAssets(options: capSQLiteFromAssetsOptions): Promise<void> {
398
+ this.ensureJeepSqliteIsAvailable();
399
+ this.ensureWebstoreIsOpen();
400
+
401
+ try {
402
+ await this.jeepSqliteElement.copyFromAssets(options);
403
+ return;
404
+ } catch (err) {
405
+ throw new Error(`${err}`);
406
+ }
407
+ }
408
+
409
+ async getFromHTTPRequest(options: capSQLiteHTTPOptions): Promise<void> {
410
+ this.ensureJeepSqliteIsAvailable();
411
+ this.ensureWebstoreIsOpen();
412
+
413
+ try {
414
+ await this.jeepSqliteElement.getFromHTTPRequest(options);
415
+ return;
416
+ } catch (err) {
417
+ throw new Error(`${err}`);
418
+ }
419
+ }
420
+
421
+ async getDatabaseList(): Promise<capSQLiteValues> {
422
+ this.ensureJeepSqliteIsAvailable();
423
+ this.ensureWebstoreIsOpen();
424
+
425
+ try {
426
+ const databaseListResult: capSQLiteValues =
427
+ await this.jeepSqliteElement.getDatabaseList();
428
+ return databaseListResult;
429
+ } catch (err) {
430
+ throw new Error(`${err}`);
431
+ }
432
+ }
433
+
434
+ /**
435
+ * Checks if the `jeep-sqlite` element is present in the DOM.
436
+ * If it's not in the DOM, this method throws an Error.
437
+ *
438
+ * Attention: This will always fail, if the `intWebStore()` method wasn't called before.
439
+ */
440
+ private ensureJeepSqliteIsAvailable() {
441
+ if (this.jeepSqliteElement === null) {
442
+ throw new Error(
443
+ `The jeep-sqlite element is not present in the DOM! Please check the @capacitor-community/sqlite documentation for instructions regarding the web platform.`,
444
+ );
445
+ }
446
+ }
447
+
448
+ private ensureWebstoreIsOpen() {
449
+ if (!this.isWebStoreOpen) {
450
+ /**
451
+ * if (!this.isWebStoreOpen)
452
+ this.isWebStoreOpen = await this.jeepSqliteElement.isStoreOpen();
453
+ */
454
+ throw new Error(
455
+ 'WebStore is not open yet. You have to call "initWebStore()" first.',
456
+ );
457
+ }
458
+ }
459
+
460
+ ////////////////////////////////////
461
+ ////// UNIMPLEMENTED METHODS
462
+ ////////////////////////////////////
463
+
464
+ async getUrl(): Promise<capSQLiteUrl> {
465
+ throw this.unimplemented('Not implemented on web.');
466
+ }
467
+
468
+ async getMigratableDbList(
469
+ options: capSQLitePathOptions,
470
+ ): Promise<capSQLiteValues> {
471
+ console.log('getMigratableDbList', options);
472
+ throw this.unimplemented('Not implemented on web.');
473
+ }
474
+
475
+ async addSQLiteSuffix(options: capSQLitePathOptions): Promise<void> {
476
+ console.log('addSQLiteSuffix', options);
477
+ throw this.unimplemented('Not implemented on web.');
478
+ }
479
+
480
+ async deleteOldDatabases(options: capSQLitePathOptions): Promise<void> {
481
+ console.log('deleteOldDatabases', options);
482
+ throw this.unimplemented('Not implemented on web.');
483
+ }
484
+
485
+ async moveDatabasesAndAddSuffix(
486
+ options: capSQLitePathOptions,
487
+ ): Promise<void> {
488
+ console.log('moveDatabasesAndAddSuffix', options);
489
+ throw this.unimplemented('Not implemented on web.');
490
+ }
491
+
492
+ async isSecretStored(): Promise<capSQLiteResult> {
493
+ throw this.unimplemented('Not implemented on web.');
494
+ }
495
+
496
+ async setEncryptionSecret(options: capSetSecretOptions): Promise<void> {
497
+ console.log('setEncryptionSecret', options);
498
+ throw this.unimplemented('Not implemented on web.');
499
+ }
500
+
501
+ async changeEncryptionSecret(options: capChangeSecretOptions): Promise<void> {
502
+ console.log('changeEncryptionSecret', options);
503
+ throw this.unimplemented('Not implemented on web.');
504
+ }
505
+
506
+ async clearEncryptionSecret(): Promise<void> {
507
+ console.log('clearEncryptionSecret');
508
+ throw this.unimplemented('Not implemented on web.');
509
+ }
510
+
511
+ async checkEncryptionSecret(
512
+ options: capSetSecretOptions,
513
+ ): Promise<capSQLiteResult> {
514
+ console.log('checkEncryptionPassPhrase', options);
515
+ throw this.unimplemented('Not implemented on web.');
516
+ }
517
+
518
+ async getNCDatabasePath(
519
+ options: capNCDatabasePathOptions,
520
+ ): Promise<capNCDatabasePathResult> {
521
+ console.log('getNCDatabasePath', options);
522
+ throw this.unimplemented('Not implemented on web.');
523
+ }
524
+
525
+ async createNCConnection(options: capNCConnectionOptions): Promise<void> {
526
+ console.log('createNCConnection', options);
527
+ throw this.unimplemented('Not implemented on web.');
528
+ }
529
+
530
+ async closeNCConnection(options: capNCOptions): Promise<void> {
531
+ console.log('closeNCConnection', options);
532
+ throw this.unimplemented('Not implemented on web.');
533
+ }
534
+
535
+ async isNCDatabase(options: capNCOptions): Promise<capSQLiteResult> {
536
+ console.log('isNCDatabase', options);
537
+ throw this.unimplemented('Not implemented on web.');
538
+ }
539
+ }