Registry / database / %40prisma/client

%40prisma/client

JSON →
library5.12.1jsnpmunverified

Prisma Client is an auto-generated, highly type-safe query builder for Node.js and TypeScript that makes database access intuitive and secure. Currently at version 5.12.1, it supports PostgreSQL, MySQL, SQLite, SQL Server, MongoDB, and CockroachDB. Unlike traditional ORMs that rely on complex classes and decorators, Prisma generates a customized client based on your explicit data model defined in a `schema.prisma` file. It features an active release cycle, excellent developer experience, and seamless integration with modern frameworks like Next.js. Choose Prisma when you want absolute, end-to-end type safety from your database to your frontend and prefer a declarative schema approach over programmatic migrations.

npm install @prisma/client
INSTALL
IMPORT
SIG · @PRISMA/CLIENT
C
@prisma/client
databasejavascriptv5.12.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PrismaClient
import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient();
import PrismaClient from '@prisma/client'; // Incorrect default export import { PrismaClient } from 'prisma'; // 'prisma' is the CLI package, not the client
The client must be instantiated from the `@prisma/client` package. In serverless environments (like Next.js development), it's highly recommended to instantiate this as a global singleton to prevent connection pooling exhaustion.
Edge Client
import { PrismaClient } from '@prisma/client/edge'; import { withAccelerate } from '@prisma/extension-accelerate';
import { PrismaClient } from '@prisma/client';
When deploying to Edge runtimes (Cloudflare Workers, Vercel Edge), you cannot use the standard client because it relies on a Rust binary. You must import from the `/edge` subpath and use a connection pooler like Prisma Accelerate.

A basic workflow demonstrating how to initialize the client, perform a write operation, and execute a relational read operation, ensuring the client disconnects properly upon completion.

import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); async function main() { // 1. Create a new user record const newUser = await prisma.user.create({ data: { name: 'Alice', email: 'alice@example.com', }, }); console.log('Created user:', newUser); // 2. Query the database with relation mapping const users = await prisma.user.findMany({ include: { posts: true }, }); console.log('All users with posts:', users); } main() .catch((e) => console.error(e)) .finally(async () => await prisma.$disconnect());
Debug
Known issues
gotchaIn development environments with Hot Module Replacement (like Next.js), calling `new PrismaClient()` in an API route creates a new database connection every time the file is saved. This quickly exhausts the database's connection pool, causing the app to crash.
fix
Implement a global singleton pattern for the Prisma Client instance. Assign the instantiated client to `globalThis.prisma` and reuse it if it already exists.
affects: All
breakingPrisma generates the client code dynamically into `node_modules/.prisma/client`. If your CI/CD pipeline caches the `node_modules` folder but does not run `prisma generate` after restoring the cache, the client will be missing or out of sync with your schema.
fix
Always add `npx prisma generate` as a build step in your CI/CD pipeline, or ensure it is part of your package.json `postinstall` script.
affects: All
gotchaWhen using Supabase or other pgBouncer-enabled PostgreSQL databases, Prisma's standard connection method may fail or hang due to prepared statement limitations in transaction mode.
fix
Append `?pgbouncer=true&connection_limit=1` to your `DATABASE_URL` and specify a `DIRECT_URL` environment variable for running migrations.
affects: All
Errors
Common errors & fixes
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
The `@prisma/client` package is essentially an empty shell until `prisma generate` parses your `schema.prisma` file and generates the actual TypeScript types and runtime code into the `node_modules` folder.
fix
Run `npx prisma generate` in your terminal. Ensure your database schema is properly defined before running this command.
PrismaClientKnownRequestError: Unique constraint failed on the fields: (`email`) [P2002]
You attempted to `create` or `update` a record with a value that already exists in the database for a column marked with the `@unique` attribute in your Prisma schema.
fix
Catch the error and handle it gracefully (e.g., return a 'User already exists' message to the client). Check `if (error.code === 'P2002')` within your catch block.
PrismaClientInitializationError: Can't reach database server at `localhost`:`5432`
Prisma cannot establish a connection to your database. This is usually due to an incorrect `DATABASE_URL` environment variable, a typo in the port/credentials, or the database service (like Docker) not running.
fix
Verify that your database container or service is active. Double-check your `.env` file to ensure the `DATABASE_URL` exactly matches your database's connection string format.
Upgrade
Version history
5.12.1latest on npm
Audit
Dependencies
required
Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources
%40prisma/client — npm install %40prisma/client · libregistry