9 skills · 29 min
Skills
Skill 5 of 9
Required reference for Prisma ORM 7 SQL driver adapter work.
3 minutes · 690 words · 13 sections
Install
npx skills add prisma/skills --skill prisma-driver-adapter-implementationnpx skills add prisma/skillsThe first command installs just this skill, by the name in its SKILL.md; the second installs the whole repository.
Use this guide with the exact @prisma/driver-adapter-utils version installed by the target Prisma release. Driver adapters are a protocol boundary: type-compatible code can still corrupt values, leak connections, or break transactions.
SqlDriverAdapterFactory, SqlMigrationAwareDriverAdapterFactory, SqlDriverAdapter, or TransactionP2039, transaction leaks, shadow-database failures, or adapter-specific query behaviorinterface SqlDriverAdapterFactory extends AdapterInfo {
connect(): Promise<SqlDriverAdapter>
}
interface SqlMigrationAwareDriverAdapterFactory extends SqlDriverAdapterFactory {
connectToShadowDb(): Promise<SqlDriverAdapter>
IsolationLevel currently includes READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SNAPSHOT, and SERIALIZABLE; validate what the concrete database supports.
| Priority | Rule | Impact |
|---|---|---|
| CRITICAL | One dedicated connection per transaction | Prevents interleaving and leaks |
| CRITICAL | commit/rollback are lifecycle cleanup hooks | Prevents duplicate COMMIT/ROLLBACK |
| CRITICAL | Savepoints live on Transaction, not adapter-global depth | Makes nested scopes connection-local |
| CRITICAL | Preserve original database error code/message | Enables useful P2039 fallback |
| HIGH | Map arguments and result metadata exactly | Prevents silent value corruption |
| HIGH | Shadow databases are isolated and always cleaned up | Makes Migrate safe |
| HIGH | Dispose only resources the adapter owns | Prevents shutting down caller-owned pools |
SqlQuery contains sql, args, and parallel argTypes. Map each argument using both value and ArgType; do not discard type/arity information. Execute in the driver’s array/tuple row mode so column order is stable.
class ExampleQueryable {
readonly provider = 'postgres' as const
readonly adapterName = '@acme/adapter-example'
constructor(protected readonly connection: DriverConnection) {}
async queryRaw(
Return columnNames, columnTypes, and rows with identical lengths/order. Map driver metadata to ColumnTypeEnum deliberately:
Int32/Int64; preserve 64-bit values without JS number truncationNumeric using the representation expected by PrismaUint8Array/BytesDate, Time, and DateTimeDriverAdapterError({ kind: 'UnsupportedNativeDataType', type })Test null, empty arrays, array element types, big integers, decimals, byte arrays, JSON, dates, and user-defined/unknown native types.
executeScript must execute a migration script as the provider expects. Prefer the driver’s native multi-statement/script facility or a real SQL parser. Naively splitting on ; breaks functions, triggers, quoted strings, and dialect-specific blocks.
startTransaction must acquire one dedicated connection, start the database transaction, apply the requested isolation level, and return a Transaction bound to that same connection. If setup fails, release it immediately.
async startTransaction(level?: IsolationLevel): Promise<Transaction> {
const connection = await this.pool.acquire()
try {
const tx = new ExampleTransaction(connection, () => connection.release())
await tx.executeRaw
Prisma coordinates the SQL COMMIT/ROLLBACK through executeRaw. The transaction object’s commit() and rollback() methods are lifecycle hooks: detach listeners and release the dedicated connection exactly once. They must not issue a second SQL commit/rollback.
class ExampleTransaction extends ExampleQueryable implements Transaction {
readonly options = { usePhantomQuery: false }
#closed = false
constructor(connection: DriverConnection, private readonly release: ()
Implement the optional savepoint methods only where the provider supports them. Validate/quote savepoint identifiers. For providers whose savepoints are intentionally no-ops, document and test that limitation.
Never keep transaction depth on the shared adapter. Parallel transactions make adapter-global depth incorrect; nested state belongs to the returned transaction connection and Prisma’s savepoint calls.
Wrap recognized driver failures in DriverAdapterError. Map known conditions to MappedError kinds such as constraint violations, authentication/reachability, missing table/column/database, timeouts, closed transactions, invalid input, value range, and write conflicts.
For database errors, preserve originalCode and originalMessage even when falling back to the provider-specific raw variant:
import {
DriverAdapterError,
type Error as DriverAdapterErrorObject,
type MappedError,
} from '@prisma/driver-adapter-utils'
function convertDriverError(error: DatabaseError): DriverAdapterErrorObject {
return {
Prisma uses preserved original details when an unmapped driver error becomes P2039. Do not replace every unknown exception with a fabricated GenericJs id; rethrow genuinely unexpected non-driver errors so programming bugs remain visible.
connect() returns a fresh usable adapter connection/pool wrapper.dispose() closes owned pools and only detaches listeners from caller-owned pools unless an explicit option transfers ownership.SqlMigrationAwareDriverAdapterFactory only when connectToShadowDb() can create an isolated shadow database, connect to it, and drop it during disposal/failure cleanup.getConnectionInfo() should accurately report schemaName, maxBindValues when applicable, and supportsRelationJoins.@prisma/driver-adapter-utils versionqueryRaw preserves column order, types, nulls, and precisionexecuteRaw reports affected rows correctlyexecuteScript handles provider-specific multi-statement syntaxInvalidIsolationLevelP2039Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.
The verbatim description from this skill’s front matter — the string an agent matches on to decide whether to load it.
prisma-driver-adapter-implementation/SKILL.mdmain, last pushed 24 September 2026.SKILL.md, not by matching a directory convention. One layout observed: */SKILL.md.h1 and no skipped levels:/prisma/skills.md, and each skill at its own .md URL.