-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Supabase Transaction pool mode 対応のため DB ドライバを postgres-js に切り替え #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,24 @@ | ||
| import { drizzle } from "drizzle-orm/node-postgres"; | ||
| import { Pool } from "pg"; | ||
| /// <reference types="node" /> | ||
| import { drizzle } from "drizzle-orm/postgres-js"; | ||
| import postgres, { type Sql } from "postgres"; | ||
| import * as schema from "./schema"; | ||
|
|
||
| let pool: Pool | null = null; | ||
| let client: Sql | null = null; | ||
|
|
||
| function getPool(): Pool { | ||
| if (!pool) { | ||
| function getClient(): Sql { | ||
| if (!client) { | ||
| const connectionString = process.env.DATABASE_URL; | ||
| if (!connectionString) { | ||
| throw new Error("DATABASE_URL environment variable is not set"); | ||
| } | ||
| pool = new Pool({ connectionString }); | ||
| // Supabase の Transaction pool mode は prepared statement をサポートしないため無効化 | ||
| client = postgres(connectionString, { prepare: false }); | ||
| } | ||
| return pool; | ||
| return client; | ||
| } | ||
|
|
||
| export function getDb() { | ||
| return drizzle(getPool(), { schema }); | ||
| return drizzle(getClient(), { schema }); | ||
| } | ||
|
Comment on lines
20
to
22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: getDb() creates a new drizzle instance on every call Each call to Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| export type DrizzleDb = ReturnType<typeof getDb>; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: prepare: false disables prepared statements globally
Setting
prepare: falseatsrc/infrastructure/drizzle/client.ts:16disables prepared statements for all queries through this client. The comment correctly explains this is needed for Supabase's Transaction pool mode (pgbouncer in transaction mode doesn't support prepared statements). This is a correct and necessary configuration choice, but it does mean a slight performance trade-off — repeated identical queries won't benefit from server-side prepared statement caching. Worth noting for anyone reading this code that this is an intentional trade-off, not an oversight.Was this helpful? React with 👍 or 👎 to provide feedback.