Fix invalid sql query from findAll with empty sort (#9135)

* Add test for empty sort for findAll in postgres
* Do not add ORDER BY without order fields

---------

Signed-off-by: Nikolay Marchuk <nikolay.marchuk@hardcoreeng.com>
This commit is contained in:
Nikolay Marchuk 2025-05-30 00:02:56 +07:00 committed by GitHub
parent b6e8fdd409
commit 73f7cfc11b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -247,6 +247,9 @@ describe('postgres operations', () => {
const sortDesc = await client.findAll(taskPlugin.class.Task, {}, { sort: { name: SortingOrder.Descending } })
expect(sortDesc[0].name).toMatch('my-task-4')
const sortEmpty = await client.findAll(taskPlugin.class.Task, {}, { sort: {} })
expect(sortEmpty).toHaveLength(5)
})
it('check attached', async () => {

View File

@ -522,7 +522,11 @@ abstract class PostgresAdapterBase implements DbAdapter {
// todo handle custom sorting
}
}
return `ORDER BY ${res.join(', ')}`
if (res.length > 0) {
return `ORDER BY ${res.join(', ')}`
} else {
return ''
}
}
buildRawQuery<T extends Doc>(
@ -1170,7 +1174,11 @@ abstract class PostgresAdapterBase implements DbAdapter {
// todo handle custom sorting
}
}
return `ORDER BY ${res.join(', ')}`
if (res.length > 0) {
return `ORDER BY ${res.join(', ')}`
} else {
return ''
}
}
private buildQuery<T extends Doc>(