I am using a package prisma-offset-pagination to a...
# orm-help
i
I am using a package prisma-offset-pagination to apply pagination. In this I have to use Prisma Model in my code , how is that possible:
const result = prismaOffsetPagination({
model: User,   // How to access prisma model like in this example.
cursor: <cursor>,
size: 5,
buttonNum: 7,
orderBy: 'id',
orderDirection: 'desc',
where: {
email: {
contains: 'smallbee',
},
},
prisma: prisma,
});
Check Line:2
j
did you tried
import { User } from '@prisma/client'
? See the code https://github.com/prisma-korea/prisma-offset-pagination/blob/master/src/paginator/pageEdge.ts#L77
i
Didn't work.
@Ryan 👋 Please guide.
r
Copy code
const result = prismaOffsetPagination({
    model: 'User', 
    cursor: <cursor>,
    size: 5,
    buttonNum: 7,
    orderBy: 'id',
    orderDirection: 'desc',
    where: {
      email: {
        contains: 'smallbee',
      },
    },
    prisma: prisma,
});
Try this.
i
Already tried this in beginning but it failed. Throws an error : UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toLowerCase' of undefined at prismaOffsetPagination
r
Add User in quotes like this:
'User'
i
const result = _prismaOffsetPagination_({     _model_:_ _'Post',     _cursor_:_ _2,     _size_:_ _5,     _buttonNum_:_ _3,     _orderBy_:_ _'id',     _orderDirection_:_ _'desc', _  _}) I have used single quotes but no effect.
r
This works:
Copy code
const result = await prismaOffsetPagination({
    model: { name: 'Post' },
    size: 5,
    orderBy: 'id',
    orderDirection: 'desc',
    prisma,
  })
i
Thanks @Ryan Atleast it worked without the error which it throws before. But as you know Im already stuck in the failure of prisma.post.count() query. Inside the code of prisma-offset-pagination ,the count() method is used multiple times. Ultimately it throws the error I already mentioned in the seperate thread : UnhandledPromiseRejectionWarning: Error: Invalid
prisma.post.aggregate()
invocation: Failed to validate the query:
Field does not exist on enclosing type.
at
Query.aggregatepost.AggregatePost._count
I have submitted the issue of .count( ). The issue id is #9340
👍 1
Hi, @Ryan 👋 Please update me on this issue.
r
It works fine for me with the above with count so this would be specific to your system. We will be looking into this.