docs: correcties CLAUDE.md en prisma-client patroon
- Next.js versie gecorrigeerd naar 16 in CLAUDE.md - prisma-client.md bijgewerkt met werkelijke adapter-implementatie (SQLite + PostgreSQL) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c764d69e52
commit
8e0513e07c
1 changed files with 26 additions and 3 deletions
|
|
@ -2,14 +2,37 @@
|
||||||
|
|
||||||
## lib/prisma.ts
|
## lib/prisma.ts
|
||||||
|
|
||||||
|
Detecteert automatisch SQLite (lokaal, `file:`) of PostgreSQL (Neon/Vercel).
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { PrismaClient } from '@prisma/client'
|
import { PrismaClient } from '@prisma/client'
|
||||||
|
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'
|
||||||
|
import { Pool } from 'pg'
|
||||||
|
import { PrismaPg } from '@prisma/adapter-pg'
|
||||||
|
|
||||||
|
function createPrismaClient() {
|
||||||
|
const url = process.env.DATABASE_URL
|
||||||
|
if (!url) throw new Error('DATABASE_URL is not set')
|
||||||
|
|
||||||
|
if (url.startsWith('file:')) {
|
||||||
|
const adapter = new PrismaBetterSqlite3({ url })
|
||||||
|
return new PrismaClient({
|
||||||
|
adapter,
|
||||||
|
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const pool = new Pool({ connectionString: url })
|
||||||
|
const adapter = new PrismaPg(pool)
|
||||||
|
return new PrismaClient({
|
||||||
|
adapter,
|
||||||
|
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined }
|
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined }
|
||||||
|
|
||||||
export const prisma = globalForPrisma.prisma ?? new PrismaClient({
|
export const prisma = globalForPrisma.prisma ?? createPrismaClient()
|
||||||
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
|
|
||||||
})
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue