Skip to main content
Driver adapters bridge the gap between Rust-compiled query plans and database-specific TypeScript drivers. They enable Prisma to run in any JavaScript environment with appropriate database connectivity.

Overview

The driver adapter system allows the Query Compiler to target different databases and environments:
  • PostgreSQL: pg, @neondatabase/serverless, @prisma/adapter-pg
  • MySQL: mysql2, @planetscale/database, @prisma/adapter-mysql
  • SQLite: better-sqlite3, @libsql/client, Cloudflare D1
  • SQL Server: tedious, @prisma/adapter-mssql

Architecture

The Rust side provides WASM bindings and connection info abstraction:
Connection info tells the compiler which SQL dialect to generate without requiring actual database access.

Driver Adapter Manager

The DriverAdaptersManager interface standardizes driver setup:
From libs/driver-adapters/executor/src/driver-adapters-manager/index.ts

Example: PostgreSQL Adapter

Here’s how the pg adapter is implemented:
From libs/driver-adapters/executor/src/driver-adapters-manager/pg.ts

Supported Adapters

PostgreSQL

  • @prisma/adapter-pg (node-postgres)
  • @prisma/adapter-neon (Neon serverless)
  • @prisma/adapter-pg-worker (Cloudflare Workers)

MySQL

  • @prisma/adapter-mysql (mysql2)
  • @prisma/adapter-planetscale (PlanetScale serverless)
  • @prisma/adapter-mariadb

SQLite

  • @prisma/adapter-better-sqlite3
  • @prisma/adapter-libsql (Turso)
  • @prisma/adapter-d1 (Cloudflare D1)

SQL Server

  • @prisma/adapter-mssql (tedious)

Building the Driver Adapters Kit

The driver adapters are built separately from the query compiler:
1

Ensure Prisma repository is available

The build process requires the main Prisma repository for adapter packages:
This clones prisma/prisma to ../prisma if not already present.
2

Install dependencies

Runs pnpm i in the driver adapters directory.
3

Build for Query Compiler

This runs pnpm build:qc which builds only the packages needed for query compiler tests.
From the Makefile:

Testing with Driver Adapters

The connector test kit can run against any driver adapter:
This:
  1. Starts PostgreSQL via Docker
  2. Builds query-compiler-wasm
  3. Builds driver adapters kit
  4. Sets up test config for pg adapter

Connection Info Types

The WASM compiler needs to know the provider without having a real connection:
In the WASM constructor:
From query-compiler-wasm/src/compiler.rs

Expression Execution Flow

When the TypeScript interpreter executes a plan:

Relation Join Strategies

Driver adapters support different relation loading strategies:
Load relations in separate queries (application-level joins):
Generates a Join expression in the plan.

Migration Script Support

Some adapters (like Cloudflare D1) support migration scripts:

Benchmarking

Benchmark driver adapter performance:
This:
  1. Sets up a PostgreSQL instance via Docker
  2. Runs JavaScript benchmarks comparing adapter performance

Next Steps

Query Planning

Learn how queries are planned and optimized

WASM Build

Build the WebAssembly module