Does anybody know if it’s possible (without a raw ...
# orm-help
d
Does anybody know if it’s possible (without a raw query) to use “tuple comparison” (I don’t know what it’s called) with Prisma? E.g. something that results in:
Copy code
select * from "foobar"
where ("foo", "bar", "baz") > ('lorem', 'ipsum', 'dolor')
r
you can maybe consider working with bitwise. it would make it very simple to do checks like that on the bits. the bitwise value would be mapped as Int in prisma schema. so in your queries you can just compare bits to check to the current bits.
d
Here’s my use case: I’m trying to implement cursor based pagination, where my cursors are UUIDs (v4 — not lexicographically sortable). This raw query works OK (the
id
and
createdAt
I’m comparing against are previously fetched):
Copy code
select
	id, "createdAt"
from
	"EventParticipant"
where
	"eventId" = 'b891c975-439a-4c64-ae73-48d2af411909'
and
	("createdAt", id) > ('2022-10-20 12:03:08.035', 'f4b41ba3-0be9-4a84-9acd-64810cddbe34')
order by
	"createdAt" asc,
	id asc
limit 100;
Ideally, I want to use
@prisma/client
and
findMany
, especially because the columns I’ll be sorting on will be dynamic/based on user input.
r
wait actually I'm not sure if that's a correct usage for your case... you can ignore my answer
in apllo graphql there is the @export directive which will allow you to use a value from a query result in another query. is this what you want sort of? is the issue here the sorting with the cursor? can you use "over partition" queries?
so I'm trying to understand the core issue here... is it the cursor with sorting or is the dynamic params?
d
The issue is that I don’t know how to rewrite the above pasted SQL query that uses “tuple comparison” into something that I can recreate/replicate with
findMany
. One step back, the reason why I have a need for “tuple comparisons” is because it’s the only way I’ve found to do cursor based pagination where I need to sort on one ore more non sequential columns.
…I know about the
cursor
property that
findMany
supports, but you can only use it for “unique” columns.
r
yeah... not too sure I can help you here. we are using mongo which doesn't have "cursor" issues. and take, skip are supported natively.
d
Ah, I can imagine it’s more straight forward there