---
title: "Prisma driver-adapter implementation: review, setup & limitations · Undominated.ai"
canonical: https://undominated.ai/skills/prisma-prisma-driver-adapter-implementation/
description: "A Prisma ORM 7 driver-adapter contract: one connection per transaction, cleanup hooks that do not issue a second commit, and original database errors kept intact."
---

# Prisma driver-adapter implementation: review, setup & limitations · Undominated.ai

> A Prisma ORM 7 driver-adapter contract: one connection per transaction, cleanup hooks that do not issue a second commit, and original database errors kept intact.

[← Explore all skills](/skills/)

DATABASE ADAPTERS / Prisma

# Prisma driver-adapter implementation

A Prisma ORM 7 driver-adapter contract: one connection per transaction, cleanup hooks that do not issue a second commit, and original database errors kept intact.

 [See setup guidance ↓](#setup)[Original source ↗](https://github.com/prisma/skills/tree/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation)

SOURCE REVIEW

 Reviewed 2026-10-15
 Evidence 3 linked sources
 Publisher Prisma
 Licence [MIT ↗](https://github.com/prisma/skills/blob/be16a8740d01363d13552b317042431ee8dfc581/LICENSE)
 Revision be16a8740d01
 [Read what was—and wasn’t—checked ↓](#review)

“Required 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.”

 [Prisma · upstream description ↗](https://github.com/prisma/skills/blob/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation/SKILL.md) Our analysis follows below.

01 / THE REASONING

## Why this made the selection.

 - It specifies the Prisma 7 SQL adapter contract, including one dedicated connection per transaction and commit hooks that must not send a second COMMIT.
- Shadow databases must be isolated from the primary, and dispose must not close a pool the caller owns.

### A good fit for

 - Implementing or changing a Prisma ORM 7 SQL driver adapter
- Debugging transaction leaks, P2039 mapping, or a shadow database pointed at the primary
- Implement a Prisma adapter without leaking transaction connections or corrupting typed results.

### Weigh up before choosing

 - The skill is a protocol guide; it does not ship a working adapter or run Prisma.
- commit and rollback must not issue SQL, because Prisma already sends COMMIT and ROLLBACK through executeRaw.
- Unit tests alone are not the verification bar; the checklist also asks for Client integration tests.
- This review did not execute the resource.
- Compile-time compatibility cannot prove driver protocol semantics. The installed adapter-utils version, database savepoint behavior and caller-owned pool lifetime must be verified.
- Migration script execution must use the driver facility or a SQL parser; splitting on semicolons breaks functions, triggers, quoted strings and dialect-specific blocks.

02 / THE REVIEW RECORD

## What we actually inspected.

Source review has boundaries. A clear record is more useful than a “safe” badge.

### Material inspected

 - prisma-driver-adapter-implementation/SKILL.md
- README.md
- LICENSE

### Our findings

 - SqlDriverAdapter requires queryRaw, executeRaw, executeScript, startTransaction, and dispose, with savepoints on the Transaction object.
- The network and connection boundary is the driver's own pool: one connection per transaction, and dispose closes only pools the adapter created.
- commit and rollback are lifecycle hooks and must not issue a second SQL commit or rollback.
- The shadow adapter must never point at the primary database.
- The contract treats commit/rollback methods as lifecycle cleanup hooks because Prisma issues the SQL transaction commands through executeRaw, preventing duplicate commit/rollback.

### Not established by this review

 - The resource was not executed and its tools were not called.
- Not executed: it was not installed or run.

The review applies to the material and revision named here. A newer upstream release can change its behavior.

03 / PUT IT TO WORK

## Add a skill to your workflow.

[Upstream setup instructions ↗](https://github.com/vercel-labs/skills/blob/48dc9e8eb8aa19040e91cb90ba0b642c9cbad57e/README.md)

DOCUMENTED COMMAND

 npx skills add prisma/skills/prisma-driver-adapter-implementation Copy command ↗

Run in your terminal to choose your AI tools, project or global scope, and installation method. This short command follows the current upstream version; the review covers the revision shown above.

 Optional: install the reviewed revision

Keeps the original source and installer version where recorded, while leaving your AI tools and installation scope for you to choose.

 npx skills add https://github.com/prisma/skills/tree/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation Copy reviewed-revision command ↗ - The command pins one directory at the reviewed commit. The installer was not executed.
- Do not point the installer at the repository root. That would install other Prisma skills this review did not select.
- The publisher README lists npx skills add prisma/skills --skill prisma-driver-adapter-implementation, which does not pin revision be16a8740d01363d13552b317042431ee8dfc581.
- For manual installation instead, download the complete bundle from https://undominated.ai/resources/skills/prisma-prisma-driver-adapter-implementation/bundle.zip and extract it into a new directory. It holds SKILL.md unchanged at revision be16a874, the upstream licence and an attribution file.
- Place the extracted directory in your host's documented skills directory, named prisma-driver-adapter-implementation. Keep SKILL.md and the licence together.

### Before you start

 - The Prisma release whose @prisma/driver-adapter-utils the adapter must typecheck against

### Compatibility

Hosts that can read a SKILL.md file

### Implementation

Markdown

### Instruction file. It describes adapter methods, including script execution and a shadow database.

 - Read the skill file
- The file tells an implementer to execute SQL and to create an isolated shadow database. This review did not do that.
- Executes SQL and migrations, opens connections and may create shadow databases; dispose only adapter-owned resources.

### Cost model

MIT instructions at no charge. Copyright (c) 2025 Prisma.

THE COMPLETE REVIEWED DEFINITION

## Read it before you reuse it.

Original source bytes, with attribution. Review the host-specific setup notes above.

 Copy definition ↗ [Download definition + licence ↗](/resources/skills/prisma-prisma-driver-adapter-implementation/bundle.zip)[Raw Markdown ↗](/resources/skills/prisma-prisma-driver-adapter-implementation/definition.md)
 ---
name: prisma-driver-adapter-implementation
description: Required 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.
license: MIT
metadata:
 author: prisma
 version: "7.9.1"
---

# Prisma SQL Driver Adapter Implementation

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.

## When to Apply

- Implementing `SqlDriverAdapterFactory`, `SqlMigrationAwareDriverAdapterFactory`, `SqlDriverAdapter`, or `Transaction`
- Adding nested-transaction/savepoint support
- Mapping driver values, column metadata, bind arguments, or database errors
- Debugging `P2039`, transaction leaks, shadow-database failures, or adapter-specific query behavior

## Contract snapshot

```typescript
interface SqlDriverAdapterFactory extends AdapterInfo {
 connect(): Promise<SqlDriverAdapter>
}

interface SqlMigrationAwareDriverAdapterFactory extends SqlDriverAdapterFactory {
 connectToShadowDb(): Promise<SqlDriverAdapter>
}

interface SqlDriverAdapter extends AdapterInfo {
 queryRaw(query: SqlQuery): Promise<SqlResultSet>
 executeRaw(query: SqlQuery): Promise<number>
 executeScript(script: string): Promise<void>
 startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>
 getConnectionInfo?(): ConnectionInfo
 dispose(): Promise<void>
}

interface Transaction extends AdapterInfo {
 readonly options: { usePhantomQuery: boolean }
 queryRaw(query: SqlQuery): Promise<SqlResultSet>
 executeRaw(query: SqlQuery): Promise<number>
 commit(): Promise<void>
 rollback(): Promise<void>
 createSavepoint?(name: string): Promise<void>
 rollbackToSavepoint?(name: string): Promise<void>
 releaseSavepoint?(name: string): Promise<void>
}
```

`IsolationLevel` currently includes `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, `SNAPSHOT`, and `SERIALIZABLE`; validate what the concrete database supports.

## Priority rules

| 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 |

## Query implementation

`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.

```typescript
class ExampleQueryable {
 readonly provider = 'postgres' as const
 readonly adapterName = '@acme/adapter-example'

 constructor(protected readonly connection: DriverConnection) {}

 async queryRaw(query: SqlQuery): Promise<SqlResultSet> {
 try {
 const result = await this.connection.query({
 text: query.sql,
 values: query.args.map((value, index) =>
 mapArg(value, query.argTypes[index]),
 ),
 rowMode: 'array',
 })

 return {
 columnNames: result.fields.map((field) => field.name),
 columnTypes: result.fields.map(mapColumnType),
 rows: result.rows,
 }
 } catch (error) {
 throwAdapterError(error)
 }
 }

 async executeRaw(query: SqlQuery): Promise<number> {
 try {
 const result = await this.connection.execute(
 query.sql,
 query.args.map((value, index) => mapArg(value, query.argTypes[index])),
 )
 return result.rowsAffected ?? 0
 } catch (error) {
 throwAdapterError(error)
 }
 }
}
```

### Result mapping

Return `columnNames`, `columnTypes`, and `rows` with identical lengths/order. Map driver metadata to `ColumnTypeEnum` deliberately:

- signed integer widths to `Int32`/`Int64`; preserve 64-bit values without JS number truncation
- decimal/numeric to `Numeric` using the representation expected by Prisma
- binary to `Uint8Array`/`Bytes`
- date-only, time-only, and timestamp to `Date`, `Time`, and `DateTime`
- UUID, JSON, enum, arrays, and provider-specific unknown values to their explicit types
- unsupported native types to `DriverAdapterError({ kind: 'UnsupportedNativeDataType', type })`

Test `null`, empty arrays, array element types, big integers, decimals, byte arrays, JSON, dates, and user-defined/unknown native types.

### Script execution

`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.

## Transaction protocol

`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.

```typescript
async startTransaction(level?: IsolationLevel): Promise<Transaction> {
 const connection = await this.pool.acquire()
 try {
 const tx = new ExampleTransaction(connection, () => connection.release())
 await tx.executeRaw({ sql: 'BEGIN', args: [], argTypes: [] })
 if (level) {
 await tx.executeRaw({
 sql: `SET TRANSACTION ISOLATION LEVEL ${validateLevel(level)}`,
 args: [],
 argTypes: [],
 })
 }
 return tx
 } catch (error) {
 connection.release(error)
 throwAdapterError(error)
 }
}
```

### Commit and rollback

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.

```typescript
class ExampleTransaction extends ExampleQueryable implements Transaction {
 readonly options = { usePhantomQuery: false }
 #closed = false

 constructor(connection: DriverConnection, private readonly release: () => void) {
 super(connection)
 }

 async commit() { this.finish() }
 async rollback() { this.finish() }

 private finish() {
 if (this.#closed) return
 this.#closed = true
 this.release()
 }

 async createSavepoint(name: string) {
 await this.control(`SAVEPOINT ${safeSavepoint(name)}`)
 }

 async rollbackToSavepoint(name: string) {
 await this.control(`ROLLBACK TO SAVEPOINT ${safeSavepoint(name)}`)
 }

 async releaseSavepoint(name: string) {
 await this.control(`RELEASE SAVEPOINT ${safeSavepoint(name)}`)
 }

 private async control(sql: string) {
 await this.executeRaw({ sql, args: [], argTypes: [] })
 }
}
```

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.

## Error mapping

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:

```typescript
import {
 DriverAdapterError,
 type Error as DriverAdapterErrorObject,
 type MappedError,
} from '@prisma/driver-adapter-utils'

function convertDriverError(error: DatabaseError): DriverAdapterErrorObject {
 return {
 originalCode: String(error.code),
 originalMessage: error.message,
 ...mapKnownOrRaw(error),
 }
}

function mapKnownOrRaw(error: DatabaseError): MappedError {
 if (error.code === '23505') {
 return { kind: 'UniqueConstraintViolation', constraint: parsedConstraint(error) }
 }
 return {
 kind: 'postgres',
 code: String(error.code ?? 'N/A'),
 severity: error.severity ?? 'N/A',
 message: error.message,
 detail: error.detail,
 column: error.column,
 hint: error.hint,
 }
}

function throwAdapterError(error: unknown): never {
 if (!isDatabaseError(error)) throw error
 throw new DriverAdapterError(convertDriverError(error))
}
```

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.

## Factory, ownership, and shadow database

- `connect()` returns a fresh usable adapter connection/pool wrapper.
- Track whether the factory created the pool. `dispose()` closes owned pools and only detaches listeners from caller-owned pools unless an explicit option transfers ownership.
- Implement `SqlMigrationAwareDriverAdapterFactory` only when `connectToShadowDb()` can create an isolated shadow database, connect to it, and drop it during disposal/failure cleanup.
- Never point the shadow adapter at the primary database. Quote generated identifiers and use cryptographically unique names.
- `getConnectionInfo()` should accurately report `schemaName`, `maxBindValues` when applicable, and `supportsRelationJoins`.

## Verification checklist

- [ ] Typecheck against the exact target `@prisma/driver-adapter-utils` version
- [ ] `queryRaw` preserves column order, types, nulls, and precision
- [ ] `executeRaw` reports affected rows correctly
- [ ] `executeScript` handles provider-specific multi-statement syntax
- [ ] Concurrent interactive transactions use distinct dedicated connections
- [ ] Success commits and releases once; failure rolls back and releases once
- [ ] Nested transaction tests exercise create/rollback/release savepoint hooks
- [ ] Unsupported isolation levels fail as `InvalidIsolationLevel`
- [ ] Known constraints map to structured errors
- [ ] Unmapped database errors retain original code/message and surface useful `P2039`
- [ ] Dispose ownership is tested for internal and external pools
- [ ] Shadow database creation, use, failure cleanup, and disposal are isolated
- [ ] Run Prisma Client integration/E2E tests, not only adapter unit tests

## Source references

- [Driver adapter interfaces](https://github.com/prisma/prisma/blob/v7/packages/driver-adapter-utils/src/types.ts)
- [PostgreSQL adapter transaction implementation](https://github.com/prisma/prisma/blob/v7/packages/adapter-pg/src/pg.ts)
- [PostgreSQL adapter error mapping](https://github.com/prisma/prisma/blob/v7/packages/adapter-pg/src/errors.ts)

The download contains SKILL.md . Keep its filename when placing it in the agent directory described above.

By **Prisma**. [Exact upstream source ↗](https://github.com/prisma/skills/blob/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation/SKILL.md) · [Licence](/resources/skills/prisma-prisma-driver-adapter-implementation/LICENSE.txt) · [Attribution](/resources/skills/prisma-prisma-driver-adapter-implementation/ATTRIBUTION.txt)

SHA-256 cb8f4127acb259a1827140ee6201ed46f872021254902a86d5fadcd6d2b8a409

 Read the applicable licence MIT License

Copyright (c) 2025 Prisma

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

04 / FOLLOW THE EVIDENCE

## The source trail.

Our notes are separate from the original resource. Check upstream before adopting a new version.

 - [Driver-adapter skill ↗](https://github.com/prisma/skills/blob/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation/SKILL.md) Checked 2026-10-14 https://github.com/prisma/skills/blob/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation/SKILL.md Supports: summary, whySelected, limitations
- [MIT licence ↗](https://github.com/prisma/skills/blob/be16a8740d01363d13552b317042431ee8dfc581/LICENSE) Checked 2026-10-14 https://github.com/prisma/skills/blob/be16a8740d01363d13552b317042431ee8dfc581/LICENSE Supports: Redistribution terms, Copyright (c) 2025 Prisma
- [Pinned source review C2-W34 ↗](https://raw.githubusercontent.com/prisma/skills/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation/SKILL.md) Checked 2026-10-15 https://raw.githubusercontent.com/prisma/skills/be16a8740d01363d13552b317042431ee8dfc581/prisma-driver-adapter-implementation/SKILL.md Supports: limitations, review.notTested, review.reviewedAt

KEEP COMPARING

## Other approaches to consider.

Related by category or shared topics. These are alternatives to inspect, not a measured quality order.

 [### Prisma Client API ↗ Covers Prisma Client model queries, relation filtering, interactive transactions, and batching semantics.](/skills/prisma-client-api/)[### CockroachDB SQL ↗ Cockroach Labs skill that turns a natural-language request into CockroachDB SQL, applies the relevant rule files with 00-fundamental-principles.md first, and tells the agent to run EXPLAIN on every generated query when a cluster connection is available.](/skills/cockroachlabs-cockroachdb-sql/)[### dbt Documentation Maintenance ↗ Audits descriptions in a dbt manifest and drafts missing model or column documentation in the project’s existing style.](/skills/dbt-labs-maintaining-dbt-documentation/)

 [AI Tools ↗](/tools/)[Skills ↗](/skills/)[Agents ↗](/agents/)[MCP Servers ↗](/mcp-servers/)[Workflows ↗](/workflows/)

## Continue your investigation

 - [Choose a toolkit](/tools/)
- [Inspect execution hosts](/agents/)
- [Check tool access](/mcp-servers/)
- [Check project dependencies](/check-repo/)
