closeDb (db/index.ts)

mobvibe · apps/gateway/src/db/index.ts · typescript · Apache-2.0
database

Creates a Drizzle ORM pool and exposes a close function for graceful shutdown.

// Source: https://github.com/Eric-Song-Nop/mobvibe | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { drizzle } from "drizzle-orm/node-postgres";
import pg from "pg";
import * as schema from "./schema.js";

const { Pool } = pg;

if (!process.env.DATABASE_URL) {
	throw new Error("DATABASE_URL environment variable is required");
}

const pool = new Pool({
	connectionString: process.env.DATABASE_URL,
	max: 10,
	idleTimeoutMillis: 30000,
	connectionTimeoutMillis: 5000,
});

/**
 * Database connection.
 */
export const db = drizzle(pool, { schema });

/**
 * Close the database connection pool.
 * Call this during graceful shutdown.
 */
export async function closeDb(): Promise<vo

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key