mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-19 03:41:23 +02:00
- Add eslint.config.mjs with ESLint v9 flat config - Add missing dependencies (@eslint/js, globals, typescript-eslint) - Auto-fix formatting issues from ESLint --fix 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
38 lines
832 B
TypeScript
38 lines
832 B
TypeScript
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
import * as schema from './schema';
|
|
|
|
// Use require for postgres to avoid ESM/CommonJS interop issues
|
|
|
|
const postgres = require('postgres');
|
|
|
|
let connection: ReturnType<typeof postgres> | null = null;
|
|
let db: ReturnType<typeof drizzle> | null = null;
|
|
|
|
export function getConnection(databaseUrl: string) {
|
|
if (!connection) {
|
|
connection = postgres(databaseUrl, {
|
|
max: 10,
|
|
idle_timeout: 20,
|
|
connect_timeout: 10,
|
|
});
|
|
}
|
|
return connection;
|
|
}
|
|
|
|
export function getDb(databaseUrl: string) {
|
|
if (!db) {
|
|
const conn = getConnection(databaseUrl);
|
|
db = drizzle(conn, { schema });
|
|
}
|
|
return db;
|
|
}
|
|
|
|
export async function closeConnection() {
|
|
if (connection) {
|
|
await connection.end();
|
|
connection = null;
|
|
db = null;
|
|
}
|
|
}
|
|
|
|
export type Database = ReturnType<typeof getDb>;
|