mirror your GitHub repos to tangled.org automatically
1import { neon } from '@neondatabase/serverless'
2import { drizzle } from 'drizzle-orm/neon-http'
3import * as schema from '../db/schema'
4
5let _db: ReturnType<typeof drizzle<typeof schema>> | undefined
6
7export function useDb() {
8 if (_db) return _db
9 const { databaseUrl } = useRuntimeConfig()
10 if (!databaseUrl) {
11 throw new Error('NUXT_DATABASE_URL is not set')
12 }
13 const client = neon(databaseUrl)
14 _db = drizzle(client, { schema })
15 return _db
16}
17
18export { schema }