5.2.1 ā€¢ Published 5 months ago

prisma-paginate v5.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

šŸ“– prisma-paginate

npm versionCIpages-build-deployment

Install

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

prisma/schema.prisma:

generator client {
  provider      = "prisma-client-js"
  previewFeatures = ["clientExtensions"]
}

āš ļø These steps no longer required for versions starting from 4.16.0

Documentation and usage

For more details and type definitions see:

http://sandrewtx08.github.io/prisma-paginate/

Importing

// ESM
import { PrismaClient } from "@prisma/client";
import extension from "prisma-paginate";

// Commonjs
const { PrismaClient } = require("@prisma/client");
const { extension } = require("prisma-paginate");

Applying extension

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({ where: { id: 5 } }, { limit: 10, page: 1 })
	.then((result) => {
		console.log(result);
	});

Paginating 100 rows

// 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 } ]
	});

Paginating SQL queries

const [{ count }] = await prisma.$queryRawUnsafe<[{ count: bigint }]>(
	'SELECT COUNT(*) FROM "Model3";',
);

const pagination = new Pagination(limit, page, Number(count));
const data = await prisma.$queryRawUnsafe<unknown[]>(
	'SELECT name FROM "Model3" LIMIT $1 OFFSET $2;',
	limit,
	Pagination.offset(limit, page),
);

Parameters

  • findManyArgs {Object}
  • paginationArgs {Pagination&onCount?(pagination) => void}

  • findManyPaginationArgs {Object&Pagination}

Return

  • result {Array}
  • totalPages {Number}
  • hasNextPage {Boolean}
  • hasPrevPage {Boolean}
  • count {Number}
  • nextPage {() => Promise}
  • exceedCount {Boolean}
  • exceedTotalPages {Boolean}
5.2.1

5 months ago

5.2.0

6 months ago

5.0.4

11 months ago

5.0.3

11 months ago

5.1.1

10 months ago

5.0.2

11 months ago

5.1.0

10 months ago

5.0.1

11 months ago

5.0.0

11 months ago

1.0.0

1 year ago

3.0.0

1 year ago

4.2.3

1 year ago

2.2.1

1 year ago

4.4.0

1 year ago

4.3.1

1 year ago

4.2.2

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

4.1.0

1 year ago

4.0.0

1 year ago

4.3.0

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago