sandrewtx08 / prisma-paginate Goto Github PK
View Code? Open in Web Editor NEWPaginate ORM Prisma
Home Page: https://sandrewtx08.github.io/prisma-paginate/
Paginate ORM Prisma
Home Page: https://sandrewtx08.github.io/prisma-paginate/
I open this issue #31 and change tsconfig works for me but its best if you can add support for nestjs and proper guide
Now in the extension description
// ESM
import { PrismaClient } from "@prisma/client";
import extension from "prisma-paginate";
// Commonjs
const { PrismaClient } = require("@prisma/client");
const { extension } = require("prisma-paginate");
But must be
// ESM
import { PrismaClient } from "@prisma/client";
import { extension } from "prisma-paginate";
// Commonjs
const { PrismaClient } = require("@prisma/client");
const { extension } = require("prisma-paginate");
If you use an include
directive in the paginate
call you get the following error:
PrismaClientValidationError:
Invalid `this.model.count()` invocation in
/Users/james/Code/console/node_modules/prisma-paginate/dist/paginator.js:18:24
15 const result = new Promise((resolve, reject) => {
16 const paginate = new paginate_1.Paginate(findManyArgs, Object.assign(Object.assign({}, findManyArgs), (typeof paginationOrCallback === "object" &&
17 paginationOrCallback)), new Paginator(this.model));
→ 18 this.model.count({
...snip
Please either use `include` or `select`, but not both at the same time.
This is because you can't use an include
in Prisma's count()
: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#count
We should strip out the include
param before passing it to count()
const prisma = new PrismaClient();
const paginate = paginator(prisma);
Just by adding that code it shows error
What's the use case for this option? As far as I can see it's just a workaround for incorrect rounding that is happening.
In paginate.ts
you're using Math.round
to calculate totalPages
; this should be Math.ceil
, you never want to be in a situation where you're not showing the last page of results because you rounded down.
I'm happy to raise a PR to fix this.
This lib has a cursor pagination
https://github.com/deptyped/prisma-extension-pagination
Do you think you will support and add cursor?
Hello Morning to you I got this weird behavior when Im using a library that uses native Response
When I console.log, I got this result and when I return it response json it strips out fields nextPage, hasNextPage, etc
{
limit: 5,
page: 1,
count: 6,
exceedCount: false,
exceedTotalPages: false,
result: [
{
id: 1
}, {
id: 2
}, {
id: 3
}, {
id: 4
}, {
id: 5
}
],
nextPage: [Function: nextPage],
hasNextPage: [Getter],
hasPrevPage: [Getter],
totalPages: [Getter]
}
... rather than in dependencies
in package.json
so that people are more flexible in which versions of Prisma they can use.
Hi! Thank you for amazing package!
I have a problem with types
import { Controller, Get, Query } from '@nestjs/common';
import { BrandService } from './brand.service';
import { PaginationRequestDto } from '../../common/dto/pagination-request.dto';
import paginator from 'prisma-paginate';
import { Brand } from '@prisma/client';
import PaginationResult = paginator.PaginationResult;
@Controller('brands')
export class BrandsController {
constructor(private readonly brandService: BrandService) {}
@Get()
async getAll(
@Query() query: PaginationRequestDto,
): Promise<PaginationResult<Brand>> {
return this.brandService.getAll(query);
}
}
But there is error:
TS2344: Type 'Brand' does not satisfy the constraint 'PrismaClientModel'. Type 'Brand' is missing the following properties from type 'PrismaClientModel': findMany, count
How can I fix it?
Hi,
When using pagination with NestJs it's necessary to code like this:
// prisma.service.ts
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
public readonly pagination;
constructor() {
super();
this.pagination = this.$extends(pagination);
}
async onModuleInit(): Promise<void> {
await this.$connect();
}
}
// in any repository class
findAll(id: string) {
return this.prismaService.pagination. // no type identification from here on
// expected: return this.prismaService.pagination.any_model.paginate({ limit: 10, page: 1})
}
But since pagination variable is not typed, when you try to use paginator, autocomplete is not generated anywhere, and also, any schema breakchanges are not detected by prisma.
Is It possible to add pagination types to this library?
Hi, i have try open page 4 and limit 10 with 33 data, but what appears is an error..?, which should output 3 data.
"pagination": {
"limit": 10,
"page": 4,
"count": 33, <-- The data here is 33, but when I access the 4th page which should display 3 data, but instead error: "Pagination exceed count of rows."
"exceedCount": true,
"exceedTotalPages": false,
"hasNextPage": false,
"hasPrevPage": true,
"totalPages": 4
}
Anyone have a solution?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@prisma/client
, prisma
)@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
).github/workflows/ci.yaml
actions/checkout v3
actions/setup-node v3
ubuntu 20.04
.github/workflows/documentation-release.yaml
actions/checkout v3
actions/setup-node v3
peaceiris/actions-gh-pages v3
.github/workflows/semantic-release.yaml
actions/checkout v3
actions/setup-node v3
package.json
@prisma/client >=5.7.1
@types/jest ^29.5.12
@types/node ^20.12.13
@typescript-eslint/eslint-plugin ^7.2.0
@typescript-eslint/parser ^7.2.0
eslint ^8.57.0
jest ^29.7.0
prisma >=5.7.1
ts-jest ^29.1.4
typedoc ^0.25.13
typescript ^5.4.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.