Git Product home page Git Product logo

prisma-paginate's People

Contributors

dependabot[bot] avatar jamesmoss avatar renovate[bot] avatar sandrewtx08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

prisma-paginate's Issues

Add Support for Nestjs

I open this issue #31 and change tsconfig works for me but its best if you can add support for nestjs and proper guide

Correct import of the extension for ESM

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");

Using `include` breaks pagination

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()

`strictLimit` seems to be unnecessary

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.

Pagination doesnt return nextPage, hasNextPage or any Getter

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]
}

Return type error

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?

Add typing for Prisma client with pagination extension

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?

Pagination exceed count of rows but totalPages: equal

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?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.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
npm
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

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.