diff --git a/src/common/interfaces/antares.ts b/src/common/interfaces/antares.ts index 753bd81b..8614443d 100644 --- a/src/common/interfaces/antares.ts +++ b/src/common/interfaces/antares.ts @@ -25,6 +25,7 @@ export interface IpcResponse { */ export interface ClientParams { client: ClientCode; + uid: string; params: mysql.ConnectionOptions & {schema: string; ssl?: mysql.SslOptions; ssh?: SSHConfig; readonly: boolean} | pg.ClientConfig & {schema: string; ssl?: mysql.SslOptions; ssh?: SSHConfig; readonly: boolean} diff --git a/src/main/ipc-handlers/connection.ts b/src/main/ipc-handlers/connection.ts index 72e14fe5..69630ec5 100644 --- a/src/main/ipc-handlers/connection.ts +++ b/src/main/ipc-handlers/connection.ts @@ -55,6 +55,7 @@ export default (connections: {[key: string]: antares.Client}) => { try { const connection = await ClientsFactory.getClient({ + uid: conn.uid, client: conn.client, params }); @@ -128,6 +129,7 @@ export default (connections: {[key: string]: antares.Client}) => { try { const connection = ClientsFactory.getClient({ + uid: conn.uid, client: conn.client, params, poolSize: 5 diff --git a/src/main/libs/AntaresCore.ts b/src/main/libs/AntaresCore.ts index 9803f016..e8106513 100644 --- a/src/main/libs/AntaresCore.ts +++ b/src/main/libs/AntaresCore.ts @@ -1,11 +1,14 @@ import * as antares from 'common/interfaces/antares'; +import { webContents } from 'electron'; import mysql from 'mysql2/promise'; import * as pg from 'pg'; import SSH2Promise from 'ssh2-promise'; -const queryLogger = (sql: string) => { +const queryLogger = ({ sql, cUid }: {sql: string; cUid: string}) => { // Remove comments, newlines and multiple spaces const escapedSql = sql.replace(/(\/\*(.|[\r\n])*?\*\/)|(--(.*|[\r\n]))/gm, '').replace(/\s\s+/g, ' '); + const mainWindow = webContents.fromId(1); + mainWindow.send('query-log', { cUid, sql: escapedSql }); console.log(escapedSql); }; @@ -14,15 +17,17 @@ const queryLogger = (sql: string) => { */ export class AntaresCore { _client: antares.ClientCode; + protected _cUid: string protected _params: mysql.ConnectionOptions | pg.ClientConfig | { databasePath: string; readonly: boolean}; protected _poolSize: number; protected _ssh?: SSH2Promise; - protected _logger: (sql: string) => void; + protected _logger: (args: {sql: string; cUid: string}) => void; protected _queryDefaults: antares.QueryBuilderObject; protected _query: antares.QueryBuilderObject; constructor (args: antares.ClientParams) { this._client = args.client; + this._cUid = args.uid; this._params = args.params; this._poolSize = args.poolSize || undefined; this._logger = args.logger || queryLogger; diff --git a/src/main/libs/clients/MySQLClient.ts b/src/main/libs/clients/MySQLClient.ts index ba3226f0..d1836023 100644 --- a/src/main/libs/clients/MySQLClient.ts +++ b/src/main/libs/clients/MySQLClient.ts @@ -1536,7 +1536,7 @@ export class MySQLClient extends AntaresCore { } async raw (sql: string, args?: antares.QueryParams) { - if (process.env.NODE_ENV === 'development') this._logger(sql); + if (process.env.NODE_ENV === 'development') this._logger({ cUid: this._cUid, sql }); args = { nest: false, diff --git a/src/main/libs/clients/PostgreSQLClient.ts b/src/main/libs/clients/PostgreSQLClient.ts index fca9a68d..89c9dfe7 100644 --- a/src/main/libs/clients/PostgreSQLClient.ts +++ b/src/main/libs/clients/PostgreSQLClient.ts @@ -1314,7 +1314,7 @@ export class PostgreSQLClient extends AntaresCore { } async raw (sql: string, args?: antares.QueryParams) { - if (process.env.NODE_ENV === 'development') this._logger(sql); + if (process.env.NODE_ENV === 'development') this._logger({ cUid: this._cUid, sql }); args = { nest: false, diff --git a/src/main/libs/clients/SQLiteClient.ts b/src/main/libs/clients/SQLiteClient.ts index b73a40f2..270dad11 100644 --- a/src/main/libs/clients/SQLiteClient.ts +++ b/src/main/libs/clients/SQLiteClient.ts @@ -586,7 +586,7 @@ export class SQLiteClient extends AntaresCore { } async raw (sql: string, args?: antares.QueryParams) { - if (process.env.NODE_ENV === 'development') this._logger(sql);// TODO: replace BLOB content with a placeholder + if (process.env.NODE_ENV === 'development') this._logger({ cUid: this._cUid, sql });// TODO: replace BLOB content with a placeholder args = { nest: false, diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 3798e2a8..08eb2928 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -71,6 +71,10 @@ ipcRenderer.on('open-connections-modal', () => { isAllConnectionsModal.value = true; }); +ipcRenderer.on('query-log', (e, sql: string) => { + console.log(sql); +}); + document.addEventListener('DOMContentLoaded', () => { setTimeout(() => { changeApplicationTheme(applicationTheme.value);// Forces persistentStore to save on file and mail process