2023-11-06 02:57:00 +01:00
|
|
|
import mysql, { type Connection } from "mysql2/promise";
|
2023-05-11 06:03:22 +02:00
|
|
|
|
2023-05-24 09:40:45 +02:00
|
|
|
const connectionOptions: mysql.ConnectionOptions = {
|
2023-05-11 06:03:22 +02:00
|
|
|
host: process.env.DB_HOST,
|
|
|
|
port: Number(process.env.DB_PORT),
|
|
|
|
user: process.env.DB_USER,
|
|
|
|
password: process.env.DB_PASSWORD,
|
|
|
|
database: process.env.DB_SCHEMA,
|
2023-05-24 09:40:45 +02:00
|
|
|
decimalNumbers: true,
|
|
|
|
supportBigNumbers: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const database =
|
2023-06-14 10:41:25 +02:00
|
|
|
await mysql.createConnection(connectionOptions) as Connection & {
|
2023-11-06 02:57:00 +01:00
|
|
|
new: (localConnectionOptions?: mysql.ConnectionOptions | undefined) => Promise<Connection>
|
2023-06-14 10:41:25 +02:00
|
|
|
};
|
2023-11-06 02:57:00 +01:00
|
|
|
database.new = (localConnectionOptions?: mysql.ConnectionOptions | undefined) => { return mysql.createConnection({ ...localConnectionOptions, ...connectionOptions }); };
|
2023-05-11 06:03:22 +02:00
|
|
|
|
|
|
|
export type data<T> = [T[], mysql.FieldPacket[]];
|