From 46323cdc80def17230333345cfb8bec91ba2f5ab Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 14 Oct 2020 08:29:58 +0200 Subject: [PATCH] MOBILE-3565 core: Fix some ESLint of CoreDbProvider --- src/app/services/db.ts | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/app/services/db.ts b/src/app/services/db.ts index 1244ed1fa..ca5aedb1e 100644 --- a/src/app/services/db.ts +++ b/src/app/services/db.ts @@ -24,9 +24,7 @@ import { makeSingleton, SQLite, Platform } from '@singletons/core.singletons'; @Injectable() export class CoreDbProvider { - protected dbInstances = {}; - - constructor() { } + protected dbInstances: {[name: string]: SQLiteDB} = {}; /** * Get or create a database object. @@ -55,31 +53,31 @@ export class CoreDbProvider { * @param name DB name. * @return Promise resolved when the DB is deleted. */ - deleteDB(name: string): Promise { - let promise; - + async deleteDB(name: string): Promise { if (typeof this.dbInstances[name] != 'undefined') { // Close the database first. - promise = this.dbInstances[name].close(); - } else { - promise = Promise.resolve(); - } + await this.dbInstances[name].close(); - return promise.then(() => { const db = this.dbInstances[name]; delete this.dbInstances[name]; - if (Platform.instance.is('cordova')) { - return SQLite.instance.deleteDatabase({ - name, - location: 'default' - }); - } else { + if (db instanceof SQLiteDBMock) { // In WebSQL we cannot delete the database, just empty it. return db.emptyDatabase(); + } else { + return SQLite.instance.deleteDatabase({ + name, + location: 'default', + }); } - }); + } else if (Platform.instance.is('cordova')) { + return SQLite.instance.deleteDatabase({ + name, + location: 'default', + }); + } } + } export class CoreDB extends makeSingleton(CoreDbProvider) {}