Skip to content

Commit

Permalink
add better logging and mysql ignore system database
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Sep 3, 2024
1 parent 15afa0e commit 76a3f23
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
30 changes: 28 additions & 2 deletions src/components/gui/studio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -36,9 +36,35 @@ export function Studio({
sideBarFooterComponent,
onBack,
}: Readonly<StudioProps>) {
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 (
<DriverProvider
driver={driver}
driver={proxyDriver}
collaborationDriver={collaboration}
docDriver={docDriver}
>
Expand Down
1 change: 0 additions & 1 deletion src/components/gui/tabs/table-data-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/drivers/mysql/mysql-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ export default abstract class MySQLLikeDriver extends CommonSQLImplement {
}

async schemas(): Promise<DatabaseSchemas> {
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[];

Expand Down

0 comments on commit 76a3f23

Please sign in to comment.