From a4872b41599a59f6487948c7e8ad252af9690f02 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 26 Sep 2024 09:06:14 +0200 Subject: [PATCH] fixed Syntax error when trying to sort by UUID column #895 --- packages/datalib/src/GridDisplay.ts | 6 +++++- .../dbgate-plugin-postgres/src/frontend/drivers.js | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/datalib/src/GridDisplay.ts b/packages/datalib/src/GridDisplay.ts index 33b1224f..f272123a 100644 --- a/packages/datalib/src/GridDisplay.ts +++ b/packages/datalib/src/GridDisplay.ts @@ -278,7 +278,7 @@ export abstract class GridDisplay { applySortOnSelect(select: Select, displayedColumnInfo: DisplayedColumnInfo) { if (this.config.sort?.length > 0) { - select.orderBy = this.config.sort + const orderByColumns = this.config.sort .map(col => ({ ...col, dispInfo: displayedColumnInfo[col.uniqueName] })) .map(col => ({ ...col, expr: select.columns.find(x => x.alias == col.uniqueName) })) .filter(col => col.dispInfo && col.expr) @@ -286,6 +286,10 @@ export abstract class GridDisplay { ...col.expr, direction: col.order, })); + + if (orderByColumns.length > 0) { + select.orderBy = orderByColumns; + } } } diff --git a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js index 8b366ecd..e9d7e5bc 100644 --- a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js +++ b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js @@ -105,11 +105,11 @@ const dialect = { exprType: 'unaryRaw', expr: { exprType: 'column', - alias: alias || columnName, source, columnName, }, afterSql: '::text', + alias: alias || columnName, }; } }, @@ -136,9 +136,15 @@ const postgresDriverBase = { } return ( - ['authType', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly', 'useSeparateSchemas'].includes( - field - ) || + [ + 'authType', + 'user', + 'password', + 'defaultDatabase', + 'singleDatabase', + 'isReadOnly', + 'useSeparateSchemas', + ].includes(field) || (values.authType == 'socket' && ['socketPath'].includes(field)) || (values.authType != 'socket' && ['server', 'port'].includes(field)) );