From 04c17a537b6d9ce69f5d4f5024eaa10363d81f04 Mon Sep 17 00:00:00 2001 From: argshook Date: Tue, 24 Oct 2023 17:32:09 +0300 Subject: [PATCH] fix `showTables` to be backwards compatible with `name` property Upcoming QuestdB versions will change the column name from `name` -> `table_name` for `tables()` query. The web console is already using `table_name` property, but it should be backwards compatible with older versions of QuestDB. Once the new version of QuestDB is released, we can remove this backwards compatible code. --- packages/web-console/src/utils/questdb.ts | 37 ++++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/packages/web-console/src/utils/questdb.ts b/packages/web-console/src/utils/questdb.ts index f4f3b64b7..d00b930e2 100644 --- a/packages/web-console/src/utils/questdb.ts +++ b/packages/web-console/src/utils/questdb.ts @@ -348,22 +348,37 @@ export class Client { } async showTables(): Promise> { - const response = await this.query("tables();") + type BackwardsCompatibleTable = Table & { + /** @deprecated use `table_name` instead */ + name: string + } + + const response = await this.query("tables();") if (response.type === Type.DQL) { return { ...response, - data: response.data.slice().sort((a, b) => { - if (a.table_name > b.table_name) { - return 1 - } - - if (a.table_name < b.table_name) { - return -1 - } + data: response.data + .slice() + .sort((a, b) => { + const aName = a.table_name ?? a.name + const bName = b.table_name ?? b.name + if (aName > bName) { + return 1 + } + + if (aName < bName) { + return -1 + } + + return 0 + }) - return 0 - }), + // @TODO: remove this once upstream questdb releases version with `table_name` + .map((table) => ({ + ...table, + table_name: table.table_name ?? table.name, + })), } }