fix(completion): restore result field suggestions
This commit is contained in:
@@ -15,14 +15,16 @@ function fallbackColumnInfo(name: string): ColumnInfo {
|
||||
|
||||
export function tableMetaForDataTab(tab: QueryTab | undefined): DataTabTableMeta | undefined {
|
||||
if (!tab || tab.mode !== "data") return undefined;
|
||||
if (tab.tableMeta) return tab.tableMeta;
|
||||
if (tab.tableMeta?.columns.length) return tab.tableMeta;
|
||||
const tableName = tab.title.trim();
|
||||
if (!tableName) return undefined;
|
||||
|
||||
// Keep filters usable when the table identity loaded but its column metadata did not.
|
||||
return {
|
||||
...tab.tableMeta,
|
||||
schema: tab.schema,
|
||||
tableName,
|
||||
columns: (tab.result?.columns ?? []).map(fallbackColumnInfo),
|
||||
primaryKeys: [],
|
||||
primaryKeys: tab.tableMeta?.primaryKeys ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
+46
@@ -76,6 +76,52 @@ test("builds fallback metadata from a data tab when column metadata is unavailab
|
||||
});
|
||||
});
|
||||
|
||||
test("uses result columns when persisted table metadata has no columns", () => {
|
||||
const tableMeta = {
|
||||
schema: "public",
|
||||
tableName: "users",
|
||||
columns: [],
|
||||
primaryKeys: ["id"],
|
||||
};
|
||||
|
||||
assert.deepEqual(
|
||||
tableMetaForDataTab(
|
||||
tab({
|
||||
tableMeta,
|
||||
result: {
|
||||
columns: ["id", "name"],
|
||||
rows: [],
|
||||
affected_rows: 0,
|
||||
execution_time_ms: 1,
|
||||
},
|
||||
}),
|
||||
),
|
||||
{
|
||||
schema: "public",
|
||||
tableName: "users",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
data_type: "",
|
||||
is_nullable: true,
|
||||
column_default: null,
|
||||
is_primary_key: false,
|
||||
extra: null,
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
data_type: "",
|
||||
is_nullable: true,
|
||||
column_default: null,
|
||||
is_primary_key: false,
|
||||
extra: null,
|
||||
},
|
||||
],
|
||||
primaryKeys: ["id"],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("does not infer table metadata for query tabs", () => {
|
||||
assert.equal(tableMetaForDataTab(tab({ mode: "query" })), undefined);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user