4

I have been using prisma-binding npm, I don't know how to get the total matched count of the query in order to perform pagination.

I'm using below code to pull record which working fine. Now i want total number of records.

const users = await prisma.query.users(null,`{id, name}`)

Note: By default prisma returns maximum of 3000 records only, but have 9000 records.

Thavaprakash Swaminathan
  • 6,226
  • 2
  • 30
  • 31

1 Answers1

3

You need to use the usersConnection query to get a count.

const count = await prisma.query.usersConnection({
  where: {
    // whatever your filter parameters are
  }
}, `{ aggregate { count } }`)

I haven't heard of this maximum returned records, but the usersConnection count is a single record being returned (the count), so that isn't an issue and as you want to do this for pagination I would imagine you would be returning at most 50 records at a time in your query.

Andrew1325
  • 3,519
  • 1
  • 14
  • 25