mswjs / data

Data modeling and relation library for testing JavaScript applications.

Home Page:https://npm.im/@mswjs/data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support both pagination and total results count

kettanaito opened this issue · comments

It should be possible to paginate the results of .findMany() but expose the total count of results for the query.

I suggest extending the .count() model method to accept a query. If given a query, the .count() method would filter the database based on that query and return the count of records matching it.

const filter = { pagesCount: { gte: 500 } }

// Returns 5 books of the second page.
const paginagedResults = db.book.findMany({
  which: filter,
  take: 5,
  offset: 10,
})

// Returns the total amount of books that match the `filter` query.
const totalBooks = db.book.count(filter)