import type { IndexableType } from "dexie"; import { AppTable } from "@/constants/table"; import { Field } from "@/constants/model"; import { dexieWrapper } from "@/services/DexieWrapper"; import type { IDBAccount } from "@/models/Account"; export default function useDBAccounts() { /** * Gets all data from the Logs table. * @returns IDBAccount[] */ async function getAccountsTable(): Promise { return await dexieWrapper.table(AppTable.ACCOUNTS).toArray(); } /** * Adds an Account to the database. * @param name * @param description * @param identity * @returns Id of new Account */ async function addAccount( name: string, description: string, identity: string ): Promise { const account: IDBAccount = { [Field.CREATED_TIMESTAMP]: new Date().getTime(), [Field.NAME]: name, [Field.DESCRIPTION]: description, [Field.IDENTITY]: identity, }; return await dexieWrapper.table(AppTable.ACCOUNTS).add(account); } return { getAccountsTable, addAccount, }; }