Skip to content

Commit

Permalink
fix showTables to be backwards compatible with name property
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
argshook committed Oct 24, 2023
1 parent 0d4e7ad commit 04c17a5
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions packages/web-console/src/utils/questdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,37 @@ export class Client {
}

async showTables(): Promise<QueryResult<Table>> {
const response = await this.query<Table>("tables();")
type BackwardsCompatibleTable = Table & {
/** @deprecated use `table_name` instead */
name: string
}

const response = await this.query<BackwardsCompatibleTable>("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,
})),
}
}

Expand Down

0 comments on commit 04c17a5

Please sign in to comment.