import a complete database from cli
This commit is contained in:
parent
962bfde214
commit
f026a8d326
@ -2024,11 +2024,11 @@ export interface DatabaseDump {
|
||||
version: string;
|
||||
}
|
||||
|
||||
export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
|
||||
async function recoverFromDump(db: IDBDatabase, dump: DatabaseDump): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const tx = db.transaction(Array.from(db.objectStoreNames), "readwrite");
|
||||
tx.addEventListener("complete", () => {
|
||||
resolve(db);
|
||||
resolve();
|
||||
});
|
||||
for (let i = 0; i < db.objectStoreNames.length; i++) {
|
||||
const name = db.objectStoreNames[i];
|
||||
@ -2041,5 +2041,51 @@ export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
|
||||
});
|
||||
}
|
||||
tx.commit();
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export async function importDb(db: IDBDatabase, object: any): Promise<void> {
|
||||
if ("name" in object && "stores" in object && "version" in object) {
|
||||
// looks like a database dump
|
||||
const dump = object as DatabaseDump
|
||||
return recoverFromDump(db, dump);
|
||||
}
|
||||
|
||||
if ("databases" in object && "$types" in object) {
|
||||
// looks like a IDBDatabase
|
||||
const someDatabase = object.databases;
|
||||
|
||||
if (TALER_META_DB_NAME in someDatabase) {
|
||||
//looks like a taler database
|
||||
const currentMainDbValue = someDatabase[TALER_META_DB_NAME].objectStores.metaConfig.records[0].value.value
|
||||
|
||||
if (currentMainDbValue !== TALER_DB_NAME) {
|
||||
console.log("not the current database version")
|
||||
}
|
||||
|
||||
const talerDb = someDatabase[currentMainDbValue];
|
||||
|
||||
const objectStoreNames = Object.keys(talerDb.objectStores);
|
||||
|
||||
const dump: DatabaseDump = {
|
||||
name: talerDb.schema.databaseName,
|
||||
version: talerDb.schema.databaseVersion,
|
||||
stores: {},
|
||||
}
|
||||
|
||||
for (let i = 0; i < objectStoreNames.length; i++) {
|
||||
const name = objectStoreNames[i];
|
||||
const storeDump = {} as { [s: string]: any };
|
||||
dump.stores[name] = storeDump;
|
||||
talerDb.objectStores[name].records.map((r: any) => {
|
||||
const pkey = r.primaryKey
|
||||
const key = typeof pkey === "string" ? pkey : pkey.join(",")
|
||||
storeDump[key] = r.value;
|
||||
})
|
||||
}
|
||||
|
||||
return recoverFromDump(db, dump);
|
||||
}
|
||||
}
|
||||
throw Error("could not import database");
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import { useEffect, useState } from "preact/hooks";
|
||||
import { Loading } from "../components/Loading.js";
|
||||
import { LoadingError } from "../components/LoadingError.js";
|
||||
import {
|
||||
ButtonBoxPrimary,
|
||||
CenteredBoldText,
|
||||
CenteredText,
|
||||
DateSeparator,
|
||||
@ -37,6 +36,8 @@ import { useTranslationContext } from "../context/translation.js";
|
||||
import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
|
||||
import { Button } from "../mui/Button.js";
|
||||
import { NoBalanceHelp } from "../popup/NoBalanceHelp.js";
|
||||
import DownloadIcon from "../svg/download_24px.svg";
|
||||
import UploadIcon from "../svg/upload_24px.svg";
|
||||
import * as wxApi from "../wxApi.js";
|
||||
|
||||
interface Props {
|
||||
@ -96,8 +97,6 @@ const term = 1000 * 60 * 60 * 24;
|
||||
function normalizeToDay(x: number): number {
|
||||
return Math.round(x / term) * term;
|
||||
}
|
||||
import DownloadIcon from "../svg/download_24px.svg";
|
||||
import UploadIcon from "../svg/upload_24px.svg";
|
||||
|
||||
export function HistoryView({
|
||||
defaultCurrency,
|
||||
|
Loading…
Reference in New Issue
Block a user