add settings table to store names (and other things soon)

This commit is contained in:
2023-03-18 19:56:57 -06:00
parent 315cdc0cf1
commit afc175e3e7
4 changed files with 77 additions and 35 deletions

View File

@@ -1,6 +1,12 @@
import BaseDexie, { Table } from "dexie";
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
import { Account, accountsSchema } from "./tables/accounts";
import {
Account,
AccountsSchema,
MASTER_SETTINGS,
Settings,
SettingsSchema,
} from "./tables";
/**
* In order to make the next line be acceptable, the program needs to have its linter suppress a rule:
@@ -12,10 +18,13 @@ import { Account, accountsSchema } from "./tables/accounts";
*/
type DexieTables = {
accounts: Table<Account>;
settings: Table<Settings>;
};
export type Dexie<T extends unknown = DexieTables> = BaseDexie & T;
export const db = new BaseDexie("KickStart") as Dexie;
const schema = Object.assign({}, accountsSchema);
const AllSchemas = Object.assign({}, AccountsSchema, SettingsSchema);
/**
* Needed to enable a special webpack setting to allow *await* below:
@@ -29,6 +38,12 @@ const secret =
if (localStorage.getItem("secret") == null) {
localStorage.setItem("secret", secret);
}
console.log(secret);
console.log("Secret:", secret);
encrypted(db, { secretKey: secret });
db.version(1).stores(schema);
db.version(1).stores(AllSchemas);
// initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event
db.on("populate", function () {
// ensure there's an initial entry for settings
db.settings.add({ id: MASTER_SETTINGS });
});