Deploying edge functions with Prisma ORM
You can deploy an application that uses Prisma ORM to the edge. Depending on which edge function provider and which database you use, there are different considerations and things to be aware of.
Here is a brief overview of all the edge function providers that are currently supported by Prisma ORM:
Provider / Product | Supported natively with Prisma ORM | Supported with Prisma Accelerate |
---|---|---|
Vercel Edge Functions | ✅ (Preview; only compatible drivers) | ✅ |
Vercel Edge Middleware | ✅ (Preview; only compatible drivers) | ✅ |
Cloudflare Workers | ✅ (Preview; only compatible drivers) | ✅ |
Cloudflare Pages | ✅ (Preview; only compatible drivers) | ✅ |
Deno Deploy | Not yet | ✅ |
Deploying edge functions that use Prisma ORM on Cloudflare and Vercel is currently in Preview.
Edge-compatibility of database drivers
Why are there limitations around database drivers in edge functions?
Edge functions typically don't use the standard Node.js runtime. For example, Vercel Edge Functions and Cloudflare Workers are running code in V8 isolates. Deno Deploy is using the Deno JavaScript runtime. As a consequence, these edge functions only have access to a small subset of the standard Node.js APIs and also have constrained computing resources (CPU and memory).
In particular, the constraint of not being able to freely open TCP connections makes it difficult to talk to a traditional database from an edge function. While Cloudflare has introduced a connect()
API that enables limited TCP connections, this still only enables database access using specific database drivers that are compatible with that API.
Note: Prisma Accelerate enables you to access any database from any edge function provider. No edge-compatible driver is necessary.
Which database drivers are edge-compatible?
Here is an overview of the different database drivers and their compatibility with different edge function offerings:
- Neon Serverless uses HTTP to access the database. It works with Cloudflare Workers and Vercel Edge Functions.
- PlanetScale Serverless uses HTTP to access the database. It works with Cloudflare Workers and Vercel Edge Functions.
node-postgres
(pg
) uses Cloudflare'sconnect()
(TCP) to access the database. It is only compatible with Cloudflare Workers, not with Vercel Edge Functions.@libsql/client
is used to access Turso databases. It works with Cloudflare Workers and Vercel Edge Functions.- Cloudflare D1 is used to access D1 databases. It is only compatible with Cloudflare Workers, not with Vercel Edge Functions.
There's also work being done on the node-mysql2
driver which will enable access to traditional MySQL databases from Cloudflare Workers and Pages in the future as well.
You can use all of these drivers with Prisma ORM using the respective driver adapters.
Depending on which deployment provider and database/driver you use, there may be special considerations. Please take a look at the deployment docs for your respective scenario to make sure you can deploy your application successfully:
- Cloudflare
- Vercel
If you want to deploy an app using Turso, you can follow the instructions here.