Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@nodeteam/nestjs-prisma-pagination
Advanced tools
npm install --save @nodeteam/nestjs-prisma-pagination
// import paginators
import { paginator, searchPaginator } from '@nodeteam/nestjs-prisma-pagination';
// import types
import { PaginatorTypes } from '@nodeteam/nestjs-prisma-pagination';
page
- number of page
perPage
- number of records per page
Options can be redefined
{
data: T[],
meta: {
total: number,
lastPage: number,
currentPage: number,
perPage: number,
prev: number | null,
next: number | null,
},
}
Create new paginator function with default options
const paginate: PaginatorTypes.PaginateFunction = paginator({
page: 1,
perPage: 10,
});
full example:
import PrismaService from '@providers/prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import { PaginatorTypes, paginator } from '@nodeteam/nestjs-prisma-pagination';
const paginate: PaginatorTypes.PaginateFunction = paginator({ perPage: 10 });
@Injectable()
export default class UserService {
constructor(private prisma: PrismaService) {}
async findMany({ where, orderBy, pagination }: {
where?: Prisma.UserWhereInput,
orderBy?: Prisma.UserOrderByWithRelationInput
page?: number,
perPage?: number,
}): Promise<PaginatorTypes.PaginatedResult<User>> {
return paginate(
this.prisma.user,
{
where,
orderBy,
},
{
page,
perPage,
},
);
}
}
paginate(
this.prisma.user,
{
where,
orderBy,
},
{
page: 2, // Rendefine page
perPage: 5, // Rendefine perPage
},
);
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
const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({
page: 1,
perPage: 10,
});
full example:
import PrismaService from '@providers/prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import { PaginatorTypes, searchPaginator } from '@nodeteam/nestjs-prisma-pagination';
const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({ perPage: 10 });
@Injectable()
export default class UserService {
constructor(private prisma: PrismaService) {}
async searchUser({
page,
perPage,
skip,
searchValue
}: {
page: number,
perPage: number,
skip: number,
searchValue?: string,
}): Promise<PaginatorTypes.PaginatedResult<User>> {
const searchColumns = ['firstName', 'lastName', 'description'];
return searchPaginate(
this.prisma,
'User',
{
page,
perPage,
skip,
searchValue,
searchColumns,
},
);
}
}
searchPaginate(
this.prisma,
'User',
{
page: 2, // Rendefine page
perPage: 5, // Rendefine perPage
skip,
searchValue,
searchColumns,
},
);
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
FAQs
Paginators for Nest.JS app
The npm package @nodeteam/nestjs-prisma-pagination receives a total of 1,227 weekly downloads. As such, @nodeteam/nestjs-prisma-pagination popularity was classified as popular.
We found that @nodeteam/nestjs-prisma-pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.