From 27b2134b0cee0428a6cafe53266e1135b1583c24 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 26 Sep 2023 20:01:22 +0530 Subject: [PATCH] refactor: apply sort order and set null handling in sort Signed-off-by: Pranav C --- packages/nocodb/src/db/BaseModelSqlv2.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 560c690a0c..f0dbd55052 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -580,8 +580,10 @@ ${qb.toQuery()} } break; default: - selectors.push(column.column_name); - groupBySelectors.push(sanitize(column.column_name)); + selectors.push( + this.dbDriver.raw('?? as ??', [column.column_name, column.title]), + ); + groupBySelectors.push(sanitize(column.title)); break; } }), @@ -642,6 +644,8 @@ ${qb.toQuery()} qb.orderBy( groupByColumns[sort.fk_column_id].column_name || groupByColumns[sort.fk_column_id].title, + sort.direction, + sort.direction === 'desc' ? 'LAST' : 'FIRST', ); }); @@ -736,8 +740,13 @@ ${qb.toQuery()} } break; default: - selectors.push(column.column_name); - groupBySelectors.push(sanitize(column.column_name)); + selectors.push( + this.dbDriver.raw('?? as ??', [ + column.column_name, + column.title, + ]), + ); + groupBySelectors.push(sanitize(column.title)); break; } }),