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',
})
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,
});