From bbe0c91d7eec37f05beea67dea0ac997230226ae Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Wed, 14 Jun 2023 10:41:25 +0200 Subject: [PATCH] allow to override default database config in new this way we can temporarily allow to execute multiple statements in one query. --- server/utils/database.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/utils/database.ts b/server/utils/database.ts index d956d52..de9c79c 100644 --- a/server/utils/database.ts +++ b/server/utils/database.ts @@ -11,7 +11,9 @@ const connectionOptions: mysql.ConnectionOptions = { }; export const database = - await mysql.createConnection(connectionOptions) as Connection & { new: () => Promise }; -database.new = () => { return mysql.createConnection(connectionOptions); }; + await mysql.createConnection(connectionOptions) as Connection & { + new: (localConnectionOptions: mysql.ConnectionOptions | undefined) => Promise + }; +database.new = (localConnectionOptions: mysql.ConnectionOptions | undefined) => { return mysql.createConnection({ ...localConnectionOptions, ...connectionOptions }); }; export type data = [T[], mysql.FieldPacket[]];