Files
splitt-the-bill/server/database/client.ts
T
anbraten cbe1b42f6e
tinyedge/deploy Deployed by TinyEdge
🐛 add env to useDb and apply prettier
2026-08-07 13:28:26 +02:00

19 lines
538 B
TypeScript

import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import * as schema from './schema';
import type { H3Event } from 'h3';
let instance: ReturnType<typeof drizzle<typeof schema>> | undefined;
export function useDb(event: H3Event) {
if (!instance) {
const config = useRuntimeConfig(event);
const client = createClient({
url: config.database.url,
authToken: config.database.authToken || undefined,
});
instance = drizzle(client, { schema });
}
return instance;
}