PrismaClient Constructor
ThePrismaClient constructor initializes a new Prisma Client instance with the specified configuration options.
Constructor Signature
PrismaClientOptions
The constructor accepts aPrismaClientOptions object with the following properties:
Instance of a Driver Adapter for connecting to your database.Example:Available adapters:
@prisma/adapter-pg- PostgreSQL@prisma/adapter-neon- Neon serverless@prisma/adapter-planetscale- PlanetScale@prisma/adapter-libsql- Turso/libSQL@prisma/adapter-d1- Cloudflare D1@prisma/adapter-better-sqlite3- Better SQLite3@prisma/adapter-mssql- SQL Server@prisma/adapter-mariadb- MariaDB
The
adapter and accelerateUrl options are mutually exclusive. You must provide one or the other.Prisma Accelerate URL for connecting through Accelerate instead of a direct database connection.Example:
The
adapter and accelerateUrl options are mutually exclusive.Configures the formatting of error messages returned by Prisma Client.
pretty- Colorized error messages with code frames (not recommended for production)colorless- Plain text error messages with code framesminimal- Minimal error messages without code frames (recommended for production)
- In production (
NODE_ENV=production):'minimal' - When
NO_COLORis set:'colorless' - Otherwise:
'colorless'
Configures logging for Prisma Client operations.Log levels: Event-based logging:LogDefinition type:
'query', 'info', 'warn', 'error'Simple logging (to stdout):Default configuration for interactive transactions.Example:
maxWait- Maximum time (in ms) to wait for a transaction to starttimeout- Maximum time (in ms) for the transaction to runisolationLevel- Transaction isolation level (database-dependent)
Globally omit specific fields from all query results.Example:
SQL commenter plugins that add metadata to SQL queries as comments following the sqlcommenter format.Example:Available plugins:
@prisma/sqlcommenter-trace-context- Adds W3C Trace Context@prisma/sqlcommenter-query-insights- Adds query shape information@prisma/sqlcommenter-query-tags- Adds custom query tags
Instance Methods
After instantiation, the PrismaClient instance provides these core methods:$connect()
Manually establishes a connection to the database.Prisma Client automatically connects on the first query, so calling
$connect() is optional.$disconnect()
Closes the database connection and cleans up resources.$on()
Registers an event listener for log events or thebeforeExit event.