From 76a3f23018bd1836f394364c96683712d460607a Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Tue, 3 Sep 2024 19:31:12 +0700 Subject: [PATCH] add better logging and mysql ignore system database --- src/components/gui/studio.tsx | 30 ++++++++++++++++++++-- src/components/gui/tabs/table-data-tab.tsx | 1 - src/drivers/mysql/mysql-driver.ts | 7 ++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/components/gui/studio.tsx b/src/components/gui/studio.tsx index 800dd56..7cb6d83 100644 --- a/src/components/gui/studio.tsx +++ b/src/components/gui/studio.tsx @@ -3,7 +3,7 @@ import MainScreen from "@/components/gui/main-connection"; import { ConfigProvider } from "@/context/config-provider"; import { DriverProvider } from "@/context/driver-provider"; import type { BaseDriver } from "@/drivers/base-driver"; -import { ReactElement } from "react"; +import { ReactElement, useMemo } from "react"; import OptimizeTableState from "@/components/gui/table-optimized/OptimizeTableState"; import { StudioContextMenuItem } from "@/messages/open-context-menu"; import { CollaborationBaseDriver } from "@/drivers/collaboration-driver-base"; @@ -36,9 +36,35 @@ export function Studio({ sideBarFooterComponent, onBack, }: Readonly) { + const proxyDriver = useMemo(() => { + return new Proxy(driver, { + get(...arg) { + const [target, property] = arg; + + if (property === "query") { + return async (statement: string) => { + console.group("Query"); + console.info(`%c${statement}`, "color:#e67e22"); + console.groupEnd(); + return await target.query(statement); + }; + } else if (property === "transaction") { + return async (statements: string[]) => { + console.group("Transaction"); + statements.forEach((s) => console.log(`%c${s}`, "color:#e67e22")); + console.groupEnd(); + return await target.transaction(statements); + }; + } + + return Reflect.get(...arg); + }, + }); + }, [driver]); + return ( diff --git a/src/components/gui/tabs/table-data-tab.tsx b/src/components/gui/tabs/table-data-tab.tsx index 35ca808..1569f8c 100644 --- a/src/components/gui/tabs/table-data-tab.tsx +++ b/src/components/gui/tabs/table-data-tab.tsx @@ -143,7 +143,6 @@ export default function TableDataWindow({ commitChange({ driver: databaseDriver, tableName, tableSchema, data }) .then(({ errorMessage }) => { - console.log("here", errorMessage); if (errorMessage) setExecuteError(errorMessage); }) .catch(console.error) diff --git a/src/drivers/mysql/mysql-driver.ts b/src/drivers/mysql/mysql-driver.ts index 712d070..e094f8a 100644 --- a/src/drivers/mysql/mysql-driver.ts +++ b/src/drivers/mysql/mysql-driver.ts @@ -55,17 +55,18 @@ export default abstract class MySQLLikeDriver extends CommonSQLImplement { } async schemas(): Promise { - const schemaSql = "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA"; + const schemaSql = + "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')"; const schemaResult = (await this.query(schemaSql)) .rows as unknown as MySqlDatabase[]; const tableSql = - "SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE FROM information_schema.tables"; + "SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE FROM information_schema.tables WHERE TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')"; const tableResult = (await this.query(tableSql)) .rows as unknown as MySqlTable[]; const columnSql = - "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE, EXTRA FROM information_schema.columns"; + "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE, EXTRA FROM information_schema.columns WHERE TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')"; const columnResult = (await this.query(columnSql)) .rows as unknown as MySqlColumn[];