import { Client } from "https://deno.land/x/mysql/mod.ts"; import config from "./config.json" assert { type: "json" }; import {Maybe} from "./Maybe.ts"; export type WithoutId = Omit; export interface StoccaTreDbConn { query(query: string): Promise>; } export default async function createNewDbConnection(): Promise { const mysqlClient = await new Client().connect({ hostname: config.hostname, username: config.username, db: "stocca_tre", password: config.password, }); return { query: async (query: string): Promise> => { let errMessage: string; try { const result = await mysqlClient.query(query); return { just: result as T, }; } catch (e: unknown) { if (e && typeof (e as { message?: any }).message === "string") { errMessage = (e as { message: string}).message; } else { errMessage = "An unknown error occurred in the database."; } } return { error: { message: errMessage }, }; } } }