19 lines
539 B
TypeScript
19 lines
539 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;
|
|
}
|