Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Created May 19, 2026 17:13
Show Gist options
  • Select an option

  • Save jrobinsonc/20f257f2b2f484b8f1e2379d0532a259 to your computer and use it in GitHub Desktop.

Select an option

Save jrobinsonc/20f257f2b2f484b8f1e2379d0532a259 to your computer and use it in GitHub Desktop.
Configuring Drizzle with Supabase #Drizzle #Supabase
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