refactor DB organization (prepping for more tables)
This commit is contained in:
@@ -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);
|
||||
|
||||
/**
|
||||
|
||||
@@ -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",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user