Created
May 19, 2026 17:13
-
-
Save jrobinsonc/20f257f2b2f484b8f1e2379d0532a259 to your computer and use it in GitHub Desktop.
Configuring Drizzle with Supabase #Drizzle #Supabase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { drizzle } from "drizzle-orm/postgres-js"; | |
| import postgres from "postgres"; | |
| import * as schema from "./schema"; | |
| import { envs } from "@/config/envs"; | |
| const globalForDrizzle = global as unknown as { | |
| db: ReturnType<typeof drizzle>; | |
| client: ReturnType<typeof postgres>; | |
| }; | |
| /** | |
| * When configuring Drizzle with Supabase the property `prepare` must be FALSE. | |
| * https://supabase.com/docs/guides/database/drizzle | |
| */ | |
| const client = | |
| globalForDrizzle.client ?? postgres(envs.DATABASE_URL, { prepare: false }); | |
| export const db = globalForDrizzle.db ?? drizzle(client, { schema }); | |
| if (envs.ENV !== "production") { | |
| globalForDrizzle.db = db; | |
| globalForDrizzle.client = client; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment