mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
WIP: Rewrite to TS & Cleanup
This commit is contained in:
27 files changed
+508
-504
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { mysql_debug, mysql_slow_query_warning, mysql_ui } from '../config';
|
||||
import type { CFXParameters } from '../types';
|
||||
|
||||
type QueryLog = {
|
||||
[invokingResource: string]: {
|
||||
date: number;
|
||||
query: string;
|
||||
executionTime: number;
|
||||
}[];
|
||||
};
|
||||
|
||||
const logStorage: QueryLog = {};
|
||||
|
||||
export const logQuery = (invokingResource: string, query: string, executionTime: number, parameters: CFXParameters) => {
|
||||
if (executionTime >= mysql_slow_query_warning || mysql_debug)
|
||||
console.log(
|
||||
`^3[${mysql_debug ? 'DEBUG' : 'WARNING'}] ${invokingResource} took ${executionTime}ms to execute a query!
|
||||
${query} ${JSON.stringify(parameters)}^0`
|
||||
);
|
||||
|
||||
if (!mysql_ui) return;
|
||||
|
||||
logStorage[invokingResource].push({ query, executionTime, date: Date.now() });
|
||||
};
|
||||
|
||||
RegisterCommand(
|
||||
'mysql',
|
||||
() => {
|
||||
if (!mysql_ui) return;
|
||||
|
||||
emitNet(`oxmysql:openUi`, logStorage);
|
||||
},
|
||||
true
|
||||
);
|
||||
Reference in new issue
Block a user