refactor DB organization (prepping for more tables)

This commit is contained in:
2023-03-18 17:04:14 -06:00
parent 53204179a2
commit cfeabf05a4
6 changed files with 48 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
import BaseDexie from "dexie";
import BaseDexie, { Table } from "dexie";
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
import { accountsSchema, AccountsTable } from "./tables/accounts";
import { Account, accountsSchema } from "./tables/accounts";
/**
* In order to make the next line be acceptable, the program needs to have its linter suppress a rule:
@@ -10,9 +10,11 @@ import { accountsSchema, AccountsTable } from "./tables/accounts";
*
* https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any
*/
type DexieTables = AccountsTable;
type DexieTables = {
accounts: Table<Account>;
};
export type Dexie<T extends unknown = DexieTables> = BaseDexie & T;
export const db = new BaseDexie("kickStarter") as Dexie;
export const db = new BaseDexie("KickStart") as Dexie;
const schema = Object.assign({}, accountsSchema);
/**

View File

@@ -1,18 +1,15 @@
import { Table } from "dexie";
export type Account = {
id?: number;
publicKey: string;
mnemonic: string;
id?: number; // auto-generated by Dexie
dateCreated: Date;
derivationPath: string;
identity: string;
dateCreated: number;
};
export type AccountsTable = {
accounts: Table<Account>;
publicKeyHex: string;
mnemonic: string;
};
// mark encrypted field by starting with a $ character
// see https://github.com/PVermeer/dexie-addon-suite-monorepo/tree/master/packages/dexie-encrypted-addon
export const accountsSchema = {
accounts: "++id, publicKey, $mnemonic, $identity, dateCreated",
accounts:
"++id, dateCreated, derivationPath, $identity, $mnemonic, publicKeyHex",
};