wallet-core/src/db.ts

35 lines
910 B
TypeScript
Raw Normal View History

2019-12-13 13:10:20 +01:00
import { Stores } from "./types/dbTypes";
2019-12-12 22:39:45 +01:00
import { openDatabase, Database } from "./util/query";
2019-07-31 01:33:56 +02:00
2019-12-12 22:39:45 +01:00
const TALER_DB_NAME = "taler";
2019-07-31 01:33:56 +02:00
2019-12-13 13:10:20 +01:00
/**
* Current database version, should be incremented
* each time we do incompatible schema changes on the database.
* In the future we might consider adding migration functions for
* each version increment.
*/
export const WALLET_DB_VERSION = 28;
2019-07-31 01:33:56 +02:00
/**
* Return a promise that resolves
* to the taler wallet db.
*/
2019-12-12 22:39:45 +01:00
export function openTalerDatabase(
2019-07-31 01:33:56 +02:00
idbFactory: IDBFactory,
onVersionChange: () => void,
onUpgradeUnsupported: (oldVersion: number, newVersion: number) => void,
): Promise<IDBDatabase> {
2019-12-12 22:39:45 +01:00
return openDatabase(
idbFactory,
TALER_DB_NAME,
WALLET_DB_VERSION,
Stores,
onVersionChange,
onUpgradeUnsupported,
);
2019-07-31 01:33:56 +02:00
}
2019-12-12 22:39:45 +01:00
export function deleteTalerDatabase(idbFactory: IDBFactory) {
Database.deleteDatabase(idbFactory, TALER_DB_NAME);
}