Serverless drivers
Choose a driver for connecting to your Postgres database from a serverless environment.
Learn how to connect to your Postgres database from a serverless environment. The driver you use depends on which runtime your code runs in.
supabase-js is an isomorphic JavaScript client that uses the auto-generated REST API, so it works in any environment that supports HTTPS connections. This API has a built-in connection pooler and can serve thousands of simultaneous requests, which suits serverless workloads.
If you connect with a Postgres client instead, use the shared pooler in transaction mode, then configure your client for pool size, prepared statements, and SSL. Those three settings are what most serverless connection problems come down to.
Vercel Edge Functions#
Vercel's Edge runtime runs on the V8 engine and exposes a limited set of Web Standard APIs.
Start from a deploy template, or configure the connection yourself.
Quickstart#
Choose one of these Vercel Deploy Templates. They use the Vercel Deploy Integration to configure your connection strings as environment variables on your Vercel project.
Manual configuration#
- In the Supabase Dashboard, click Connect and copy the URI from the Transaction pooler section.
- Replace the password placeholder with your database password.
- Add the suffix
?workaround=supabase-pooler.vercelto the URI. - Save the result as the
POSTGRES_URLenvironment variable.
POSTGRES_URL="postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@[POOLER-HOST]:6543/postgres?workaround=supabase-pooler.vercel"import { sql } from '@vercel/postgres'import { InferInsertModel, InferSelectModel } from 'drizzle-orm'import { pgTable, serial, text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core'import { drizzle } from 'drizzle-orm/vercel-postgres'export const UsersTable = pgTable( 'users', { id: serial('id').primaryKey(), name: text('name').notNull(), email: text('email').notNull(), image: text('image').notNull(), createdAt: timestamp('createdAt').defaultNow().notNull(), }, (users) => { return { uniqueIdx: uniqueIndex('unique_idx').on(users.email), } })export type User = InferSelectModel<typeof UsersTable>export type NewUser = InferInsertModel<typeof UsersTable>// Connect to Vercel Postgresexport const db = drizzle(sql)Cloudflare Workers#
Cloudflare's Workers runtime also uses the V8 engine, but it provides polyfills for a subset of Node.js APIs and the TCP Sockets API. That gives you three options:
Drivers #
Supabase Edge Functions#
Supabase Edge Functions use the Deno runtime, which has native support for TCP connections. You can choose any of these clients: