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
- Rust Side
- TypeScript Side
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
TheDriverAdaptersManager interface standardizes driver setup:
libs/driver-adapters/executor/src/driver-adapters-manager/index.ts
Example: PostgreSQL Adapter
Here’s how thepg adapter is implemented:
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: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.Makefile:
Testing with Driver Adapters
The connector test kit can run against any driver adapter:- PostgreSQL + pg
- SQLite + libsql
- MySQL + PlanetScale
- SQL Server
- Starts PostgreSQL via Docker
- Builds query-compiler-wasm
- Builds driver adapters kit
- Sets up test config for pg adapter
Connection Info Types
The WASM compiler needs to know the provider without having a real connection: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:- Query Strategy
- Join Strategy
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:- Sets up a PostgreSQL instance via Docker
- Runs JavaScript benchmarks comparing adapter performance
Next Steps
Query Planning
Learn how queries are planned and optimized
WASM Build
Build the WebAssembly module