Greater/Less than comparators for strings #244
-
|
We have a use case where we're building the ability to navigate backwards with cursor-based pagination. To facilitate sorting, we need a way to do a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
Hey, @ericchernuka. Thanks for the proposal. How would you implement these new comparators? Simply as I don't like the semantics breach that happens when we handle strings this way, to be honest. I'd much prefer to go with something like |
Beta Was this translation helpful? Give feedback.
-
UpdateSince v1.0, you can implement your own comparators (in fact, the library no longer ships any built-in comparators at all). This is how you get a gt/lt comparator for strings: const users = new Collection({
schema: z.object({
firstName: z.string(),
lastName: z.string(),
}),
})
users.findFirst((q) => q.where({
firstName: (firstName) => firstName > 'Alice',
lastName: (lastName) => lastName < 'Doe',
})) |
Beta Was this translation helpful? Give feedback.
Update
Since v1.0, you can implement your own comparators (in fact, the library no longer ships any built-in comparators at all). This is how you get a gt/lt comparator for strings: