Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 12 additions & 158 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@
},
"dependencies": {
"drizzle-orm": "^0.45.1",
"pg": "^8.20.0",
"postgres": "^3.4.8",
"uuid": "^13.0.0"
},
"devDependencies": {
"@types/node": "^25.5.0",
"@types/pg": "^8.20.0",
"drizzle-kit": "^0.31.10",
"typescript": "^6.0.2",
"vite-plus": "^0.1.13"
Expand Down
18 changes: 10 additions & 8 deletions src/infrastructure/drizzle/client.ts
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 });
}
Comment on lines +15 to 16
Copy link
Copy Markdown

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: false at src/infrastructure/drizzle/client.ts:16 disables 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

return pool;
return client;
}

export function getDb() {
return drizzle(getPool(), { schema });
return drizzle(getClient(), { schema });
}
Comment on lines 20 to 22
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 getDb() at src/infrastructure/drizzle/client.ts:19-21 creates a new drizzle() wrapper instance, even though the underlying postgres client is cached. This is the same pattern that existed before the migration (with drizzle(getPool(), { schema })), so it's not a regression. However, drizzle-orm recommends creating the drizzle instance once. The drizzle wrapper is lightweight, so this is unlikely to cause measurable performance issues, but caching the drizzle instance (similar to how client is cached) would be a minor improvement.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


export type DrizzleDb = ReturnType<typeof getDb>;