@capacitor-community/sqlite 4.1.0-4 → 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.
@@ -43,10 +43,6 @@ class UtilsSQLite {
43
43
  password: string,*/) {
44
44
  const msg = 'OpenOrCreateDatabase: ';
45
45
  // open sqlite3 database
46
- /* const mDB: any = new this.JSQlite.Database(pathDB, {
47
- verbose: console.log,
48
- });
49
- */
50
46
  const mDB = new this.SQLite3.Database(pathDB, {
51
47
  verbose: console.log,
52
48
  });
@@ -62,14 +58,9 @@ class UtilsSQLite {
62
58
  if (password.length > 0) {
63
59
  await this.setCipherPragma(mDB, password);
64
60
  }
65
- */
61
+ */
66
62
  // set Foreign Keys On
67
63
  await this.setForeignKeyConstraintsEnabled(mDB, true);
68
- // Check Version
69
- const curVersion = await this.getVersion(mDB);
70
- if (curVersion === 0) {
71
- await this.setVersion(mDB, 1);
72
- }
73
64
  }
74
65
  catch (err) {
75
66
  return Promise.reject(msg + `${err}`);
@@ -345,9 +336,7 @@ class UtilsSQLite {
345
336
  if (trimStmt === 'DELETE FROM' &&
346
337
  stmt.toLowerCase().includes('WHERE'.toLowerCase())) {
347
338
  const whereStmt = `${stmt.trim()};`;
348
- console.log(`in utilsSQLite execute whereStmt ${whereStmt}`);
349
339
  const rStmt = await this.deleteSQL(mDB, whereStmt, []);
350
- console.log(`in utilsSQLite execute rStmt ${rStmt}`);
351
340
  resArr.push(rStmt);
352
341
  }
353
342
  else {
@@ -356,7 +345,6 @@ class UtilsSQLite {
356
345
  }
357
346
  sqlStmt = resArr.join(';');
358
347
  }
359
- console.log(`in utilsSQLite execute sqlStmt ${sqlStmt}`);
360
348
  await this.execDB(mDB, sqlStmt);
361
349
  changes = (await this.dbChanges(mDB)) - initChanges;
362
350
  return Promise.resolve(changes);
@@ -448,7 +436,6 @@ class UtilsSQLite {
448
436
  async runExec(db, stmt, values = []) {
449
437
  return new Promise((resolve, reject) => {
450
438
  if (values != null && values.length > 0) {
451
- console.log(`in runExec stmt: ${stmt} values: ${values}`);
452
439
  db.run(stmt, values, (err) => {
453
440
  if (err) {
454
441
  console.log(`in runExec err1: ${JSON.stringify(err)}`);
@@ -512,7 +499,6 @@ class UtilsSQLite {
512
499
  .substring('DELETE FROM'.length)
513
500
  .trim();
514
501
  sqlStmt = `UPDATE ${tableName} SET sql_deleted = 1 ${clauseStmt}`;
515
- console.log(`in deleteSQL sqlStmt: ${sqlStmt}`);
516
502
  // Find REFERENCES if any and update the sql_deleted column
517
503
  await this.findReferencesAndUpdate(db, tableName, clauseStmt, values);
518
504
  }
@@ -537,31 +523,24 @@ class UtilsSQLite {
537
523
  return;
538
524
  }
539
525
  const tableNameWithRefs = references.pop();
540
- console.log(`references: ${references}`);
541
- console.log(`tableNameWithRefs: ${tableNameWithRefs}`);
542
526
  for (const refe of references) {
543
527
  // get the tableName of the reference
544
528
  const refTable = await this.getReferenceTableName(refe);
545
529
  if (refTable.length <= 0) {
546
530
  continue;
547
531
  }
548
- console.log(`refTable: ${refTable}`);
549
532
  // get the with references columnName
550
533
  const withRefsNames = await this.getWithRefsColumnName(refe);
551
- console.log(`withRefsNames: ${withRefsNames}`);
552
534
  if (withRefsNames.length <= 0) {
553
535
  continue;
554
536
  }
555
537
  // get the referenced columnName
556
538
  const colNames = await this.getReferencedColumnName(refe);
557
- console.log(`colNames: ${colNames}`);
558
539
  if (colNames.length <= 0) {
559
540
  continue;
560
541
  }
561
542
  // update the where clause
562
543
  const uWhereStmt = await this.updateWhere(whereStmt, withRefsNames, colNames);
563
- console.log(`whereStmt: ${whereStmt}`);
564
- console.log(`uWhereStmt: ${uWhereStmt}`);
565
544
  if (uWhereStmt.length <= 0) {
566
545
  continue;
567
546
  }
@@ -571,31 +550,22 @@ class UtilsSQLite {
571
550
  updTableName = refTable;
572
551
  updColNames = withRefsNames;
573
552
  }
574
- console.log(`updTableName: ${updTableName}`);
575
- console.log(`updColNames: ${updColNames}`);
576
553
  //update sql_deleted for this reference
577
554
  const stmt = 'UPDATE ' + updTableName + ' SET sql_deleted = 1 ' + uWhereStmt;
578
- console.log(`stmt: ${stmt}`);
579
- console.log(`values: ${values}`);
580
555
  if (values != null && values.length > 0) {
581
556
  const mVal = await this.replaceUndefinedByNull(values);
582
557
  let arrVal = whereStmt.split('?');
583
558
  if (arrVal[arrVal.length - 1] === ';')
584
559
  arrVal = arrVal.slice(0, -1);
585
- console.log(`arrVal: ${arrVal}`);
586
560
  const selValues = [];
587
561
  for (const [j, val] of arrVal.entries()) {
588
- console.log(`j: ${j} val: ${val}`);
589
562
  for (const updVal of updColNames) {
590
563
  const idxVal = val.indexOf(updVal);
591
- console.log(`updVal: ${updVal} idxVal ${idxVal}`);
592
564
  if (idxVal > -1) {
593
565
  selValues.push(mVal[j]);
594
566
  }
595
567
  }
596
568
  }
597
- console.log(`*** stmt: ${selValues}`);
598
- console.log(`*** selValues: ${selValues}`);
599
569
  await db.run(stmt, selValues);
600
570
  }
601
571
  else {
@@ -1717,11 +1687,11 @@ utilsJson.UtilsJson = UtilsJson;
1717
1687
  Object.defineProperty(exportToJson, "__esModule", { value: true });
1718
1688
  exportToJson.ExportToJson = void 0;
1719
1689
  const utilsSQLite_1$4 = utilsSQLite;
1720
- const utilsJson_1$4 = utilsJson;
1690
+ const utilsJson_1$3 = utilsJson;
1721
1691
  class ExportToJson {
1722
1692
  constructor() {
1723
1693
  this.sqliteUtil = new utilsSQLite_1$4.UtilsSQLite();
1724
- this.jsonUtil = new utilsJson_1$4.UtilsJson();
1694
+ this.jsonUtil = new utilsJson_1$3.UtilsJson();
1725
1695
  }
1726
1696
  /**
1727
1697
  * CreateExportObject
@@ -2539,14 +2509,14 @@ utilsDrop.UtilsDrop = UtilsDrop;
2539
2509
 
2540
2510
  Object.defineProperty(importFromJson, "__esModule", { value: true });
2541
2511
  importFromJson.ImportFromJson = void 0;
2542
- const utilsDrop_1$1 = utilsDrop;
2512
+ const utilsDrop_1 = utilsDrop;
2543
2513
  const utilsSQLite_1$2 = utilsSQLite;
2544
- const utilsJson_1$3 = utilsJson;
2514
+ const utilsJson_1$2 = utilsJson;
2545
2515
  class ImportFromJson {
2546
2516
  constructor() {
2547
- this.jsonUtil = new utilsJson_1$3.UtilsJson();
2517
+ this.jsonUtil = new utilsJson_1$2.UtilsJson();
2548
2518
  this.sqliteUtil = new utilsSQLite_1$2.UtilsSQLite();
2549
- this.dropUtil = new utilsDrop_1$1.UtilsDrop();
2519
+ this.dropUtil = new utilsDrop_1.UtilsDrop();
2550
2520
  }
2551
2521
  /**
2552
2522
  * CreateDatabaseSchema
@@ -2808,10 +2778,13 @@ class UtilsFile {
2808
2778
  */
2809
2779
  getAssetsDatabasesPath() {
2810
2780
  let retPath = '';
2811
- const rawdata = this.NodeFs.readFileSync(this.Path.resolve(this.appPath, 'capacitor.config.json'));
2812
- const webDir = JSON.parse(rawdata).webDir;
2781
+ const webDir = this.capConfig.webDir;
2813
2782
  const dir = webDir === 'www' ? 'src' : 'public';
2814
- retPath = this.Path.resolve(this.appPath, dir, 'assets', this.pathDB.toLowerCase());
2783
+ let mAppPath = this.appPath;
2784
+ if (this.Path.basename(this.appPath) === 'electron') {
2785
+ mAppPath = this.Path.dirname(this.appPath);
2786
+ }
2787
+ retPath = this.Path.resolve(mAppPath, dir, 'assets', 'databases');
2815
2788
  return retPath;
2816
2789
  }
2817
2790
  /**
@@ -3120,18 +3093,10 @@ var utilsUpgrade = {};
3120
3093
 
3121
3094
  Object.defineProperty(utilsUpgrade, "__esModule", { value: true });
3122
3095
  utilsUpgrade.UtilsUpgrade = void 0;
3123
- const utilsJson_1$2 = utilsJson;
3124
- const utilsDrop_1 = utilsDrop;
3125
- const utilsFile_1$2 = utilsFile;
3126
3096
  const utilsSQLite_1$1 = utilsSQLite;
3127
3097
  class UtilsUpgrade {
3128
3098
  constructor() {
3129
3099
  this.sqliteUtil = new utilsSQLite_1$1.UtilsSQLite();
3130
- this.fileUtil = new utilsFile_1$2.UtilsFile();
3131
- this.dropUtil = new utilsDrop_1.UtilsDrop();
3132
- this.jsonUtil = new utilsJson_1$2.UtilsJson();
3133
- this._alterTables = {};
3134
- this._commonColumns = {};
3135
3100
  }
3136
3101
  /**
3137
3102
  * OnUpgrade
@@ -3141,300 +3106,50 @@ class UtilsUpgrade {
3141
3106
  * @param curVersion
3142
3107
  * @param targetVersion
3143
3108
  */
3144
- async onUpgrade(mDB, vUpgDict, dbName, curVersion, targetVersion) {
3145
- const upgrade = vUpgDict[curVersion];
3146
- if (upgrade != null) {
3147
- const keys = Object.keys(upgrade);
3148
- if (!keys.includes('toVersion')) {
3149
- return Promise.reject('onUpgrade: toVersion not given');
3150
- }
3151
- const toVersion = upgrade.toVersion;
3152
- if (!keys.includes('statement')) {
3153
- return Promise.reject('onUpgrade: statement not given');
3154
- }
3155
- const statement = upgrade.statement;
3156
- let set = [];
3157
- if (keys.includes('set')) {
3158
- set = upgrade.set;
3159
- }
3160
- if (targetVersion < toVersion) {
3161
- let msg = 'Error: version mistmatch ';
3162
- msg += 'Upgrade Statement would upgrade to ';
3163
- msg += `version ${toVersion} , but target version `;
3164
- msg += `is ${targetVersion} for database ${dbName}`;
3165
- msg += ` and version ${curVersion}`;
3166
- return Promise.reject(`onUpgrade: ${msg}`);
3167
- }
3168
- try {
3169
- // set Foreign Keys Off
3170
- await this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB, false);
3171
- await this.fileUtil.copyFileName(dbName, `backup-${dbName}`);
3172
- const initChanges = await this.sqliteUtil.dbChanges(mDB);
3173
- // Here we assume that all table schemas are given
3174
- // in the upgrade statement
3175
- if (statement.length > 0) {
3176
- await this.executeStatementProcess(mDB, statement);
3177
- // Here we assume that the Set contains only
3178
- // - the data for new tables
3179
- // as INSERT statements
3180
- // - the data for new columns in existing tables
3181
- // as UPDATE statements
3182
- if (set.length > 0) {
3183
- await this.executeSetProcess(mDB, set, toVersion);
3184
- }
3185
- }
3186
- // set Foreign Keys On
3187
- await this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB, true);
3188
- const changes = (await this.sqliteUtil.dbChanges(mDB)) - initChanges;
3189
- return Promise.resolve(changes);
3190
- }
3191
- catch (err) {
3192
- return Promise.reject(`onUpgrade: ${err}`);
3193
- }
3194
- }
3195
- else {
3196
- return Promise.reject('onUpgrade: upgrade not found');
3197
- }
3198
- }
3199
- /**
3200
- * ExecuteStatementProcess
3201
- * @param mDB
3202
- * @param statement
3203
- */
3204
- async executeStatementProcess(mDB, statement) {
3205
- try {
3206
- // -> backup all existing tables "tableName" in
3207
- // "temp_tableName"
3208
- await this.backupTables(mDB);
3209
- // -> Drop all Indexes
3210
- await this.dropUtil.dropElements(mDB, 'index');
3211
- // -> Drop all Triggers
3212
- await this.dropUtil.dropElements(mDB, 'trigger');
3213
- // -> Create new tables from upgrade.statement
3214
- const changes = await this.sqliteUtil.execute(mDB, statement, false);
3215
- if (changes < 0) {
3216
- return Promise.reject('ExecuteStatementProcess: ' + 'changes < 0');
3217
- }
3218
- // -> Create the list of table's common fields
3219
- await this.findCommonColumns(mDB);
3220
- // -> Update the new table's data from old table's data
3221
- if (Object.keys(this._commonColumns).length > 0) {
3222
- await this.updateNewTablesData(mDB);
3223
- }
3224
- return Promise.resolve();
3225
- }
3226
- catch (err) {
3227
- return Promise.reject(`ExecuteStatementProcess: ${err}`);
3228
- }
3229
- finally {
3230
- // -> Drop _temp_tables
3231
- await this.dropUtil.dropTempTables(mDB, this._alterTables);
3232
- // -> Do some cleanup
3233
- this._alterTables = {};
3234
- this._commonColumns = {};
3235
- }
3236
- }
3237
- /**
3238
- * ExecuteSetProcess
3239
- * @param mDB
3240
- * @param set
3241
- * @param toVersion
3242
- */
3243
- async executeSetProcess(mDB, set, toVersion) {
3244
- try {
3245
- // -> load new data
3246
- const lastId = await this.sqliteUtil.executeSet(mDB, set, false);
3247
- if (lastId < 0) {
3248
- return Promise.reject('ExecuteSetProcess: lastId ' + '< 0');
3249
- }
3250
- // -> update database version
3251
- await this.sqliteUtil.setVersion(mDB, toVersion);
3252
- // -> update syncDate if any
3253
- const retB = await this.jsonUtil.isTableExists(mDB, true, 'sync_table');
3254
- if (retB) {
3255
- const sDate = Math.round(new Date().getTime() / 1000);
3256
- let stmt = 'UPDATE sync_table SET ';
3257
- stmt += `sync_date = ${sDate} WHERE id = 1;`;
3258
- const changes = await this.sqliteUtil.execute(mDB, stmt, false);
3259
- if (changes < 0) {
3260
- return Promise.reject('ExecuteSetProcess: changes ' + '< 0');
3109
+ async onUpgrade(mDB, vUpgDict, curVersion, targetVersion) {
3110
+ const sortedKeys = Object.keys(vUpgDict)
3111
+ .map(item => parseInt(item))
3112
+ .sort();
3113
+ for (const versionKey of sortedKeys) {
3114
+ if (versionKey > curVersion && versionKey <= targetVersion) {
3115
+ const statements = vUpgDict[versionKey].statements;
3116
+ if (statements.length === 0) {
3117
+ return Promise.reject('onUpgrade: statements not given');
3261
3118
  }
3262
- }
3263
- return Promise.resolve();
3264
- }
3265
- catch (err) {
3266
- return Promise.reject(`ExecuteSetProcess: ${err}`);
3267
- }
3268
- }
3269
- /**
3270
- * BackupTables
3271
- * @param mDB
3272
- */
3273
- async backupTables(mDB) {
3274
- const msg = 'BackupTables: ';
3275
- try {
3276
- const tables = await this.sqliteUtil.getTablesNames(mDB);
3277
- for (const table of tables) {
3278
3119
  try {
3279
- await this.backupTable(mDB, table);
3120
+ // set Foreign Keys Off
3121
+ await this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB, false);
3122
+ const initChanges = await this.sqliteUtil.dbChanges(mDB);
3123
+ await this.executeStatementsProcess(mDB, statements);
3124
+ await this.sqliteUtil.setVersion(mDB, versionKey);
3125
+ // set Foreign Keys On
3126
+ await this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB, true);
3127
+ const changes = (await this.sqliteUtil.dbChanges(mDB)) - initChanges;
3128
+ return Promise.resolve(changes);
3280
3129
  }
3281
3130
  catch (err) {
3282
- return Promise.reject(`${msg}table ${table}: ` + `${err}`);
3131
+ return Promise.reject(`onUpgrade: ${err}`);
3283
3132
  }
3284
3133
  }
3285
- return Promise.resolve();
3286
- }
3287
- catch (err) {
3288
- return Promise.reject(`BackupTables: ${err}`);
3289
3134
  }
3290
3135
  }
3291
3136
  /**
3292
- * BackupTable
3137
+ * ExecuteStatementProcess
3293
3138
  * @param mDB
3294
- * @param table
3139
+ * @param statements
3295
3140
  */
3296
- async backupTable(mDB, table) {
3141
+ async executeStatementsProcess(mDB, statements) {
3297
3142
  try {
3298
- // start a transaction
3299
3143
  await this.sqliteUtil.beginTransaction(mDB, true);
3300
- // get the table's column names
3301
- const colNames = await this.getTableColumnNames(mDB, table);
3302
- this._alterTables[`${table}`] = colNames;
3303
- const tmpTable = `_temp_${table}`;
3304
- // Drop the tmpTable if exists
3305
- const delStmt = `DROP TABLE IF EXISTS ${tmpTable};`;
3306
- await this.sqliteUtil.prepareRun(mDB, delStmt, [], false);
3307
- // prefix the table with _temp_
3308
- let stmt = `ALTER TABLE ${table} RENAME `;
3309
- stmt += `TO ${tmpTable};`;
3310
- const lastId = await this.sqliteUtil.prepareRun(mDB, stmt, [], false);
3311
- if (lastId < 0) {
3312
- let msg = 'BackupTable: lastId < 0';
3313
- try {
3314
- await this.sqliteUtil.rollbackTransaction(mDB, true);
3315
- }
3316
- catch (err) {
3317
- msg += `: ${err}`;
3318
- }
3319
- return Promise.reject(`${msg}`);
3320
- }
3321
- else {
3322
- try {
3323
- await this.sqliteUtil.commitTransaction(mDB, true);
3324
- }
3325
- catch (err) {
3326
- return Promise.reject('BackupTable: ' + `${err}`);
3327
- }
3328
- }
3329
- return Promise.resolve();
3330
- }
3331
- catch (err) {
3332
- return Promise.reject(`BackupTable: ${err}`);
3333
- }
3334
- }
3335
- /**
3336
- * GetTableColumnNames
3337
- * @param mDB
3338
- * @param tableName
3339
- */
3340
- async getTableColumnNames(mDB, tableName) {
3341
- let resQuery = [];
3342
- const retNames = [];
3343
- const query = `PRAGMA table_info('${tableName}');`;
3344
- try {
3345
- resQuery = await this.sqliteUtil.queryAll(mDB, query, []);
3346
- if (resQuery.length > 0) {
3347
- for (const query of resQuery) {
3348
- retNames.push(query.name);
3349
- }
3350
- }
3351
- return Promise.resolve(retNames);
3352
- }
3353
- catch (err) {
3354
- return Promise.reject('GetTableColumnNames: ' + `${err}`);
3355
- }
3356
- }
3357
- /**
3358
- * FindCommonColumns
3359
- * @param mDB
3360
- */
3361
- async findCommonColumns(mDB) {
3362
- try {
3363
- // Get new table list
3364
- const tables = await this.sqliteUtil.getTablesNames(mDB);
3365
- if (tables.length === 0) {
3366
- return Promise.reject('FindCommonColumns: get ' + "table's names failed");
3367
- }
3368
- for (const table of tables) {
3369
- // get the column's name
3370
- const tableNames = await this.getTableColumnNames(mDB, table);
3371
- // find the common columns
3372
- const keys = Object.keys(this._alterTables);
3373
- if (keys.includes(table)) {
3374
- this._commonColumns[table] = this.arraysIntersection(this._alterTables[table], tableNames);
3375
- }
3144
+ for (const statement of statements) {
3145
+ await this.sqliteUtil.execute(mDB, statement, false);
3376
3146
  }
3147
+ await this.sqliteUtil.commitTransaction(mDB, true);
3377
3148
  return Promise.resolve();
3378
3149
  }
3379
3150
  catch (err) {
3380
- return Promise.reject(`FindCommonColumns: ${err}`);
3381
- }
3382
- }
3383
- /**
3384
- * ArraysIntersection
3385
- * @param a1
3386
- * @param a2
3387
- */
3388
- arraysIntersection(a1, a2) {
3389
- if (a1 != null && a2 != null) {
3390
- const first = new Set(a1);
3391
- const second = new Set(a2);
3392
- return [...first].filter(item => second.has(item));
3393
- }
3394
- else {
3395
- return [];
3396
- }
3397
- }
3398
- /**
3399
- * UpdateNewTablesData
3400
- * @param mDB
3401
- */
3402
- async updateNewTablesData(mDB) {
3403
- try {
3404
- // start a transaction
3405
- await this.sqliteUtil.beginTransaction(mDB, true);
3406
- const statements = [];
3407
- const keys = Object.keys(this._commonColumns);
3408
- keys.forEach(key => {
3409
- const columns = this._commonColumns[key].join(',');
3410
- let stmt = `INSERT INTO ${key} `;
3411
- stmt += `(${columns}) `;
3412
- stmt += `SELECT ${columns} FROM _temp_${key};`;
3413
- statements.push(stmt);
3414
- });
3415
- const changes = await this.sqliteUtil.execute(mDB, statements.join('\n'), false);
3416
- if (changes < 0) {
3417
- let msg = 'updateNewTablesData: ' + 'changes < 0';
3418
- try {
3419
- await this.sqliteUtil.rollbackTransaction(mDB, true);
3420
- }
3421
- catch (err) {
3422
- msg += `: ${err}`;
3423
- }
3424
- return Promise.reject(`${msg}`);
3425
- }
3426
- else {
3427
- try {
3428
- await this.sqliteUtil.commitTransaction(mDB, true);
3429
- return Promise.resolve();
3430
- }
3431
- catch (err) {
3432
- return Promise.reject('updateNewTablesData: ' + `${err}`);
3433
- }
3434
- }
3435
- }
3436
- catch (err) {
3437
- return Promise.reject('updateNewTablesData: ' + `${err}`);
3151
+ await this.sqliteUtil.rollbackTransaction(mDB, true);
3152
+ return Promise.reject(`ExecuteStatementProcess: ${err}`);
3438
3153
  }
3439
3154
  }
3440
3155
  }
@@ -3518,8 +3233,9 @@ class Database {
3518
3233
  if (this.version > curVersion &&
3519
3234
  Object.keys(this.upgradeVersionDict).length > 0) {
3520
3235
  try {
3236
+ await this.fileUtil.copyFileName(this.dbName, `backup-${this.dbName}`);
3521
3237
  // execute the upgrade flow process
3522
- await this.upgradeUtil.onUpgrade(this.database, this.upgradeVersionDict, this.dbName, curVersion, this.version);
3238
+ await this.upgradeUtil.onUpgrade(this.database, this.upgradeVersionDict, curVersion, this.version);
3523
3239
  // delete the backup database
3524
3240
  await this.fileUtil.deleteFileName(`backup-${this.dbName}`);
3525
3241
  }
@@ -4301,16 +4017,15 @@ class CapacitorSQLite {
4301
4017
  const upgrades = this.getOptionValue(options, 'upgrade');
4302
4018
  const firstUpgrade = upgrades[0];
4303
4019
  const versionUpgradeKeys = Object.keys(firstUpgrade);
4304
- if (!versionUpgradeKeys.includes('fromVersion') ||
4305
- !versionUpgradeKeys.includes('toVersion') ||
4306
- !versionUpgradeKeys.includes('statement')) {
4020
+ if (!versionUpgradeKeys.includes('toVersion') ||
4021
+ !versionUpgradeKeys.includes('statements')) {
4307
4022
  throw new Error('Must provide an upgrade capSQLiteVersionUpgrade Object');
4308
4023
  }
4309
- if (typeof firstUpgrade.fromVersion != 'number') {
4310
- throw new Error('upgrade.fromVersion must be a number');
4024
+ if (typeof firstUpgrade.toVersion != 'number') {
4025
+ throw new Error('upgrade.toVersion must be a number');
4311
4026
  }
4312
4027
  const upgradeVersionDict = {};
4313
- upgradeVersionDict[firstUpgrade.fromVersion] = firstUpgrade;
4028
+ upgradeVersionDict[firstUpgrade.toVersion] = firstUpgrade;
4314
4029
  this.versionUpgrades[dbName] = upgradeVersionDict;
4315
4030
  return;
4316
4031
  }