Serverless Drivers
Connecting to your Postgres database in serverless environments.
Supabase provides several options for connecting to your Postgres database from serverless environments.
supabase-js is an isomorphic JavaScript client that uses the auto-generated REST API and therefore works in any environment that supports HTTPS connections. This API has a built-in connection pooler and can serve thousands of simultaneous requests, and therefore is ideal for Serverless workloads.
Vercel Edge Functions
Vercel's Edge runtime is built on top of the V8 engine, that provides a limited set of Web Standard APIs.
Quickstart
Choose one of these Vercel Deploy Templates which use our Vercel Deploy Integration to automatically configure your connection strings as environment variables on your Vercel project!
Manual configuration
In your Database Settings and copy the URI from the Transaction pooler section and save it as the POSTGRES_URL environment variable. Remember to replace the password placeholder with your actual database password and add the following suffix ?workaround=supabase-pooler.vercel.
1POSTGRES_URL="postgres://postgres.cfcxynqnhdybqtbhjemm:[YOUR-PASSWORD]@aws-0-ap-southeast-1.pooler.supabase.com:6543/postgres?workaround=supabase-pooler.vercel"1import { pgTable, serial, text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core'2import { InferSelectModel, InferInsertModel } from 'drizzle-orm'3import { sql } from '@vercel/postgres'4import { drizzle } from 'drizzle-orm/vercel-postgres'56export const UsersTable = pgTable(7 'users',8 {9 id: serial('id').primaryKey(),10 name: text('name').notNull(),11 email: text('email').notNull(),12 image: text('image').notNull(),13 createdAt: timestamp('createdAt').defaultNow().notNull(),14 },15 (users) => {16 return {17 uniqueIdx: uniqueIndex('unique_idx').on(users.email),18 }19 }20)2122export type User = InferSelectModel<typeof UsersTable>23export type NewUser = InferInsertModel<typeof UsersTable>2425// Connect to Vercel Postgres26export const db = drizzle(sql)Cloudflare Workers
Cloudflare's Workers runtime also uses the V8 engine but provides polyfills for a subset of Node.js APIs and TCP Sockets API, giving you a couple of options:
Supabase Edge Functions
Supabase Edge Functions uses the Deno runtime which has native support for TCP connections allowing you to choose your favorite client: