@capacitor-community/sqlite 4.1.0-6 → 4.1.0-7

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/plugin.js CHANGED
@@ -94,7 +94,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
94
94
  return Promise.reject(err);
95
95
  }
96
96
  }
97
- async createConnection(database, encrypted, mode, version) {
97
+ async createConnection(database, encrypted, mode, version, readonly) {
98
98
  try {
99
99
  if (database.endsWith('.db'))
100
100
  database = database.slice(0, -3);
@@ -103,39 +103,44 @@ var capacitorCapacitorSQLite = (function (exports, core) {
103
103
  encrypted,
104
104
  mode,
105
105
  version,
106
+ readonly,
106
107
  });
107
- const conn = new SQLiteDBConnection(database, this.sqlite);
108
- this._connectionDict.set(database, conn);
108
+ const conn = new SQLiteDBConnection(database, readonly, this.sqlite);
109
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
110
+ this._connectionDict.set(connName, conn);
109
111
  return Promise.resolve(conn);
110
112
  }
111
113
  catch (err) {
112
114
  return Promise.reject(err);
113
115
  }
114
116
  }
115
- async closeConnection(database) {
117
+ async closeConnection(database, readonly) {
116
118
  try {
117
119
  if (database.endsWith('.db'))
118
120
  database = database.slice(0, -3);
119
- await this.sqlite.closeConnection({ database });
120
- this._connectionDict.delete(database);
121
+ await this.sqlite.closeConnection({ database, readonly });
122
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
123
+ this._connectionDict.delete(connName);
121
124
  return Promise.resolve();
122
125
  }
123
126
  catch (err) {
124
127
  return Promise.reject(err);
125
128
  }
126
129
  }
127
- async isConnection(database) {
130
+ async isConnection(database, readonly) {
128
131
  const res = {};
129
132
  if (database.endsWith('.db'))
130
133
  database = database.slice(0, -3);
131
- res.result = this._connectionDict.has(database);
134
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
135
+ res.result = this._connectionDict.has(connName);
132
136
  return Promise.resolve(res);
133
137
  }
134
- async retrieveConnection(database) {
138
+ async retrieveConnection(database, readonly) {
135
139
  if (database.endsWith('.db'))
136
140
  database = database.slice(0, -3);
137
- if (this._connectionDict.has(database)) {
138
- const conn = this._connectionDict.get(database);
141
+ const connName = readonly ? `RO_${database}` : `RW_${database}`;
142
+ if (this._connectionDict.has(connName)) {
143
+ const conn = this._connectionDict.get(connName);
139
144
  if (typeof conn != 'undefined')
140
145
  return Promise.resolve(conn);
141
146
  else {
@@ -164,8 +169,9 @@ var capacitorCapacitorSQLite = (function (exports, core) {
164
169
  databasePath,
165
170
  version,
166
171
  });
167
- const conn = new SQLiteDBConnection(databasePath, this.sqlite);
168
- this._connectionDict.set(databasePath, conn);
172
+ const conn = new SQLiteDBConnection(databasePath, true, this.sqlite);
173
+ const connName = `RO_${databasePath})`;
174
+ this._connectionDict.set(connName, conn);
169
175
  return Promise.resolve(conn);
170
176
  }
171
177
  catch (err) {
@@ -175,7 +181,8 @@ var capacitorCapacitorSQLite = (function (exports, core) {
175
181
  async closeNCConnection(databasePath) {
176
182
  try {
177
183
  await this.sqlite.closeNCConnection({ databasePath });
178
- this._connectionDict.delete(databasePath);
184
+ const connName = `RO_${databasePath})`;
185
+ this._connectionDict.delete(connName);
179
186
  return Promise.resolve();
180
187
  }
181
188
  catch (err) {
@@ -184,12 +191,14 @@ var capacitorCapacitorSQLite = (function (exports, core) {
184
191
  }
185
192
  async isNCConnection(databasePath) {
186
193
  const res = {};
187
- res.result = this._connectionDict.has(databasePath);
194
+ const connName = `RO_${databasePath})`;
195
+ res.result = this._connectionDict.has(connName);
188
196
  return Promise.resolve(res);
189
197
  }
190
198
  async retrieveNCConnection(databasePath) {
191
199
  if (this._connectionDict.has(databasePath)) {
192
- const conn = this._connectionDict.get(databasePath);
200
+ const connName = `RO_${databasePath})`;
201
+ const conn = this._connectionDict.get(connName);
193
202
  if (typeof conn != 'undefined')
194
203
  return Promise.resolve(conn);
195
204
  else {
@@ -215,12 +224,14 @@ var capacitorCapacitorSQLite = (function (exports, core) {
215
224
  async closeAllConnections() {
216
225
  const delDict = new Map();
217
226
  try {
218
- for (const database of this._connectionDict.keys()) {
219
- await this.sqlite.closeConnection({ database });
220
- delDict.set(database, null);
227
+ for (const key of this._connectionDict.keys()) {
228
+ const database = key.substring(3);
229
+ const readonly = key.substring(0, 3) === ("RO_") ? true : false;
230
+ await this.sqlite.closeConnection({ database, readonly });
231
+ delDict.set(key, null);
221
232
  }
222
- for (const database of delDict.keys()) {
223
- this._connectionDict.delete(database);
233
+ for (const key of delDict.keys()) {
234
+ this._connectionDict.delete(key);
224
235
  }
225
236
  return Promise.resolve();
226
237
  }
@@ -344,16 +355,23 @@ var capacitorCapacitorSQLite = (function (exports, core) {
344
355
  * SQLiteDBConnection Class
345
356
  */
346
357
  class SQLiteDBConnection {
347
- constructor(dbName, sqlite) {
358
+ constructor(dbName, readonly, sqlite) {
348
359
  this.dbName = dbName;
360
+ this.readonly = readonly;
349
361
  this.sqlite = sqlite;
350
362
  }
351
363
  getConnectionDBName() {
352
364
  return this.dbName;
353
365
  }
366
+ getConnectionReadOnly() {
367
+ return this.readonly;
368
+ }
354
369
  async open() {
355
370
  try {
356
- await this.sqlite.open({ database: this.dbName });
371
+ await this.sqlite.open({
372
+ database: this.dbName,
373
+ readonly: this.readonly,
374
+ });
357
375
  return Promise.resolve();
358
376
  }
359
377
  catch (err) {
@@ -362,7 +380,10 @@ var capacitorCapacitorSQLite = (function (exports, core) {
362
380
  }
363
381
  async close() {
364
382
  try {
365
- await this.sqlite.close({ database: this.dbName });
383
+ await this.sqlite.close({
384
+ database: this.dbName,
385
+ readonly: this.readonly,
386
+ });
366
387
  return Promise.resolve();
367
388
  }
368
389
  catch (err) {
@@ -373,6 +394,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
373
394
  try {
374
395
  const res = await this.sqlite.getUrl({
375
396
  database: this.dbName,
397
+ readonly: this.readonly,
376
398
  });
377
399
  return Promise.resolve(res);
378
400
  }
@@ -384,6 +406,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
384
406
  try {
385
407
  const version = await this.sqlite.getVersion({
386
408
  database: this.dbName,
409
+ readonly: this.readonly,
387
410
  });
388
411
  return Promise.resolve(version);
389
412
  }
@@ -395,6 +418,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
395
418
  try {
396
419
  const res = await this.sqlite.getTableList({
397
420
  database: this.dbName,
421
+ readonly: this.readonly,
398
422
  });
399
423
  return Promise.resolve(res);
400
424
  }
@@ -404,12 +428,18 @@ var capacitorCapacitorSQLite = (function (exports, core) {
404
428
  }
405
429
  async execute(statements, transaction = true) {
406
430
  try {
407
- const res = await this.sqlite.execute({
408
- database: this.dbName,
409
- statements: statements,
410
- transaction: transaction,
411
- });
412
- return Promise.resolve(res);
431
+ if (!this.readonly) {
432
+ const res = await this.sqlite.execute({
433
+ database: this.dbName,
434
+ statements: statements,
435
+ transaction: transaction,
436
+ readonly: false,
437
+ });
438
+ return Promise.resolve(res);
439
+ }
440
+ else {
441
+ return Promise.reject('not allowed in read-only mode');
442
+ }
413
443
  }
414
444
  catch (err) {
415
445
  return Promise.reject(err);
@@ -423,6 +453,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
423
453
  database: this.dbName,
424
454
  statement: statement,
425
455
  values: values,
456
+ readonly: this.readonly,
426
457
  });
427
458
  }
428
459
  else {
@@ -430,6 +461,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
430
461
  database: this.dbName,
431
462
  statement: statement,
432
463
  values: [],
464
+ readonly: this.readonly,
433
465
  });
434
466
  }
435
467
  if (res && typeof res.values[0] === 'object') {
@@ -457,24 +489,31 @@ var capacitorCapacitorSQLite = (function (exports, core) {
457
489
  async run(statement, values, transaction = true) {
458
490
  let res;
459
491
  try {
460
- if (values && values.length > 0) {
461
- res = await this.sqlite.run({
462
- database: this.dbName,
463
- statement: statement,
464
- values: values,
465
- transaction: transaction,
466
- });
467
- // }
492
+ if (!this.readonly) {
493
+ if (values && values.length > 0) {
494
+ res = await this.sqlite.run({
495
+ database: this.dbName,
496
+ statement: statement,
497
+ values: values,
498
+ transaction: transaction,
499
+ readonly: false,
500
+ });
501
+ // }
502
+ }
503
+ else {
504
+ res = await this.sqlite.run({
505
+ database: this.dbName,
506
+ statement: statement,
507
+ values: [],
508
+ transaction: transaction,
509
+ readonly: false,
510
+ });
511
+ }
512
+ return Promise.resolve(res);
468
513
  }
469
514
  else {
470
- res = await this.sqlite.run({
471
- database: this.dbName,
472
- statement: statement,
473
- values: [],
474
- transaction: transaction,
475
- });
515
+ return Promise.reject('not allowed in read-only mode');
476
516
  }
477
- return Promise.resolve(res);
478
517
  }
479
518
  catch (err) {
480
519
  return Promise.reject(err);
@@ -482,13 +521,19 @@ var capacitorCapacitorSQLite = (function (exports, core) {
482
521
  }
483
522
  async executeSet(set, transaction = true) {
484
523
  try {
485
- const res = await this.sqlite.executeSet({
486
- database: this.dbName,
487
- set: set,
488
- transaction: transaction,
489
- });
490
- // }
491
- return Promise.resolve(res);
524
+ if (!this.readonly) {
525
+ const res = await this.sqlite.executeSet({
526
+ database: this.dbName,
527
+ set: set,
528
+ transaction: transaction,
529
+ readonly: false,
530
+ });
531
+ // }
532
+ return Promise.resolve(res);
533
+ }
534
+ else {
535
+ return Promise.reject('not allowed in read-only mode');
536
+ }
492
537
  }
493
538
  catch (err) {
494
539
  return Promise.reject(err);
@@ -498,6 +543,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
498
543
  try {
499
544
  const res = await this.sqlite.isDBExists({
500
545
  database: this.dbName,
546
+ readonly: this.readonly,
501
547
  });
502
548
  return Promise.resolve(res);
503
549
  }
@@ -510,6 +556,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
510
556
  const res = await this.sqlite.isTableExists({
511
557
  database: this.dbName,
512
558
  table: table,
559
+ readonly: this.readonly,
513
560
  });
514
561
  return Promise.resolve(res);
515
562
  }
@@ -521,6 +568,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
521
568
  try {
522
569
  const res = await this.sqlite.isDBOpen({
523
570
  database: this.dbName,
571
+ readonly: this.readonly,
524
572
  });
525
573
  return Promise.resolve(res);
526
574
  }
@@ -530,8 +578,16 @@ var capacitorCapacitorSQLite = (function (exports, core) {
530
578
  }
531
579
  async delete() {
532
580
  try {
533
- await this.sqlite.deleteDatabase({ database: this.dbName });
534
- return Promise.resolve();
581
+ if (!this.readonly) {
582
+ await this.sqlite.deleteDatabase({
583
+ database: this.dbName,
584
+ readonly: false,
585
+ });
586
+ return Promise.resolve();
587
+ }
588
+ else {
589
+ return Promise.reject('not allowed in read-only mode');
590
+ }
535
591
  }
536
592
  catch (err) {
537
593
  return Promise.reject(err);
@@ -539,10 +595,16 @@ var capacitorCapacitorSQLite = (function (exports, core) {
539
595
  }
540
596
  async createSyncTable() {
541
597
  try {
542
- const res = await this.sqlite.createSyncTable({
543
- database: this.dbName,
544
- });
545
- return Promise.resolve(res);
598
+ if (!this.readonly) {
599
+ const res = await this.sqlite.createSyncTable({
600
+ database: this.dbName,
601
+ readonly: false,
602
+ });
603
+ return Promise.resolve(res);
604
+ }
605
+ else {
606
+ return Promise.reject('not allowed in read-only mode');
607
+ }
546
608
  }
547
609
  catch (err) {
548
610
  return Promise.reject(err);
@@ -550,11 +612,17 @@ var capacitorCapacitorSQLite = (function (exports, core) {
550
612
  }
551
613
  async setSyncDate(syncdate) {
552
614
  try {
553
- await this.sqlite.setSyncDate({
554
- database: this.dbName,
555
- syncdate: syncdate,
556
- });
557
- return Promise.resolve();
615
+ if (!this.readonly) {
616
+ await this.sqlite.setSyncDate({
617
+ database: this.dbName,
618
+ syncdate: syncdate,
619
+ readonly: false,
620
+ });
621
+ return Promise.resolve();
622
+ }
623
+ else {
624
+ return Promise.reject('not allowed in read-only mode');
625
+ }
558
626
  }
559
627
  catch (err) {
560
628
  return Promise.reject(err);
@@ -564,6 +632,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
564
632
  try {
565
633
  const res = await this.sqlite.getSyncDate({
566
634
  database: this.dbName,
635
+ readonly: this.readonly,
567
636
  });
568
637
  let retDate = '';
569
638
  if (res.syncDate > 0)
@@ -579,6 +648,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
579
648
  const res = await this.sqlite.exportToJson({
580
649
  database: this.dbName,
581
650
  jsonexportmode: mode,
651
+ readonly: this.readonly,
582
652
  });
583
653
  return Promise.resolve(res);
584
654
  }
@@ -588,8 +658,16 @@ var capacitorCapacitorSQLite = (function (exports, core) {
588
658
  }
589
659
  async deleteExportedRows() {
590
660
  try {
591
- await this.sqlite.deleteExportedRows({ database: this.dbName });
592
- return Promise.resolve();
661
+ if (!this.readonly) {
662
+ await this.sqlite.deleteExportedRows({
663
+ database: this.dbName,
664
+ readonly: false,
665
+ });
666
+ return Promise.resolve();
667
+ }
668
+ else {
669
+ return Promise.reject('not allowed in read-only mode');
670
+ }
593
671
  }
594
672
  catch (err) {
595
673
  return Promise.reject(err);
@@ -597,55 +675,65 @@ var capacitorCapacitorSQLite = (function (exports, core) {
597
675
  }
598
676
  async executeTransaction(txn) {
599
677
  try {
600
- const ret = await this.sqlite.execute({
601
- database: this.dbName,
602
- statements: 'BEGIN TRANSACTION;',
603
- transaction: false,
604
- });
605
- if (ret.changes.changes < 0) {
606
- return Promise.reject('Error in BEGIN TRANSACTION');
607
- }
608
- for (const task of txn) {
609
- if (task.values && task.values.length > 0) {
610
- const ret = await this.sqlite.run({
611
- database: this.dbName,
612
- statement: task.statement,
613
- values: task.values,
614
- transaction: false,
615
- });
616
- if (ret.changes.lastId === -1) {
617
- await this.execute('ROLLBACK;', false);
618
- return Promise.reject('Error in transaction run ');
619
- }
678
+ if (!this.readonly) {
679
+ const ret = await this.sqlite.execute({
680
+ database: this.dbName,
681
+ statements: 'BEGIN TRANSACTION;',
682
+ transaction: false,
683
+ });
684
+ if (ret.changes.changes < 0) {
685
+ return Promise.reject('Error in BEGIN TRANSACTION');
620
686
  }
621
- else {
622
- const ret = await this.sqlite.execute({
623
- database: this.dbName,
624
- statements: task.statement,
625
- transaction: false,
626
- });
627
- if (ret.changes.changes < 0) {
628
- await this.sqlite.execute({
687
+ for (const task of txn) {
688
+ if (task.values && task.values.length > 0) {
689
+ const ret = await this.sqlite.run({
690
+ database: this.dbName,
691
+ statement: task.statement,
692
+ values: task.values,
693
+ transaction: false,
694
+ readonly: false,
695
+ });
696
+ if (ret.changes.lastId === -1) {
697
+ await this.execute('ROLLBACK;', false);
698
+ return Promise.reject('Error in transaction run ');
699
+ }
700
+ }
701
+ else {
702
+ const ret = await this.sqlite.execute({
629
703
  database: this.dbName,
630
- statements: 'ROLLBACK;',
704
+ statements: task.statement,
631
705
  transaction: false,
706
+ readonly: false,
632
707
  });
633
- return Promise.reject('Error in transaction execute ');
708
+ if (ret.changes.changes < 0) {
709
+ await this.sqlite.execute({
710
+ database: this.dbName,
711
+ statements: 'ROLLBACK;',
712
+ transaction: false,
713
+ readonly: false,
714
+ });
715
+ return Promise.reject('Error in transaction execute ');
716
+ }
634
717
  }
635
718
  }
719
+ await this.sqlite.execute({
720
+ database: this.dbName,
721
+ statements: 'COMMIT;',
722
+ transaction: false,
723
+ readonly: false,
724
+ });
725
+ return Promise.resolve();
726
+ }
727
+ else {
728
+ return Promise.reject('not allowed in read-only mode');
636
729
  }
637
- await this.sqlite.execute({
638
- database: this.dbName,
639
- statements: 'COMMIT;',
640
- transaction: false,
641
- });
642
- return Promise.resolve();
643
730
  }
644
731
  catch (err) {
645
732
  await this.sqlite.execute({
646
733
  database: this.dbName,
647
734
  statements: 'ROLLBACK;',
648
735
  transaction: false,
736
+ readonly: false,
649
737
  });
650
738
  return Promise.reject(err);
651
739
  }