```this.prismaService.brand.findMany({ where: ...
# orm-help
a
Copy code
this.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 ID
1
👀 1
n
Hey Adam 👋 thanks a lot for raising this! I’m checking with our Engineering team and will get back to you soon 🙂
a
Thank you, sorry for not making a github issue
n
All good, this is a valid question to raise here on Slack as well 🙂
Received this response from one of our Engineers btw:
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.
a
Hi, a simple implementation would be something like this
Copy code
SELECT * 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 confusion
n
Thanks for sharing! It would be great if you could record this desired behaviour in a feature request so that our Engineering team can evaluate this in the future 🙂
1