fix(completion): restore result field suggestions
This commit is contained in:
1 parent
187a10f02d
commit
b11f38d2df
2 files changed
+50
-2
No files matched your search
@@ -15,14 +15,16 @@ function fallbackColumnInfo(name: string): ColumnInfo {
|
|||||||
|
|
||||||
export function tableMetaForDataTab(tab: QueryTab | undefined): DataTabTableMeta | undefined {
|
export function tableMetaForDataTab(tab: QueryTab | undefined): DataTabTableMeta | undefined {
|
||||||
if (!tab || tab.mode !== "data") return 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();
|
const tableName = tab.title.trim();
|
||||||
if (!tableName) return undefined;
|
if (!tableName) return undefined;
|
||||||
|
|
||||||
|
// Keep filters usable when the table identity loaded but its column metadata did not.
|
||||||
return {
|
return {
|
||||||
|
...tab.tableMeta,
|
||||||
schema: tab.schema,
|
schema: tab.schema,
|
||||||
tableName,
|
tableName,
|
||||||
columns: (tab.result?.columns ?? []).map(fallbackColumnInfo),
|
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", () => {
|
test("does not infer table metadata for query tabs", () => {
|
||||||
assert.equal(tableMetaForDataTab(tab({ mode: "query" })), undefined);
|
assert.equal(tableMetaForDataTab(tab({ mode: "query" })), undefined);
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user