Skip to content

PostgreSQL - instantiation of Prisma Client #7464

@radek2s

Description

@radek2s

Following overview to initialize Prisma ORM with PostgreSQL there is a confusing part where instantiation of Prisma client example leads to problematic and mysterious issues even if adapter has valid connection string:

ERROR: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string

Solution

After session of debugging I've found the solution that PrismaPg expects not connection string but pg.Pool or pg.PoolConfig. Without providing this pool instance PrismaPg tries to create an node-postgres instance with blank configuration. So we can improve Prisma documentation with following statement:

import "dotenv/config";
import { Pool } from "pg";  // <-- Import Pool from pg dependency
import { PrismaPg } from '@prisma/adapter-pg'
import { PrismaClient } from '../generated/prisma/client'

const connectionString = `${process.env.DATABASE_URL}`;
const adapter = new PrismaPg(new Pool({connectionString})); // <- Use Pool with connection string
const prisma = new PrismaClient({ adapter });

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions