typeorm-cursor-pagination icon indicating copy to clipboard operation
typeorm-cursor-pagination copied to clipboard

Nullable number columns not supported for sorting

Open jkalberer opened this issue 2 years ago • 4 comments

I can work on a PR for this feature but do you have any idea on the best way I should go about implementing this?

jkalberer avatar Jan 17 '23 21:01 jkalberer

Could you share the entity that was trying to sort?

benjamin658 avatar Jan 30 '23 01:01 benjamin658

Yeah, i have a numerical column that is nullable. I'll can get you an entity but it's just a really basic column that fails to serialize when the value is null.

Looking at the logic for this I'm not even sure that a integer column would paginate correctly unless you sorted by multiple columns. If there were many rows with the same value, it would skip over them. Please correct me here if I'm wrong.

jkalberer avatar Jan 30 '23 14:01 jkalberer

You have to use an unique column as the pagination key.

benjamin658 avatar Feb 01 '23 06:02 benjamin658

In this case I have an entity like:

class Entity {
  @Column({ nullable: true })
  value: number | null;
  
  @CreateDateColumn({ type: 'timestamptz' })
  created: Date;
}

I should be able to do a sort like (for postgres) ORDER BY value DESC NULLS LAST, created DESC

The problem is that the parsing of nulls is still busted for this use-case.

jkalberer avatar Feb 01 '23 17:02 jkalberer