- health: pings DB via SELECT 1 and returns status/version/time - list_products: active products owned or shared with the auth user - get_claude_context: bundled product + active sprint + next story (with tasks, status mapped to lowercase) + 50 open todos prisma.ts switches to a lazy proxy so the server bootstrap doesn't crash before tools fire when DATABASE_URL is unset. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
22 lines
641 B
TypeScript
22 lines
641 B
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import { Pool } from 'pg'
|
|
import { PrismaPg } from '@prisma/adapter-pg'
|
|
|
|
let client: PrismaClient | null = null
|
|
|
|
function createClient(): PrismaClient {
|
|
const url = process.env.DATABASE_URL
|
|
if (!url) {
|
|
throw new Error('DATABASE_URL is not set — see .env.example')
|
|
}
|
|
const pool = new Pool({ connectionString: url })
|
|
const adapter = new PrismaPg(pool)
|
|
return new PrismaClient({ adapter, log: ['error'] })
|
|
}
|
|
|
|
export const prisma = new Proxy({} as PrismaClient, {
|
|
get(_target, prop) {
|
|
if (!client) client = createClient()
|
|
return Reflect.get(client, prop, client)
|
|
},
|
|
})
|