WorkshopTasker/server/utils/database.ts
Wroclaw bbe0c91d7e allow to override default database config in new
this way we can temporarily allow to execute multiple statements
in one query.
2023-06-14 10:41:25 +02:00

19 lines
739 B
TypeScript

import mysql, { Connection } from "mysql2/promise";
const connectionOptions: mysql.ConnectionOptions = {
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,
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 }); };
export type data<T> = [T[], mysql.FieldPacket[]];