ionian/packages/server/src/database.ts
2024-03-29 00:19:36 +09:00

27 lines
604 B
TypeScript

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;
}