New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for 'is null' in 'order by' #3667
Labels
Comments
You can use |
Any syntax that is backwards compatible if fine for me. Sorry for really delayed answer though. That would be a useful feature. |
OlivierCavadenti
added a commit
to OlivierCavadenti/knex
that referenced
this issue
Oct 10, 2021
- add support to order nulls in order by with 'first' and 'last' option.
kibertoad
pushed a commit
that referenced
this issue
Oct 10, 2021
can be closed, resolved with #4720 |
rustyconover
pushed a commit
to rustyconover/knex
that referenced
this issue
Oct 18, 2021
OlivierCavadenti
added a commit
to AbeonaPascha/knex
that referenced
this issue
Nov 4, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to request a feature, which I would be happy to implement myself since it doesn't seem like it would be all that big of a change. Feel free to correct me if I'm wrong.
Needing to specify the sort order of nulls within a nullable column is fairly common use case. I see that this is discussed here many years back, and it seems like the conclusion was to just use raw SQL, with
orderByRaw
being added as a shortcut fororderBy(knex.raw('...'))
.I see this being said there, but I really don't follow.
If this is the reason that this feature was never implemented, and that reason still stands, some further explanation would be very helpful as I'm rather confused by this comment.
Using raw SQL is fine in a lot of use cases, but I'm trying to write an abstraction around Objection where it is common to use snake case conversion so that database columns and tables are named in snake case (idiomatic in SQL) while those same entities can be referred to in camel case (idiomatic in JavaScript).
Raw queries obviously don't get the snake case mappings, so using a raw query in my case would require me to extract the snake case mappers and run them on the column names myself, before building the raw SQL. Either that, or it would require users of my abstraction who are also using the mappers to be aware of the raw query, and specify their column names as they appear in database.
It would be much nicer for the regular
orderBy
to support this.Basically just an additional option in the
orderBy
method.Something like this would be great:
Outputs:
Outputs:
Of course, the reason for not using NULLS LAST here is because it would not work in all of the knex-supported databases. I believe this calculated criteria approach would, though.
The text was updated successfully, but these errors were encountered: