fix(postgres): distinguish overloaded routines

This commit is contained in:
t8y2 committed 2026-07-13 00:26:04 +08:00
1 parent 823b4297d8
commit a3f3cadb39
14 files changed
+146 -48

No files matched your search

+23 -2
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { appendTableTreeLoadMoreNode, buildTableTreeNodes, mergeTableTreePageChildren, tablePartitionGroups, withoutTableTreeLoadMoreNodes } from "@/lib/table/tableTree";
import type { TableInfo, TreeNode } from "@/types/database";
import { appendTableTreeLoadMoreNode, buildSimpleObjectTreeNodes, buildTableTreeNodes, mergeTableTreePageChildren, tablePartitionGroups, withoutTableTreeLoadMoreNodes } from "@/lib/table/tableTree";
import type { ObjectInfo, TableInfo, TreeNode } from "@/types/database";
const context = {
nodeId: "connection:db",
@@ -8,6 +8,27 @@ const context = {
database: "db",
};
describe("PostgreSQL overloaded routines", () => {
it("keeps routines with the same name distinct by identity arguments", () => {
const objects: ObjectInfo[] = [
{ name: "calc", object_type: "FUNCTION", schema: "public", signature: "integer" },
{ name: "calc", object_type: "FUNCTION", schema: "public", signature: "integer, integer" },
{ name: "calc", object_type: "FUNCTION", schema: "public", signature: "numeric" },
];
const nodes = buildSimpleObjectTreeNodes({ ...context, schema: "public", objects });
expect(nodes.map((node) => ({ label: node.label, objectName: node.objectName, signature: node.signature }))).toEqual(
expect.arrayContaining([
{ label: "calc(integer)", objectName: "calc", signature: "integer" },
{ label: "calc(integer, integer)", objectName: "calc", signature: "integer, integer" },
{ label: "calc(numeric)", objectName: "calc", signature: "numeric" },
]),
);
expect(new Set(nodes.map((node) => node.id)).size).toBe(3);
});
});
describe("TDengine table hierarchy", () => {
it("groups child tables under their supertable and keeps ordinary tables flat", () => {
const tables: TableInfo[] = [
+2 -2
View File
@@ -592,8 +592,8 @@ export async function completionAssistantSearch(request: CompletionAssistantRequ
return post("/api/schema/completion-assistant", request);
}
export async function getObjectSource(connectionId: string, database: string, schema: string, name: string, objectType: ObjectSourceKind): Promise<ObjectSource> {
return get(`/api/schema/object-source?${qs({ connection_id: connectionId, database, schema, table: name, object_type: objectType })}`);
export async function getObjectSource(connectionId: string, database: string, schema: string, name: string, objectType: ObjectSourceKind, signature?: string): Promise<ObjectSource> {
return get(`/api/schema/object-source?${qs({ connection_id: connectionId, database, schema, table: name, object_type: objectType, signature })}`);
}
export async function getColumns(connectionId: string, database: string, schema: string, table: string, catalog?: string): Promise<ColumnInfo[]> {
+2 -2
View File
@@ -718,8 +718,8 @@ export async function completionAssistantSearch(request: CompletionAssistantRequ
return invoke("completion_assistant_search", { request });
}
export async function getObjectSource(connectionId: string, database: string, schema: string, name: string, objectType: ObjectSourceKind): Promise<ObjectSource> {
return invoke("get_object_source", { connectionId, database, schema, name, objectType });
export async function getObjectSource(connectionId: string, database: string, schema: string, name: string, objectType: ObjectSourceKind, signature?: string): Promise<ObjectSource> {
return invoke("get_object_source", { connectionId, database, schema, name, objectType, signature });
}
export async function listSchemas(connectionId: string, database: string, applyVisibleFilter = false): Promise<string[]> {
@@ -6,6 +6,7 @@ export interface DropObjectSqlOptions {
objectType: DatabaseObjectType;
schema?: string | null;
name: string;
signature?: string | null;
}
export interface TableAdminSqlOptions {
+6 -3
View File
@@ -503,7 +503,8 @@ export function buildSimpleObjectTreeNodes({ nodeId, connectionId, database, sch
if (!name) continue;
const childSchema = obj.schema ? normalizeDatabaseObjectName(obj.schema) : schema;
const dedupeKey = `${objectType}\0${(childSchema || "").toLowerCase()}\0${name.toLowerCase()}`;
const signature = obj.signature?.trim() || "";
const dedupeKey = `${objectType}\0${(childSchema || "").toLowerCase()}\0${name.toLowerCase()}\0${signature.toLowerCase()}`;
if (seen.has(dedupeKey)) continue;
seen.add(dedupeKey);
@@ -524,9 +525,11 @@ export function buildSimpleObjectTreeNodes({ nodeId, connectionId, database, sch
} else {
const simpleNodeType = simpleObjectNodeType(objectType);
objectNodes.push({
id: objectType === "VIEW" || objectType === "MATERIALIZED_VIEW" ? entry.node.id : `${nodeId}:${childSchema ? `${childSchema}:` : ""}${name}:${objectType}`,
label: name,
id: objectType === "VIEW" || objectType === "MATERIALIZED_VIEW" ? entry.node.id : `${nodeId}:${childSchema ? `${childSchema}:` : ""}${name}:${signature}:${objectType}`,
label: signature && (objectType === "FUNCTION" || objectType === "PROCEDURE") ? `${name}(${signature})` : name,
type: simpleNodeType,
objectName: name,
signature: signature || undefined,
comment: obj.comment,
connectionId,
database,