Driver Adapters Overview
Prisma ORM’s driver adapter system allows you to use JavaScript database drivers instead of native binaries. This enables Prisma to work in environments where native binaries are not supported, such as serverless platforms and edge runtimes.What are Driver Adapters?
Driver adapters are JavaScript packages that allow Prisma Client to communicate with databases using popular JavaScript drivers. Instead of using native database drivers, Prisma Client can leverage JavaScript drivers likepg, better-sqlite3, or serverless-optimized drivers like Neon’s serverless driver.
Benefits
- Edge Runtime Support: Deploy Prisma Client to edge runtimes like Cloudflare Workers
- Serverless Optimization: Use HTTP-based database connections optimized for serverless environments
- Flexibility: Choose from multiple driver options for the same database
- No Native Dependencies: Pure JavaScript drivers work in environments where native binaries are restricted
Available Adapters
Prisma provides official driver adapters for multiple databases:PostgreSQL
@prisma/adapter-pg- Node.js PostgreSQL driver@prisma/adapter-neon- Neon serverless driver (HTTP/WebSocket)@prisma/adapter-ppg- Prisma Postgres serverless driver
MySQL/MariaDB
@prisma/adapter-mariadb- MariaDB/MySQL connector@prisma/adapter-planetscale- PlanetScale serverless driver (HTTP)
SQLite
@prisma/adapter-better-sqlite3- Fast synchronous SQLite driver@prisma/adapter-libsql- libSQL and Turso driver@prisma/adapter-d1- Cloudflare D1 driver
SQL Server
@prisma/adapter-mssql- Microsoft SQL Server driver
How Driver Adapters Work
Driver adapters implement theSqlDriverAdapter interface from @prisma/driver-adapter-utils. This interface defines methods for:
- Executing raw SQL queries (
queryRaw,executeRaw) - Managing transactions (
startTransaction, commit, rollback) - Handling savepoints for nested transactions
- Disposing connections
Architecture
The driver adapter system consists of:- Adapter Packages (
@prisma/adapter-*): Implement driver-specific logic - Adapter Utils (
@prisma/driver-adapter-utils): Shared types and interfaces - Client Engine: Orchestrates query execution using the adapter
- Query Interpreter: Executes query plans against the
SqlQueryableinterface
Error Handling
Each adapter maps database-specific errors to Prisma’s unified error format. Errors are converted toMappedError types and then to Prisma Client error codes (P2xxx).
For example, a PostgreSQL unique constraint violation is mapped to:
- Kind:
UniqueConstraintViolation - Prisma Code:
P2002
Transaction Support
All adapters support:- Interactive Transactions: Begin, commit, rollback
- Isolation Levels:
READ UNCOMMITTED,READ COMMITTED,REPEATABLE READ,SERIALIZABLE,SNAPSHOT(SQL Server) - Savepoints: Nested transaction support using
createSavepoint,rollbackToSavepoint,releaseSavepoint
Connection Management
Adapters handle connection pooling differently:- Node.js adapters (pg, mariadb, mssql): Use connection pools
- Serverless adapters (Neon HTTP, PlanetScale): Use HTTP connections
- SQLite adapters: Direct file access or remote connections