From fbc6ed32a569737663578d3f42eb359b78e80c0f Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Sun, 7 Apr 2024 11:41:54 +0700 Subject: [PATCH] feat: fixing the duplicated name --- src/components/query-result-table.tsx | 2 +- .../table-optimized/OptimizeTableState.tsx | 1 + src/components/table-optimized/index.tsx | 1 + src/drivers/base-driver.ts | 1 + src/drivers/rqlite-driver.ts | 29 ++++++++++++------- src/drivers/turso-driver.tsx | 25 +++++++++++----- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/components/query-result-table.tsx b/src/components/query-result-table.tsx index c28db6a4..21fee685 100644 --- a/src/components/query-result-table.tsx +++ b/src/components/query-result-table.tsx @@ -70,7 +70,7 @@ function Header({ }} > {header.icon ?
{header.icon}
: null} -
{header.name}
+
{header.displayName}
diff --git a/src/components/table-optimized/OptimizeTableState.tsx b/src/components/table-optimized/OptimizeTableState.tsx index 07eaba73..7a97c631 100644 --- a/src/components/table-optimized/OptimizeTableState.tsx +++ b/src/components/table-optimized/OptimizeTableState.tsx @@ -63,6 +63,7 @@ export default class OptimizeTableState { return { initialSize, name: headerName ?? "", + displayName: header.displayName, resizable: true, dataType, icon: schemaResult?.pk.includes(headerName ?? "") ? ( diff --git a/src/components/table-optimized/index.tsx b/src/components/table-optimized/index.tsx index 214d66e9..7a0a1fda 100644 --- a/src/components/table-optimized/index.tsx +++ b/src/components/table-optimized/index.tsx @@ -18,6 +18,7 @@ import { cn } from "@/lib/utils"; export interface OptimizeTableHeaderProps { name: string; + displayName: string; initialSize: number; resizable?: boolean; dataType?: TableColumnDataType; diff --git a/src/drivers/base-driver.ts b/src/drivers/base-driver.ts index 25d81c98..3fb1f6da 100644 --- a/src/drivers/base-driver.ts +++ b/src/drivers/base-driver.ts @@ -12,6 +12,7 @@ export type DatabaseRow = Record; export interface DatabaseHeader { name: string; + displayName: string; originalType: string | null; type: TableColumnDataType; } diff --git a/src/drivers/rqlite-driver.ts b/src/drivers/rqlite-driver.ts index 1df53b6d..5523b88b 100644 --- a/src/drivers/rqlite-driver.ts +++ b/src/drivers/rqlite-driver.ts @@ -20,26 +20,35 @@ export function transformRawResult(raw: RqliteResult): DatabaseResultSet { const columns = raw.columns ?? []; const types = raw.types ?? []; const values = raw.values; - - const rows = values - ? values.map((r) => - columns.reduce((a, b, idx) => { - a[b] = r[idx]; - return a; - }, {} as DatabaseRow) - ) - : []; + const headerSet = new Set(); const headers: DatabaseHeader[] = columns.map((colName, colIdx) => { const colType = types[colIdx]; + let renameColName = colName; + + for (let i = 0; i < 20; i++) { + if (!headerSet.has(renameColName)) break; + renameColName = `__${colName}_${i}`; + } + return { - name: colName, + name: renameColName, + displayName: colName, originalType: colType, type: convertSqliteType(colType), }; }); + const rows = values + ? values.map((r) => + headers.reduce((a, b, idx) => { + a[b.name] = r[idx]; + return a; + }, {} as DatabaseRow) + ) + : []; + return { rows, rowsAffected: raw?.rows_affected ?? 0, diff --git a/src/drivers/turso-driver.tsx b/src/drivers/turso-driver.tsx index 1f7fbd4d..b3e05da2 100644 --- a/src/drivers/turso-driver.tsx +++ b/src/drivers/turso-driver.tsx @@ -9,23 +9,34 @@ import { DatabaseHeader, DatabaseResultSet, DatabaseRow } from "./base-driver"; import SqliteLikeBaseDriver from "./sqlite-base-driver"; export function transformRawResult(raw: ResultSet): DatabaseResultSet { - const rows = raw.rows.map((r) => - raw.columns.reduce((a, b, idx) => { - a[b] = r[idx]; - return a; - }, {} as DatabaseRow) - ); + const headerSet = new Set(); const headers: DatabaseHeader[] = raw.columns.map((colName, colIdx) => { const colType = raw.columnTypes[colIdx]; + let renameColName = colName; + + for (let i = 0; i < 20; i++) { + if (!headerSet.has(renameColName)) break; + renameColName = `__${colName}_${i}`; + } + + headerSet.add(renameColName); return { - name: colName, + name: renameColName, + displayName: colName, originalType: colType, type: convertSqliteType(colType), }; }); + const rows = raw.rows.map((r) => + headers.reduce((a, b, idx) => { + a[b.name] = r[idx]; + return a; + }, {} as DatabaseRow) + ); + return { rows, rowsAffected: raw.rowsAffected,