/
aaronair
/
Test_task_rt_solution
Обзор
Документация
Войти
/
aaronair
/
Test_task_rt_solution
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/src/db/client.ts
24 строки
568 B
Ilikedrinkpivo
first_commit
28 май 2026, 14:51
28 май 2026, 14:51
b4498fc
Код
Авторство
О чём код?
import { drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres"; import * as schema from "./schema.js"; let client: ReturnType<typeof postgres> | null = null; let db: ReturnType<typeof drizzle<typeof schema>> | null = null; export function getDb(databaseUrl: string) { if (!db) { client = postgres(databaseUrl, { max: 10 }); db = drizzle(client, { schema }); } return db; } export async function closeDb() { if (client) { await client.end(); client = null; db = null; } } export type Db = ReturnType<typeof getDb>;