import { SQL } from "bun";

let sql_object: any;

const sql = new SQL({
    adapter: "mariadb",
    hostname: process.env.DSQL_DB_HOST,
    database: process.env.DSQL_DB_NAME,
    username: process.env.DSQL_DB_USERNAME,
    password: process.env.DSQL_DB_PASSWORD,
    tls: {
        rejectUnauthorized: false,
    },
    idleTimeout: 30000,
    maxLifetime: 60 * 60 * 1000,
    onclose(err) {
        sql_object?.connect();
    },
    onconnect(err) {
        sql_object = sql;
    },
});

export default sql;
