@@ -5,7 +5,7 @@ import type { H3Event } from 'h3';
|
||||
|
||||
let instance: ReturnType<typeof drizzle<typeof schema>> | undefined;
|
||||
|
||||
export function useDb(event: H3Event) {
|
||||
export function useDb(event?: H3Event) {
|
||||
if (!instance) {
|
||||
const config = useRuntimeConfig(event);
|
||||
const client = createClient({
|
||||
|
||||
@@ -2,7 +2,7 @@ import { migrate } from 'drizzle-orm/libsql/migrator';
|
||||
import { useDb } from '../database/client';
|
||||
|
||||
export default defineNitroPlugin(async () => {
|
||||
await migrate(useDb(event), {
|
||||
await migrate(useDb(), {
|
||||
migrationsFolder: 'server/database/migrations',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ export interface ExpenseWithDetails {
|
||||
}
|
||||
|
||||
export async function getPotOrThrow(slug: string) {
|
||||
const db = useDb(event);
|
||||
const db = useDb();
|
||||
const [pot] = await db.select().from(pots).where(eq(pots.slug, slug));
|
||||
if (!pot) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Pot not found' });
|
||||
@@ -27,14 +27,14 @@ export async function getPotOrThrow(slug: string) {
|
||||
}
|
||||
|
||||
export async function getParticipants(slug: string) {
|
||||
const db = useDb(event);
|
||||
const db = useDb();
|
||||
return db.select().from(participants).where(eq(participants.potSlug, slug));
|
||||
}
|
||||
|
||||
export async function getExpensesWithParticipants(
|
||||
slug: string,
|
||||
): Promise<ExpenseWithDetails[]> {
|
||||
const db = useDb(event);
|
||||
const db = useDb();
|
||||
const expenseRows = await db
|
||||
.select()
|
||||
.from(expenses)
|
||||
|
||||
Reference in New Issue
Block a user