go-jet / jet

Type safe SQL builder with code generation and automatic query result data mapping
Apache License 2.0
2.23k stars 110 forks source link

Support `[NULLS { FIRST | LAST }]` for `jet.OrderByClause` #296

Closed oxer-0 closed 4 months ago

oxer-0 commented 7 months ago

Is your feature request related to a problem? Please describe. The type OrderByClause does not support optional [NULLS { FIRST | LAST }] (PostgreSQL) expression, Causing Nulls always being first when using descending ordering

SELECT * FROM tbl ORDER BY key DESC NULLS LAST

Same thing applies to MySQL/MariaDB, except they sort Null values first when using ascending ordering, and it has a different syntax for controlling it, and I was not able to find anything in the documents that explains about this behavior.

SELECT * FROM tbl ORDER BY -key ASC (notice the - before key)

Describe the solution you'd like Exposing methods (IMHO NullsFirst, NullsLast seem clear enough) for controlling where do nulls appear through OrderByClause could be helpful in lots of cases

go-jet commented 7 months ago

Agree, make sense. :+1:

houten11 commented 6 months ago

As a workaround, you can check if key is null:

SELECT * 
FROM tbl 
ORDER BY key is null, key DESC
go-jet commented 4 months ago

NULLS_FIRST/NULLS_LAST support added in Release v2.11.0.