Setting the file. One moment.
Skill 04 · Prisma Database Setup
Subchapter 4.4
references/postgresql.mdMarkdown2 KBView on GitHub
In prisma/schema.prisma:
datasource db {
provider = "postgresql"
}
generator client {
provider = "prisma-client"
output = "../generated"
}In prisma.config.ts:
import { defineConfig, env } from 'prisma/config'
export default defineConfig({
schema: 'prisma/schema.prisma',
datasource: {
url: env('DATABASE_URL'),
},
})In .env:
DATABASE_URL="postgresql://user:password@localhost:5432/mydb?schema=public"postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMApublic)Use a driver adapter for the standard SQL workflow.
Install adapter and driver:
npm install @prisma/adapter-pg pgInstantiate Prisma Client with the adapter:
import 'dotenv/config'
import { PrismaClient } from '../generated/client'
import { PrismaPg } from '@prisma/adapter-pg'
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
const prisma = new PrismaClient({ adapter })?schema=public (or your schema) is in the URL