From 329246e2d8a1fb8dc2c8bd0cc3d2df3ebe7fd788 Mon Sep 17 00:00:00 2001 From: Fabio286 Date: Fri, 1 Dec 2023 20:05:30 +0100 Subject: [PATCH] refactor: minor refactor --- src/main/libs/clients/BaseClient.ts | 2 +- src/main/libs/exporters/sql/MysqlExporter.ts | 7 ++----- src/main/libs/exporters/sql/PostgreSQLExporter.ts | 1 - src/renderer/stores/scratchpad.ts | 11 ++++++++++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/libs/clients/BaseClient.ts b/src/main/libs/clients/BaseClient.ts index 773f3277..2e85997a 100644 --- a/src/main/libs/clients/BaseClient.ts +++ b/src/main/libs/clients/BaseClient.ts @@ -10,7 +10,7 @@ const queryLogger = ({ sql, cUid }: {sql: string; cUid: string}) => { const mainWindow = require('electron').webContents.fromId(1); mainWindow.send('query-log', { cUid, sql: escapedSql, date: new Date() }); } - if (process.env.NODE_ENV === 'development') console.log(escapedSql); + if (process.env.NODE_ENV === 'development' && process.type === 'browser') console.log(escapedSql); }; /** diff --git a/src/main/libs/exporters/sql/MysqlExporter.ts b/src/main/libs/exporters/sql/MysqlExporter.ts index 49c91a34..469f5844 100644 --- a/src/main/libs/exporters/sql/MysqlExporter.ts +++ b/src/main/libs/exporters/sql/MysqlExporter.ts @@ -1,6 +1,5 @@ import * as exporter from 'common/interfaces/exporter'; import { valueToSqlString } from 'common/libs/sqlUtils'; -import * as mysql from 'mysql2/promise'; import { MySQLClient } from '../../clients/MySQLClient'; import { SqlExporter } from './SqlExporter'; @@ -334,12 +333,10 @@ CREATE TABLE \`${view.Name}\`( } async _queryStream (sql: string) { - if (process.env.NODE_ENV === 'development') console.log('EXPORTER:', sql); - const isPool = 'getConnection' in this._client._connection; - const connection = isPool ? await (this._client._connection as mysql.Pool).getConnection() : this._client._connection; + const connection = await this._client.getConnection(); // eslint-disable-next-line @typescript-eslint/no-explicit-any const stream = (connection as any).connection.query(sql).stream(); - const dispose = () => (connection as mysql.PoolConnection).release(); + const dispose = () => connection.end(); stream.on('end', dispose); stream.on('error', dispose); diff --git a/src/main/libs/exporters/sql/PostgreSQLExporter.ts b/src/main/libs/exporters/sql/PostgreSQLExporter.ts index 82fed408..b54c9a72 100644 --- a/src/main/libs/exporters/sql/PostgreSQLExporter.ts +++ b/src/main/libs/exporters/sql/PostgreSQLExporter.ts @@ -425,7 +425,6 @@ SET row_security = off;\n\n\n`; } async _queryStream (sql: string) { - if (process.env.NODE_ENV === 'development') console.log('EXPORTER:', sql); const connection = await this._client.getConnection(); const query = new QueryStream(sql, null); // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/renderer/stores/scratchpad.ts b/src/renderer/stores/scratchpad.ts index ac8ba5f9..73f2f802 100644 --- a/src/renderer/stores/scratchpad.ts +++ b/src/renderer/stores/scratchpad.ts @@ -2,9 +2,18 @@ import * as Store from 'electron-store'; import { defineStore } from 'pinia'; const persistentStore = new Store({ name: 'notes' }); +export interface ConnectionNote { + uid: string; + note: string; + date: Date; +} + export const useScratchpadStore = defineStore('scratchpad', { state: () => ({ - notes: persistentStore.get('notes', '# HOW TO SUPPORT ANTARES\n\n- [ ] Leave a star to Antares [GitHub repo](https://github.com/antares-sql/antares)\n- [ ] Send feedbacks and advices\n- [ ] Report for bugs\n- [ ] If you enjoy, share Antares with friends\n\n# ABOUT SCRATCHPAD\n\nThis is a scratchpad where you can save your **personal notes**. It supports `markdown` format, but you are free to use plain text.\nThis content is just a placeholder, feel free to clear it to make space for your notes.\n') as string + /** Global notes */ + notes: persistentStore.get('notes', '# HOW TO SUPPORT ANTARES\n\n- [ ] Leave a star to Antares [GitHub repo](https://github.com/antares-sql/antares)\n- [ ] Send feedbacks and advices\n- [ ] Report for bugs\n- [ ] If you enjoy, share Antares with friends\n\n# ABOUT SCRATCHPAD\n\nThis is a scratchpad where you can save your **personal notes**. It supports `markdown` format, but you are free to use plain text.\nThis content is just a placeholder, feel free to clear it to make space for your notes.\n') as string, + /** Connection specific notes */ + connectionNotes: persistentStore.get('connectionNotes', {}) as {[k: string]: ConnectionNote} }), actions: { changeNotes (notes: string) {