我正在使用包prisma-offset-pagination应用分页。为此,我必须在我的代码中使用Prisma模型,这是怎么可能的:检查行: 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,
});我试过使用下面的代码,但它没有工作,并引发了一个错误: UnhandledPromiseRejectionWarning: TypeError:无法读取未定义的prismaOffsetPagination属性'toLowerCase‘
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',
})发布于 2021-12-11 00:55:16
prismaOffsetPagination函数是这样的:
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,
},
});如您所见,model.name.toLowerCase()建议该模型是一个具有name属性的对象:model:{name:string}
基于此,对我来说,它可以在对象中传递模型的名称,如下所示:
const result = prismaOffsetPagination({
model: {name: 'user'}
cursor: <cursor>,
size: 5,
buttonNum: 7,
orderBy: 'id',
orderDirection: 'desc',
prisma: prisma,
});https://stackoverflow.com/questions/69252076
复制相似问题