2024-11-19 17:24:08 -05:00
|
|
|
// db/queries.ts
|
2024-11-19 21:15:15 -05:00
|
|
|
import { accounts } from '../schema/Account'
|
2024-11-19 17:24:08 -05:00
|
|
|
import { db } from '../index';
|
|
|
|
|
|
|
|
|
|
// Fetch all accounts
|
|
|
|
|
export async function getAllAccounts() {
|
|
|
|
|
return await db.select().from(accounts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add a new accounts
|
|
|
|
|
export async function addAcounts(name: string) {
|
2024-11-19 21:15:15 -05:00
|
|
|
return await db.insertInto(accounts).values({ name }).returning();
|
2024-11-19 17:24:08 -05:00
|
|
|
}
|
|
|
|
|
|
2024-11-19 21:15:15 -05:00
|
|
|
// Update a accounts
|
|
|
|
|
export async function updateAcounts(id: number, name: string) {
|
|
|
|
|
return await db.update(accounts).set({ name }).where(accounts.id.equals(id));
|
2024-11-19 17:24:08 -05:00
|
|
|
}
|
|
|
|
|
|
2024-11-19 21:15:15 -05:00
|
|
|
// Delete a accounts
|
|
|
|
|
export async function deleteAccount(id: number) {
|
|
|
|
|
return await db.deleteFrom(accounts).where(accounts.id.equals(id));
|
2024-11-19 17:24:08 -05:00
|
|
|
}
|