@capacitor-community/sqlite
Advanced tools
Comparing version 2.4.1-devversion.1 to 2.4.1-devversion.2
@@ -0,1 +1,7 @@ | ||
## 2.4.1-devversion.2 (2020-08-31) | ||
### Bug Fixes | ||
- some fixes for Handling version in Electron platform | ||
## 2.4.1-devversion.1 (2020-08-31) | ||
@@ -2,0 +8,0 @@ |
@@ -10,2 +10,3 @@ import { capSQLiteVersionUpgrade } from '../definitions'; | ||
constructor(dbName: string, dbVersion: number | undefined, upgradeStatements: Record<string, Record<number, capSQLiteVersionUpgrade>>); | ||
setup(): Promise<any>; | ||
private _openDB; | ||
@@ -12,0 +13,0 @@ createSyncTable(): Promise<any>; |
@@ -24,4 +24,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
// this._newsecret = newsecret; | ||
this._openDB(); | ||
} | ||
setup() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this._openDB(); | ||
}); | ||
} | ||
_openDB() { | ||
@@ -34,7 +38,15 @@ return __awaiter(this, void 0, void 0, function* () { | ||
let curVersion = yield this.getDBVersion(db); | ||
console.log('openDB: curVersion ', curVersion); | ||
if (curVersion === -1 || curVersion === 0) { | ||
this.updateDatabaseVersion(db, 1); | ||
curVersion = 1; | ||
yield this.updateDatabaseVersion(db, 1); | ||
curVersion = yield this.getDBVersion(db); | ||
console.log('openDB: After updateDatabaseVersion curVersion ', curVersion); | ||
} | ||
// check if the database version is Ok | ||
console.log('openDB: curVersion ' + | ||
curVersion + | ||
' databaseVersion ' + | ||
this._databaseVersion); | ||
console.log('this._databaseName ', this._databaseName); | ||
console.log('this._upgradeStatements ', this._upgradeStatements); | ||
if (curVersion !== this._databaseVersion) { | ||
@@ -46,4 +58,4 @@ // version not ok | ||
} | ||
else if (Object.keys(this._upgradeStatements).length !== 0 || | ||
Object.keys(this._upgradeStatements[this._databaseName]).length !== 0) { | ||
else if (Object.keys(this._upgradeStatements).length === 0 || | ||
Object.keys(this._upgradeStatements[this._databaseName]).length === 0) { | ||
this.isOpen = false; | ||
@@ -53,4 +65,4 @@ console.log('openDB: Error No upgrade statements found for that database'); | ||
else { | ||
db = this.onUpgrade(this._databaseName, db, curVersion, this._databaseVersion); | ||
if (db != null) { | ||
let res = yield this.onUpgrade(this._databaseName, db, curVersion, this._databaseVersion); | ||
if (res) { | ||
this.isOpen = true; | ||
@@ -76,2 +88,3 @@ } | ||
const db = this._utils.connection(this._databaseName, false /*,this._secret*/); | ||
console.log('createSyncTable '); | ||
if (db === null) { | ||
@@ -84,2 +97,3 @@ this.isOpen = false; | ||
const isExists = yield this.isTableExists(db, 'sync_table'); | ||
console.log('createSyncTable isExists ', isExists); | ||
if (!isExists) { | ||
@@ -97,2 +111,3 @@ const date = Math.round(new Date().getTime() / 1000); | ||
retRes = yield this.execute(db, stmts); | ||
console.log('createSyncTable retRes ', retRes); | ||
} | ||
@@ -367,2 +382,10 @@ db.close(); | ||
let changes = -1; | ||
// set PRAGMA | ||
let pragmas = ` | ||
PRAGMA user_version = ${this._databaseVersion}; | ||
PRAGMA foreign_keys = ON; | ||
`; | ||
const pchanges = yield this.exec(pragmas); | ||
if (pchanges === -1) | ||
resolve({ changes: changes, message: 'Error in setting PAGMA' }); | ||
// create the database schema | ||
@@ -404,10 +427,2 @@ changes = yield this.createDatabaseSchema(jsonData); | ||
let isIndexes = false; | ||
// set PRAGMA | ||
let pragmas = ` | ||
PRAGMA user_version = 1; | ||
PRAGMA foreign_keys = ON; | ||
`; | ||
const pchanges = yield this.exec(pragmas); | ||
if (pchanges === -1) | ||
resolve(-1); | ||
// create the database schema | ||
@@ -934,4 +949,13 @@ let statements = []; | ||
updateDatabaseVersion(db, newVersion) { | ||
db.run('PRAGMA user_version = $version;', { | ||
$version: newVersion, | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let pragmas = ` | ||
PRAGMA user_version = ${newVersion}; | ||
`; | ||
const pchanges = yield this.execute(db, pragmas); | ||
return pchanges; | ||
/* | ||
db.run('PRAGMA user_version = $version;', { | ||
$version: newVersion, | ||
}); | ||
*/ | ||
}); | ||
@@ -948,3 +972,3 @@ } | ||
tatements for Database '${dbName}' Version ${currentVersion}.`); | ||
return null; | ||
return false; | ||
} | ||
@@ -958,3 +982,3 @@ else if (!this._upgradeStatements[dbName][currentVersion]) { | ||
tatements for Database '${dbName}' Version ${currentVersion}.`); | ||
return null; | ||
return false; | ||
} | ||
@@ -970,3 +994,3 @@ const upgrade = this._upgradeStatements[dbName][currentVersion]; | ||
n is ${targetVersion}.`); | ||
return null; | ||
return false; | ||
} | ||
@@ -976,3 +1000,3 @@ let retB = yield this.beginTransaction(db); | ||
console.log('executeSet: Error beginTransaction failed'); | ||
return null; | ||
return false; | ||
} | ||
@@ -989,3 +1013,3 @@ // TODO | ||
nt returned error.`); | ||
return null; | ||
return false; | ||
} | ||
@@ -1007,6 +1031,6 @@ } | ||
nt Set returned error.`); | ||
return null; | ||
return false; | ||
} | ||
} | ||
this.updateDatabaseVersion(db, upgrade.toVersion); | ||
yield this.updateDatabaseVersion(db, upgrade.toVersion); | ||
// TODO | ||
@@ -1017,3 +1041,3 @@ // -> DROP all Tables in temp_dbName | ||
console.log('executeSet: Error endTransaction failed'); | ||
return null; | ||
return false; | ||
} | ||
@@ -1029,3 +1053,3 @@ /* Can you explain in which cases they will be some more updates to do | ||
// -> Delete temp_dbName | ||
return db; | ||
return true; | ||
}); | ||
@@ -1032,0 +1056,0 @@ } |
@@ -47,2 +47,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.mDb = new DatabaseSQLiteHelper(`${dbName}SQLite.db`, dbVersion, this.versionUpgrades /*,encrypted,inMode,secretKey,newsecretKey*/); | ||
yield this.mDb.setup(); | ||
if (!this.mDb.isOpen) { | ||
@@ -270,2 +271,3 @@ return Promise.reject({ | ||
this.mDb = new DatabaseSQLiteHelper(dbName, dbVersion, this.versionUpgrades); | ||
yield this.mDb.setup(); | ||
const ret = yield this.mDb.importJson(jsonObj); | ||
@@ -320,6 +322,7 @@ this.mDb.close(dbName); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.versionUpgrades[database]) { | ||
this.versionUpgrades[database] = {}; | ||
const fullDBName = `${database}SQLite.db`; | ||
if (!this.versionUpgrades[fullDBName]) { | ||
this.versionUpgrades[fullDBName] = {}; | ||
} | ||
this.versionUpgrades[database][upgrade.fromVersion] = { | ||
this.versionUpgrades[fullDBName][upgrade.fromVersion] = { | ||
fromVersion: upgrade.fromVersion, | ||
@@ -326,0 +329,0 @@ toVersion: upgrade.toVersion, |
{ | ||
"name": "@capacitor-community/sqlite", | ||
"version": "2.4.1-devversion.1", | ||
"version": "2.4.1-devversion.2", | ||
"description": "Capacitor SQLite Plugin", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/capacitor-community/sqlite", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9905898
3769