import { existsSync } from "node:fs"; import { get_setting } from "./SettingConfig"; import { getKysely } from "./db/kysely"; export async function connectDB() { const kysely = getKysely(); let tries = 0; for (;;) { try { console.log("try to connect db"); await kysely.selectNoFrom(eb=> eb.val(1).as("dummy")).execute(); console.log("connect success"); } catch (err) { if (tries < 3) { tries++; console.error(`connection fail ${err} retry...`); await new Promise((resolve) => setTimeout(resolve, 1000)); continue; } throw err; } break; } return kysely; }