Fix/formula as display (#11439)

* Allow formulas to be display columns in the grid

* Ensure SQL Server always has a sort order
This commit is contained in:
melohagan 2023-08-04 13:53:30 +01:00 committed by GitHub
parent 13ae01bcf4
commit ece1c421fa
3 changed files with 22 additions and 2 deletions

View File

@ -27,7 +27,6 @@
"array", "array",
"attachment", "attachment",
"boolean", "boolean",
"formula",
"json", "json",
] ]

View File

@ -315,7 +315,7 @@ class InternalBuilder {
addSorting(query: KnexQuery, json: QueryJson): KnexQuery { addSorting(query: KnexQuery, json: QueryJson): KnexQuery {
let { sort, paginate } = json let { sort, paginate } = json
const table = json.meta?.table const table = json.meta?.table
if (sort) { if (sort && Object.keys(sort || {}).length > 0) {
for (let [key, value] of Object.entries(sort)) { for (let [key, value] of Object.entries(sort)) {
const direction = const direction =
value.direction === SortDirection.ASCENDING ? "asc" : "desc" value.direction === SortDirection.ASCENDING ? "asc" : "desc"

View File

@ -26,6 +26,12 @@ function generateReadJson({
filters: filters || {}, filters: filters || {},
sort: sort || {}, sort: sort || {},
paginate: paginate || {}, paginate: paginate || {},
meta: {
table: {
name: table || TABLE_NAME,
primary: ["id"],
},
},
} }
} }
@ -636,4 +642,19 @@ describe("SQL query builder", () => {
sql: `select * from (select * from (select * from \"test\" where LOWER(\"test\".\"name\") LIKE :1) where rownum <= :2) \"test\"`, sql: `select * from (select * from (select * from \"test\" where LOWER(\"test\".\"name\") LIKE :1) where rownum <= :2) \"test\"`,
}) })
}) })
it("should sort SQL Server tables by the primary key if no sort data is provided", () => {
let query = new Sql(SqlClient.MS_SQL, limit)._query(
generateReadJson({
sort: {},
paginate: {
limit: 10,
},
})
)
expect(query).toEqual({
bindings: [10],
sql: `select * from (select top (@p0) * from [test] order by [test].[id] asc) as [test]`,
})
})
}) })