WorkshopTasker/server/utils/database.ts

20 lines
746 B
TypeScript
Raw Normal View History

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 =
await mysql.createConnection(connectionOptions) as Connection & {
new: (localConnectionOptions?: mysql.ConnectionOptions | undefined) => Promise<Connection>
};
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[]];