npm i prisma@>=4.9.0 @prisma/client@>=4.9.0 prisma-paginate@latest
yarn add prisma@>=4.9.0 @prisma/client@>=4.9.0 prisma-paginate@latest
clientExtensions
preview flag on schema file
prisma/schema.prisma
:
generator client {
provider = "prisma-client-js"
previewFeatures = ["clientExtensions"]
}
For more details and type definitions see:
http://sandrewtx08.github.io/prisma-paginate/
// ESM
import { PrismaClient } from "@prisma/client";
import extension from "prisma-paginate";
// Commonjs
const { PrismaClient } = require("@prisma/client");
const { extension } = require("prisma-paginate");
const prisma = new PrismaClient();
const xprisma = prisma.$extends(extension);
xprisma.model2
.paginate({ limit: 10, page: 1, select: { id: true } })
.then((result) => {
console.log(result);
});
xprisma.table1
.paginate({ select: { id: true } }, { limit: 10, page: 1 })
.then((result) => {
console.log(result);
});
// on database = [ { id: 1 }, { id: 2 }, {...}, { id: 100 } ]
xprisma.model1
.paginate(
{
where: {
// query stuff...
},
},
{ page: 1, limit: 50 }
)
.then((result) => {
console.log(result.result); // [ {...}, { id: 48 }, { id: 49 }, { id: 50 } ]
});
findManyArgs
{Object}paginationArgs
{Pagination}
findManyPaginationArgs
{Object&Pagination}
result
{Array}totalPages
{Number} - Total of pages based on pagination argumentshasNextPage
{Boolean} - If has result on next page indexhasPrevPage
{Boolean} - If has result on last page indexcount
{Number} - Count how many rows on has on table/model with query filternextPage
{Promise} - Request next pageexceedCount
{Boolean}exceedTotalPages
{Boolean}