refactor(database): move from mysql2/promise to callback api

Micro-optimisation for rawQuery. rawExecute and rawTransaction will
still utilise the promise api (pool.promise()).
This commit is contained in:
Linden committed 2022-03-25 06:07:57 +00:00
1 parent dd05cb8e68
commit dea98f7c5b
5 files changed
+22 -33

No files matched your search

+6 -10
View File
@@ -1,4 +1,4 @@
import { createPool, QueryError, Pool } from 'mysql2/promise';
import { createPool, Pool } from 'mysql2';
import { connectionOptions, mysql_transaction_isolation_level } from '../config';
import { typeCast } from '../utils/typeCast';
@@ -12,15 +12,11 @@ setTimeout(() => {
typeCast,
});
pool
.query(mysql_transaction_isolation_level)
.then(() => {
console.log(`^2Database server connection established!^0`);
serverReady = true;
})
.catch((e: QueryError) =>
console.error(`^3Unable to establish a connection to the database! [${e.code}]\n${e.message}^0`)
);
pool.query(mysql_transaction_isolation_level, (err) => {
if (err) return console.error(`^3Unable to establish a connection to the database!\n^3[${err}]^0`);
console.log(`^2Database server connection established!^0`);
serverReady = true;
});
});
export { pool, serverReady };