Skip to content

Commit

Permalink
feat: fixing the duplicated name
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Apr 7, 2024
1 parent 8560fcc commit fbc6ed3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/query-result-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function Header({
}}
>
{header.icon ? <div className="mr-2">{header.icon}</div> : null}
<div className="grow">{header.name}</div>
<div className="grow">{header.displayName}</div>
<LucideChevronDown className="text-mute w-4 h-4 cursor-pointer" />
</div>
</DropdownMenuTrigger>
Expand Down
1 change: 1 addition & 0 deletions src/components/table-optimized/OptimizeTableState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class OptimizeTableState {
return {
initialSize,
name: headerName ?? "",
displayName: header.displayName,
resizable: true,
dataType,
icon: schemaResult?.pk.includes(headerName ?? "") ? (
Expand Down
1 change: 1 addition & 0 deletions src/components/table-optimized/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { cn } from "@/lib/utils";

export interface OptimizeTableHeaderProps {
name: string;
displayName: string;
initialSize: number;
resizable?: boolean;
dataType?: TableColumnDataType;
Expand Down
1 change: 1 addition & 0 deletions src/drivers/base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type DatabaseRow = Record<string, unknown>;

export interface DatabaseHeader {
name: string;
displayName: string;
originalType: string | null;
type: TableColumnDataType;
}
Expand Down
29 changes: 19 additions & 10 deletions src/drivers/rqlite-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 18 additions & 7 deletions src/drivers/turso-driver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fbc6ed3

Please sign in to comment.