Kaizen
Browse modulesPersistenceFunctions

Function: createPrismaClient()

function createPrismaClient<TClientCtor extends PrismaClientCtor>(PrismaClientClass: TClientCtor, options: CreatePrismaClientOptions): InstanceType<TClientCtor>;

Defined in: server/persistence/create-prisma-client.ts:85

Wire up a Prisma 7 client against Postgres with the adapter boilerplate hidden. The consumer passes their generated PrismaClient class and a connection spec; we construct the PrismaPg adapter and instantiate the client.

Prisma 7 removed datasource.url from schema.prisma, so every consumer otherwise has to juggle the adapter themselves. This helper is the out-of-the-box path.

Type Parameters

Type Parameter
TClientCtor extends PrismaClientCtor

Parameters

ParameterType
PrismaClientClassTClientCtor
optionsCreatePrismaClientOptions

Returns

InstanceType<TClientCtor>

Example

import { PrismaClient } from "@prisma/client";
import { createPrismaClient } from "@the-kaizen-labs/taproot/persistence";

export const prisma = createPrismaClient(PrismaClient, {
  connection: process.env.DATABASE_URL!,
});

// With a schema override (e.g. for taproot-owned tables):
export const prisma = createPrismaClient(PrismaClient, {
  connection: process.env.DATABASE_URL!,
  adapter: { schema: "taproot" },
  client: { log: ["warn", "error"] },
});

On this page