enkot / prisma-pagination

Helper library for Prisma offset pagination
https://www.npmjs.com/package/prisma-pagination
45 stars 5 forks source link

Unknown arg `page` #4

Open cakctus opened 1 year ago

cakctus commented 1 year ago

await paginate(await prisma.cars_model, { where: { cars_generation: { every: { cars_modification: { every: { body_type: { contains: bodyType, }, }, }, }, }, }, include: { cars_generation: { include: { cars_modification: { where: { body_type: { contains: bodyType, }, }, }, }, }, }, take: 10, skip: 0, page: page, }) Screenshot_8

I am trying to implement this code const result = await paginate<User, Prisma.UserFindManyArgs>( prisma.user, { where: { name: { contains: 'Alice' } } orderBy: { id: 'desc', } }, { page: query.page } })

smohammadhn commented 7 months ago

The paginate function takes three arguments.

first: only the model. (prisma.cars_model) second: findMany options. (only one object containing all the options except skip & take) ({ where, include, ... }) third: The pagination option which are ({ perPage: 10, page: 1})

await paginate(prisma.cars_model, {
  where: {
    cars_generation: {
      every: {
        cars_modification: {
          every: {
            body_type: {
              contains: bodyType,
            },
          },
        },
      },
    },
  },
  include: {
    cars_generation: {
      include: {
        cars_modification: {
          where: {
            body_type: {
              contains: bodyType,
            },
          },
        },
      },
    },
  },
},
{ page, perPage: 10}
)

Also, you don't need to await the first argument, it's just a reference to your model so that the paginate function later invokes .count and .findMany of it.