import { Client } from "postgres"; import config from "./config.ts"; import {Maybe} from "./Maybe.ts"; import {JSONObject} from "./JSON.ts"; export type WithoutId = Omit; export interface StoccaTreDbConn { query(query: string): Promise>, } export default function createNewDbConnection(): StoccaTreDbConn { const postgresClient = new Client({ hostname: config.hostname, password: config.password, user: config.username, database: "stocca_tre", port: config.port, }); await postgresClient.connect(); return { async queryMany(query: string): Promise> { try { const result = await postgresClient.queryArray(query); return { just: { rows: result.rows, count: result.rowCount ?? NaN, }, }; } catch (e: unknown) { } }, queryOne(query: string): Promise> { try { const result = await postgresClient.queryObject(query); return { just: result }; } } } }