const results = await prisma.post.findMany({
skip: 3,
take: 4,
})
https://www.prisma.io/docs/static/2fd4a37fa5e3775c6510ff17279d6b6c/4c573/cursor-1.png
const secondQueryResults = await prisma.post.findMany({
take: 4,
skip: 1, //지정한 데이터부터 결과값 반환이 시작되기 때문에 하나의 데이터를 스킵해야만 함
// 커서 지정
cursor: {
id: myCursor,
},
where: {
title: {
contains: 'Prisma'
},
},
orderBy: {
id: 'asc',
},
})
const lastPostInResults = secondQueryResults[3];
const myCursor = lastPostInResults.id;
const myOldCursor = 200
const firstQueryResults = await prisma.post.findMany({
take: -4,
skip: 1,
cursor: {
id: myOldCursor,
},
where: {
title: {
contains: 'Prisma' /* Optional filter */,
},
},
orderBy: {
id: 'asc',
},
})
출처:
https://www.prisma.io/docs/concepts/components/prisma-client/pagination