aboutsummaryrefslogtreecommitdiff
path: root/extension/background/db.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-01-05 14:20:13 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-01-05 14:20:13 +0100
commitb459ffb4241877670fb7f820a67d959fec2d995c (patch)
tree23277212792e701218100c010dcea66da3b199d2 /extension/background/db.ts
parentc48f2d39f0f62ea8f862ba08234b8a5376a11a2e (diff)
more complete DB abstractions
Diffstat (limited to 'extension/background/db.ts')
-rw-r--r--extension/background/db.ts48
1 files changed, 40 insertions, 8 deletions
diff --git a/extension/background/db.ts b/extension/background/db.ts
index 92fff47f8..1dd399907 100644
--- a/extension/background/db.ts
+++ b/extension/background/db.ts
@@ -56,7 +56,7 @@ namespace Db {
mintBaseUrl: string;
coinValue: AmountJson;
}
-
+
export interface Coin {
coinPub: string;
coinPriv: string;
@@ -88,19 +88,51 @@ function openTalerDb(): Promise<IDBDatabase> {
};
req.onupgradeneeded = (e) => {
let db = req.result;
- console.log ("DB: upgrade needed: oldVersion = " + e.oldVersion);
+ console.log("DB: upgrade needed: oldVersion = " + e.oldVersion);
switch (e.oldVersion) {
case 0: // DB does not exist yet
- let mints = db.createObjectStore("mints", { keyPath: "baseUrl" });
+ let mints = db.createObjectStore("mints", {keyPath: "baseUrl"});
mints.createIndex("pubKey", "keys.master_public_key");
- db.createObjectStore("reserves", { keyPath: "reserve_pub"});
- db.createObjectStore("denoms", { keyPath: "denomPub" });
- let coins = db.createObjectStore("coins", { keyPath: "coinPub" });
+ db.createObjectStore("reserves", {keyPath: "reserve_pub"});
+ db.createObjectStore("denoms", {keyPath: "denomPub"});
+ let coins = db.createObjectStore("coins", {keyPath: "coinPub"});
coins.createIndex("mintBaseUrl", "mintBaseUrl");
- db.createObjectStore("transactions", { keyPath: "contractHash" });
- db.createObjectStore("precoins", { keyPath: "coinPub", autoIncrement: true });
+ db.createObjectStore("transactions", {keyPath: "contractHash"});
+ db.createObjectStore("precoins",
+ {keyPath: "coinPub", autoIncrement: true});
break;
}
};
});
}
+
+
+function exportDb(db): Promise<any> {
+ let dump = {
+ name: db.name,
+ version: db.version,
+ stores: {}
+ };
+
+ return new Promise((resolve, reject) => {
+
+ let tx = db.transaction(db.objectStoreNames);
+ tx.addEventListener('complete', (e) => {
+ resolve(dump);
+ });
+ for (let i = 0; i < db.objectStoreNames.length; i++) {
+ let name = db.objectStoreNames[i];
+ let storeDump = {};
+ dump.stores[name] = storeDump;
+ let store = tx.objectStore(name)
+ .openCursor()
+ .addEventListener('success', (e) => {
+ let cursor = e.target.result;
+ if (cursor) {
+ storeDump[cursor.key] = cursor.value;
+ cursor.continue();
+ }
+ });
+ }
+ });
+} \ No newline at end of file