This commit is contained in:
+12
-11
@@ -1,17 +1,18 @@
|
||||
import { createClient } from '@libsql/client'
|
||||
import { drizzle } from 'drizzle-orm/libsql'
|
||||
import * as schema from './schema'
|
||||
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
|
||||
let instance: ReturnType<typeof drizzle<typeof schema>> | undefined;
|
||||
|
||||
export function useDb() {
|
||||
export function useDb(event: H3Event) {
|
||||
if (!instance) {
|
||||
const config = useRuntimeConfig()
|
||||
const config = useRuntimeConfig(event);
|
||||
const client = createClient({
|
||||
url: config.databaseUrl,
|
||||
authToken: config.databaseAuthToken || undefined,
|
||||
})
|
||||
instance = drizzle(client, { schema })
|
||||
url: config.database.url,
|
||||
authToken: config.database.authToken || undefined,
|
||||
});
|
||||
instance = drizzle(client, { schema });
|
||||
}
|
||||
return instance
|
||||
return instance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user