diff options
author | Sebastian <sebasjm@gmail.com> | 2021-06-04 12:42:15 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-06-04 12:42:35 -0300 |
commit | e1b363c7dd210f2e684bc220ced25a255d00f331 (patch) | |
tree | 5d92d4150df22bf69f6296a5f1ae49c9a6405325 /packages/taler-wallet-core/src | |
parent | e223c012751857fbd048ff8f0503ce8570f495ee (diff) | |
download | wallet-core-e1b363c7dd210f2e684bc220ced25a255d00f331.tar.xz |
delete database when pressing reset-db
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 4 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/query.ts | 17 |
2 files changed, 16 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index c457d0ffc..687418097 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -180,8 +180,8 @@ export async function openTalerDatabase( return new Database(mainDbHandle, Stores); } -export function deleteTalerDatabase(idbFactory: IDBFactory): void { - Database.deleteDatabase(idbFactory, TALER_DB_NAME); +export function deleteTalerDatabase(idbFactory: IDBFactory): Promise<void> { + return Database.deleteDatabase(idbFactory, TALER_DB_NAME); } export enum ReserveRecordStatus { diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index 1ef75a420..7c2aea783 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -372,7 +372,17 @@ function runWithTransaction<T, StoreTypes extends Store<string, {}>>( const stack = Error("Failed transaction was started here."); return new Promise((resolve, reject) => { const storeName = stores.map((x) => x.name); - const tx = db.transaction(storeName, mode); + + let txOrUndef: IDBTransaction | undefined = undefined + try { + txOrUndef = db.transaction(storeName, mode); + } catch (e) { + logger.error("error opening transaction"); + logger.error(`${e}`); + return + } + const tx = txOrUndef; + let funResult: any = undefined; let gotFunResult = false; tx.oncomplete = () => { @@ -513,8 +523,9 @@ export function openDatabase( export class Database<StoreMap extends AnyStoreMap> { constructor(private db: IDBDatabase, stores: StoreMap) {} - static deleteDatabase(idbFactory: IDBFactory, dbName: string): void { - idbFactory.deleteDatabase(dbName); + static deleteDatabase(idbFactory: IDBFactory, dbName: string): Promise<void> { + const req = idbFactory.deleteDatabase(dbName) + return requestToPromise(req) } async exportDatabase(): Promise<any> { |