From 2eafbdf45eb0725b04de1ab71492a3ef57645e72 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Mon, 14 Apr 2025 22:14:41 -0500 Subject: [PATCH] perf(db): better control over how we stay connected --- database/dbclient.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/database/dbclient.ts b/database/dbclient.ts index 2e34427..a706f15 100644 --- a/database/dbclient.ts +++ b/database/dbclient.ts @@ -1,4 +1,4 @@ -import {drizzle} from "drizzle-orm/postgres-js"; +import { drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres"; import dotenv from "dotenv"; @@ -6,6 +6,17 @@ dotenv.config(); const database = process.env.DATABASE_URL || ""; -const queryClient = postgres(database); +const queryClient = postgres(database, { + max: 10, + idle_timeout: 60, + connect_timeout: 10, + max_lifetime: 1000 * 60 * 5, + onnotice: (notice) => { + console.log("PG NOTICE:", notice.message); + }, + // debug: (...args) => { + // console.log("QUERY DEBUG:", ...args); + // }, +}); -export const db = drizzle({client: queryClient}); +export const db = drizzle({ client: queryClient });