You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
1.1 KiB

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<IDBAccount[]> {
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<IndexableType> {
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,
};
}