2024-07-17 00:41:22 +02:00

34 lines
608 B
TypeScript

import mysql, { type PoolOptions } from 'mysql2/promise'
const poolOptions: PoolOptions = {
host: "",
port: 0,
user: "",
password: "",
database: ""
}
if (process.env.DBIP) {
poolOptions.host = process.env.DBIP;
}
if (process.env.DBPort) {
poolOptions.port = parseInt(process.env.DBPort);
}
if (process.env.DBUser) {
poolOptions.user = process.env.DBUser;
}
if (process.env.DBPassword) {
poolOptions.password = process.env.DBPassword;
}
if (process.env.DBDatabase) {
poolOptions.database = process.env.DBDatabase;
}
const pool = mysql.createPool(poolOptions);
export default pool;