Adam Boulila
07/04/2022, 11:33 AMthis.prismaService.brand.findMany({
where: {
providerSKU: Providers.ccado,
},
cursor: {
id: body.cursor,
},
take: body.take ? body.take : DEFAULT_TAKE,
include: {
pdf: true,
variants: true,
},
orderBy: {
id: 'asc',
},
})
``````
with the following code snippet, if i supply a cursor.id
that is not available (example: cursor.id: 5
and 5 do not exist) in the database prisma returns nothing, even though there are elements before and after the unavailableId, is this by design or a bug, I would assume the default behavior is to start from the next available IDnikolasburk
Adam Boulila
07/12/2022, 7:55 AMnikolasburk
nikolasburk
This is by design. Data is fetched based on the cursor, if the cursor can’t be located then there’s no data to be fetched. I’m interested in what this user thinks an SQL or equivalent query should look like.
Adam Boulila
07/12/2022, 8:39 AMSELECT * FROM `Brand`
WHERE id >= 140
AND providerSKU='buybox'
ORDER BY id asc
LIMIT 10 OFFSET 0
This way even if the cursor does not exist we still retrieve the next records.
id >=140
is for the cursor
AND providerSKU='buybox'
is for the where
LIMIT 10
is for the take
OFFSET
is for the skip
however I am sure the code that is running under the hood for Prisma is more complex than this because if I specify a negative take
Prisma still somehow retrieves the records.
another alternative is simply adding to the docs if the cursor does not exist not data will be returned to avoid confusionnikolasburk