PrismaLibSql constructor takes a Config object (with url), not a pre-created Client instance. Remove the unnecessary createClient call and the @libsql/client direct dependency. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
969 B
TypeScript
31 lines
969 B
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import { PrismaLibSql } from '@prisma/adapter-libsql'
|
|
|
|
const globalForPrisma = globalThis as unknown as {
|
|
prisma: PrismaClient | undefined
|
|
}
|
|
|
|
function getPrismaClient(): PrismaClient {
|
|
if (!globalForPrisma.prisma) {
|
|
const adapter = new PrismaLibSql({
|
|
url: process.env.DATABASE_URL ?? 'file:./dev.db',
|
|
})
|
|
globalForPrisma.prisma = new PrismaClient({
|
|
adapter,
|
|
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
|
|
})
|
|
}
|
|
return globalForPrisma.prisma
|
|
}
|
|
|
|
// Use a Proxy so `new PrismaClient()` is only called when a property
|
|
// is first accessed (inside a request handler), NOT at module import time.
|
|
export const prisma = new Proxy({} as PrismaClient, {
|
|
get(_target, prop) {
|
|
return Reflect.get(getPrismaClient(), prop)
|
|
},
|
|
apply(_target, thisArg, args) {
|
|
return Reflect.apply(getPrismaClient() as unknown as Function, thisArg, args)
|
|
},
|
|
})
|