Registry / database / prisma-paginate-extension

prisma-paginate-extension

JSON →
library0.2.1jsnpmunverified

A pagination extension for Prisma ORM that adds a convenient `paginate()` method to Prisma client instances. Version 0.2.1, released in 2023, with weekly updates. It integrates via Prisma's `$extends` API (≥4.9.0), supports both combined and separate arguments, works with raw SQL via a `Pagination` utility, and returns `result`, `totalPages`, `hasNextPage`, `hasPrevPage`, and `count`. Unlike wrapper libraries, it uses the official extension mechanism, making it compatible with future Prisma versions and TypeScript types.

npm install prisma-paginate-extension
INSTALL
IMPORT
SIG · PRISMA-PAGINATE-EX
P
prisma-paginate-extension
databasejavascriptv0.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PrismaPaginate
import PrismaPaginate from 'prisma-paginate-extension'
import { PrismaPaginate } from 'prisma-paginate-extension'
Default export — do not use named import. TypeScript types are included.
Pagination
import { Pagination } from 'prisma-paginate-extension'
import Pagination from 'prisma-paginate-extension'
Named export for raw SQL utility class. Named import is correct.
PrismaClient
import { PrismaClient } from '@prisma/client'
const { PrismaClient } = require('@prisma/client')
Prisma client is a separate package. CommonJS works but ESM is recommended.

Basic setup: create a Prisma client, extend it with PrismaPaginate, and run a paginated query with where filter and pagination args.

import { PrismaClient } from '@prisma/client'; import PrismaPaginate from 'prisma-paginate-extension'; const prisma = new PrismaClient(); const xprisma = prisma.$extends(PrismaPaginate); async function main() { const result = await xprisma.user.paginate( { where: { active: true } }, { page: 1, limit: 10 } ); console.log(result.result, result.totalPages, result.hasNextPage); } main().then(() => prisma.$disconnect());
Debug
Known issues
breakingVersion 0.2.0 changed the return type: `totalPages` is now always a number, not `null` when count is unknown. Existing code checking `if (result.totalPages === null)` will break.
fix
Update logic: `totalPages` is always a number. Use `result.count` for unknown counts.
affects: <0.2.0
breakingIn versions <0.1.0, the extension was called via `prisma.paginate()` instead of `prisma.$extends(PrismaPaginate)`. Direct upgrade breaks without migrating to $extends.
fix
Use `prisma.$extends(PrismaPaginate)` to create an extended client. The method is available on the extended client, not the original PrismaClient.
affects: <0.1.0
gotchaThe `paginate` method is only available on the extended client instance (e.g., `xprisma`), not on the original `prisma`. Calling `prisma.user.paginate()` will fail.
fix
Always call `prisma.$extends(PrismaPaginate)` first and use the resulting client.
affects: >=0.1.0
gotchaWhen using the combined arguments overload, do not include `page` and `limit` inside the `findManyArgs` object. They must be at the top level.
fix
Pass pagination args as separate properties or as second argument. Example: `paginate({ where: {} }, { page: 1, limit: 10 })`
affects: >=0.1.0
gotchaThe `onCount` callback receives a `Pagination` instance, not the raw count. Access the count via `pagination.count` inside the callback.
fix
If you need the count inside `onCount`, read `pagination.count` (a number). The `Pagination` object also has `offset()` and `limit()` methods.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: prisma.user.paginate is not a function
Called paginate on the original prisma instance instead of the extended one.
fix
Create extended client: `const xprisma = prisma.$extends(PrismaPaginate);` then use `xprisma.user.paginate()`.
Cannot find module 'prisma-paginate-extension' or its corresponding type declarations.
Missing TypeScript types or incorrect import path. The package ships types, but the import must be correct.
fix
Install the package: `npm install prisma-paginate-extension`. Import as default: `import PrismaPaginate from 'prisma-paginate-extension';`.
Property 'paginate' does not exist on type 'PrismaClient<...>'
TypeScript expects the extended client schema. Using the original PrismaClient type.
fix
Define type for extended client: `import { PrismaClient } from '@prisma/client'; import PrismaPaginate from 'prisma-paginate-extension'; type ExtendedPrismaClient = ReturnType<typeof PrismaClient['prototype']['$extends']>;` Or use a type assertion.
PrismaClientInitializationError: PrismaClient is not yet instantiated.
Trying to use the client before it's initialized (e.g., in a top-level await without proper async context).
fix
Ensure prisma instantiation and $extends happen in an async function or module scope with top-level await support.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
@prisma/clientrequiredPeer dependency — extension requires Prisma client version ≥4.9.0 for $extends functionality
prismaoptionalPeer dependency — required for development/generation, but not at runtime
Agent activity
7 hits · last 30 days
node
6
Bingbot
1
Resources
prisma-paginate-extension — npm install prisma-paginate-extension · libregistry