Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
How to import Prisma model in prisma-offset-pagination

I am using a package prisma-offset-pagination to apply pagination. For this I have to use Prisma Model in my code, how is that possible: Check line: 02

const result = prismaOffsetPagination({
    model: user,   // How to access prisma model like in this example.
    cursor: <cursor>,
    size: 5,
    buttonNum: 7,
    orderBy: 'id',
    orderDirection: 'desc',
    prisma: prisma,
});

I tried it using the code below but it didn't work and throws an error : UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toLowerCase' of undefined at prismaOffsetPagination

import pClient from '@prisma/client'
const { PrismaClient } = pClient
const { prisma } = new PrismaClient()

  const result = prismaOffsetPagination({
    model: prisma.user,
    cursor: 2,
    size: 5,
    buttonNum: 3,
    orderBy: 'id',
    orderDirection: 'desc',
  })
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is how prismaOffsetPagination function looks like:

export async function prismaOffsetPagination({
  model,
  cursor,
  size,
  buttonNum,
  orderBy,
  orderDirection,
  include,
  where,
  prisma,
}: Props<typeof model>): Promise<PaginationType> {
  // totalCount
  const prismaModel = prisma[model.name.toLowerCase()];
  const totalCount = await prismaModel.count({
    where: {
      ...where,
    },
  });

As you can see, model.name.toLowerCase() suggests that model is an object with a name property: model:{name:string}

Based on this, for me it worked passing the name of the model inside the object, as follows:

const result = prismaOffsetPagination({
    model: {name: 'user'}
    cursor: <cursor>,
    size: 5,
    buttonNum: 7,
    orderBy: 'id',
    orderDirection: 'desc',
    prisma: prisma,
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda