Gathering detailed insights and metrics for @nodeteam/nestjs-prisma-pagination
Gathering detailed insights and metrics for @nodeteam/nestjs-prisma-pagination
Gathering detailed insights and metrics for @nodeteam/nestjs-prisma-pagination
Gathering detailed insights and metrics for @nodeteam/nestjs-prisma-pagination
npm install @nodeteam/nestjs-prisma-pagination
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
24 Stars
19 Commits
8 Forks
2 Watching
2 Branches
4 Contributors
Updated on 13 Nov 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
66.7%
315
Compared to previous day
Last week
20.4%
1,476
Compared to previous week
Last month
2%
5,505
Compared to previous month
Last year
475.7%
38,735
Compared to previous year
1npm install --save @nodeteam/nestjs-prisma-pagination
1// import paginators 2import { paginator, searchPaginator } from '@nodeteam/nestjs-prisma-pagination'; 3// import types 4import { PaginatorTypes } from '@nodeteam/nestjs-prisma-pagination';
page
- number of page
perPage
- number of records per page
Options can be redefined
1{ 2 data: T[], 3 meta: { 4 total: number, 5 lastPage: number, 6 currentPage: number, 7 perPage: number, 8 prev: number | null, 9 next: number | null, 10 }, 11}
Create new paginator function with default options
1const paginate: PaginatorTypes.PaginateFunction = paginator({ 2 page: 1, 3 perPage: 10, 4});
full example:
1import PrismaService from '@providers/prisma/prisma.service'; 2import { Injectable } from '@nestjs/common'; 3import { PaginatorTypes, paginator } from '@nodeteam/nestjs-prisma-pagination'; 4 5const paginate: PaginatorTypes.PaginateFunction = paginator({ perPage: 10 }); 6 7@Injectable() 8export default class UserService { 9 constructor(private prisma: PrismaService) {} 10 11 async findMany({ where, orderBy, pagination }: { 12 where?: Prisma.UserWhereInput, 13 orderBy?: Prisma.UserOrderByWithRelationInput 14 page?: number, 15 perPage?: number, 16 }): Promise<PaginatorTypes.PaginatedResult<User>> { 17 return paginate( 18 this.prisma.user, 19 { 20 where, 21 orderBy, 22 }, 23 { 24 page, 25 perPage, 26 }, 27 ); 28 } 29}
1 paginate( 2 this.prisma.user, 3 { 4 where, 5 orderBy, 6 }, 7 { 8 page: 2, // Rendefine page 9 perPage: 5, // Rendefine perPage 10 }, 11 );
https://exmaple.com/api/v1/user?page=1&where=Jake
page
- number of page
perPage
- number of records per page
skip
- number of records to skip
searchColumns
- array of columns in db
searchValue
- string to search
Options can be redefined
model
- PrismaClient['modelName']
modelName
- Name of model
create new search paginator function with default options
1const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({ 2 page: 1, 3 perPage: 10, 4});
full example:
1import PrismaService from '@providers/prisma/prisma.service'; 2import { Injectable } from '@nestjs/common'; 3import { PaginatorTypes, searchPaginator } from '@nodeteam/nestjs-prisma-pagination'; 4 5const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({ perPage: 10 }); 6 7@Injectable() 8export default class UserService { 9 constructor(private prisma: PrismaService) {} 10 11 async searchUser({ 12 page, 13 perPage, 14 skip, 15 searchValue 16 }: { 17 page: number, 18 perPage: number, 19 skip: number, 20 searchValue?: string, 21 }): Promise<PaginatorTypes.PaginatedResult<User>> { 22 const searchColumns = ['firstName', 'lastName', 'description']; 23 24 return searchPaginate( 25 this.prisma, 26 'User', 27 { 28 page, 29 perPage, 30 skip, 31 searchValue, 32 searchColumns, 33 }, 34 ); 35 } 36}
1 searchPaginate( 2 this.prisma, 3 'User', 4 { 5 page: 2, // Rendefine page 6 perPage: 5, // Rendefine perPage 7 skip, 8 searchValue, 9 searchColumns, 10 }, 11 );
https://example.com/api/v1/users/full-text/search?search=Lions&page=1
getPagination
options:rawPage
- number of page (optional)
rawPerPage
- number of records per page (optional)
const result = getPagination(1, 10);
result => {
perPage: 10,
page: 1,
skip: 0,
};
getPaginatedResult
options:data
- array of entities
pagination
- page, perPage, skip
count
- total count
const result = getPaginatedResult({
data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
pagination: {
page: 1,
perPage: 10,
skip: 0,
},
count: 100,
});
result => {
data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
meta: {
total: 100,
lastPage: 10,
currentPage: 1,
perPage: 10,
prev: 0,
next: 1,
},
};
Check useful npm packages from NodeTeam: https://www.npmjs.com/org/nodeteam
No vulnerabilities found.
No security vulnerabilities found.