Skip to content
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

orderBy: Make nulls: 'first' | 'last' available on non-nullable fields #19760

Open
Weakky opened this issue Jun 14, 2023 · 0 comments
Open

orderBy: Make nulls: 'first' | 'last' available on non-nullable fields #19760

Weakky opened this issue Jun 14, 2023 · 0 comments
Labels
kind/feature A request for a new feature. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: null topic: orderBy / sorting topic: orderByNulls `{ sort: 'asc', nulls: 'last' }` and similar

Comments

@Weakky
Copy link
Member

Weakky commented Jun 14, 2023

Overview

I'd like to request the behavior of generated types to change a little if possible. If I have a model such as

model Table {
   value: Decimal @db.Money
   otherValue: Decimal?
}

And I set the order by in a findMany for example as

...
prisma.table.findMany({
   orderBy: {
      value: { sort 'desc', nulls: 'last' }
   }
})

This currently results in an error whereas if I sort by otherValue it does not. The reason being that the generated type for the find many args of value is simply Prisma.SortOrder whereas for otherValue it is Prisma.SortOrderInput | Prisma.SortOrder. This is frustrating in my particular case because I'm using postgres, and I can simply pass the nulls argument directly to a non-nullable field, and things just work (I realize there's a no-op here):

select *
from Table
order by value asc
null first

It's nice to be able to pass this as a no op for the purposes of developing an api against a dataset using this feature. I want that api to have null order parameters where I can use this feature, but I now have to ensure that I'm only using this feature for specific fields and not others which results in a far greater code footprint, and of course as the schema evolves it will require changes to this larger code footprint, making my use of this feature kind of brittle.

tldr; can you have prisma generate Prisma.SortOrderInput | Prisma.SortOrder types for sortable field arguments regardless of whether the field is nullable or not?

Just some food for thought - not sure if it's possible or an easy change given you need to accommodate more rdbms than just postgres.

Originally posted by @ahammouda in #14377 (comment)

@Weakky Weakky added kind/feature A request for a new feature. tech/engines Issue for tech Engines. topic: null topic: orderBy / sorting topic: orderByNulls `{ sort: 'asc', nulls: 'last' }` and similar labels Jun 14, 2023
@janpio janpio changed the title Make nulls: 'first' | 'last' available on non-nullable fields orderBy: Make nulls: 'first' | 'last' available on non-nullable fields Jun 14, 2023
@Druue Druue added the team/client Issue for team Client. label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: null topic: orderBy / sorting topic: orderByNulls `{ sort: 'asc', nulls: 'last' }` and similar
Projects
None yet
Development

No branches or pull requests

2 participants