18 lines
474 B
TypeScript
18 lines
474 B
TypeScript
import { createClient } from '@libsql/client'
|
|
import { drizzle } from 'drizzle-orm/libsql'
|
|
import * as schema from './schema'
|
|
|
|
let instance: ReturnType<typeof drizzle<typeof schema>> | undefined
|
|
|
|
export function useDb() {
|
|
if (!instance) {
|
|
const config = useRuntimeConfig()
|
|
const client = createClient({
|
|
url: config.databaseUrl,
|
|
authToken: config.databaseAuthToken || undefined,
|
|
})
|
|
instance = drizzle(client, { schema })
|
|
}
|
|
return instance
|
|
}
|