prisma-korea / prisma-offset-pagination

Offset Pagination based on cursor system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object

Cariaga opened this issue · comments

commented

import { prismaOffsetPagination } from 'prisma-offset-pagination';

      const result = await prismaOffsetPagination({
        model: {name: 'users'},     
        
        
        cursor:{id:'63772cff0146b66cc77c8f14'},//**problem here**
        size: 5, // Receive the number of row in the page
        buttonNum: 5,
        orderBy: 'id',
        orderDirection: 'asc',
        prisma: prisma,
    })

problem

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
    at new NodeError (node:internal/errors:371:5)
    at Function.from (node:buffer:323:9)

without the cursor parameter it returns all record... but how do I go to the next pageEdges?

{
    "pageEdges": [
        {
            "cursor": "c2FsdHlzYWx0NjM3NzJjZmYwMTQ2YjY2Y2M3N2M4ZjE0",
            "node": {
                "id": "63772cff0146b66cc77c8f14",
                "user_id": "63763d867fc8980e7f379eda",
                "created_at": "2022-11-18T06:58:07.676Z",
                "updated_at": "2022-11-18T06:58:07.676Z"
            }
        },
        {
            "cursor": "c2FsdHlzYWx0NjM3ODY1MjZjNzUwMmU5ZmJmMTFhNGJh",
            "node": {
                "id": "63786526c7502e9fbf11a4ba",
                "user_id": "63763d867fc8980e7f379eda",
                "created_at": "2022-11-19T05:09:58.101Z",
                "updated_at": "2022-11-19T05:09:58.101Z"
            }
        },
        {
            "cursor": "c2FsdHlzYWx0NjM3ODY1MmJjNzUwMmU5ZmJmMTFhNGJi",
            "node": {
                "id": "6378652bc7502e9fbf11a4bb",
                "user_id": "63763d867fc8980e7f379eda",
                "created_at": "2022-11-19T05:10:03.609Z",
                "updated_at": "2022-11-19T05:10:03.609Z"
            }
        },
        {
            "cursor": "c2FsdHlzYWx0NjM3ODY1MmZjNzUwMmU5ZmJmMTFhNGJj",
            "node": {
                "id": "6378652fc7502e9fbf11a4bc",
                "user_id": "63763d867fc8980e7f379eda",
                "created_at": "2022-11-19T05:10:07.512Z",
                "updated_at": "2022-11-19T05:10:07.512Z"
            }
        },
        {
            "cursor": "c2FsdHlzYWx0NjM3ODY1MzNjNzUwMmU5ZmJmMTFhNGJk",
            "node": {
                "id": "63786533c7502e9fbf11a4bd",
                "user_id": "63763d867fc8980e7f379eda",
                "created_at": "2022-11-19T05:10:11.296Z",
                "updated_at": "2022-11-19T05:10:11.296Z"
            }
        }
    ],
    "pageCursors": {
        "around": [
            {
                "cursor": "c2FsdHlzYWx0NjM3NzJjZmYwMTQ2YjY2Y2M3N2M4ZjE0",
                "page": 1,
                "isCurrent": true
            },
            {
                "cursor": "c2FsdHlzYWx0NjM3ODY1MzZjNzUwMmU5ZmJmMTFhNGJl",
                "page": 2,
                "isCurrent": false
            },
            {
                "cursor": "c2FsdHlzYWx0NjM3ODY1NDljNzUwMmU5ZmJmMTFhNGMz",
                "page": 3,
                "isCurrent": false
            },
            {
                "cursor": "c2FsdHlzYWx0NjM3ODY1NTljNzUwMmU5ZmJmMTFhNGM4",
                "page": 4,
                "isCurrent": false
            },
            {
                "cursor": "c2FsdHlzYWx0NjM3ODY1NzBjNzUwMmU5ZmJmMTFhNGNk",
                "page": 5,
                "isCurrent": false
            }
        ],
        "next": {
            "cursor": "c2FsdHlzYWx0NjM3ODY1MzZjNzUwMmU5ZmJmMTFhNGJl",
            "page": 2,
            "isCurrent": false
        }
    },
    "totalCount": 21
}

Your cursor must be a string, not an object

    const result = await prismaOffsetPagination({
        model: {name: 'users'},     
        cursor:'63772cff0146b66cc77c8f14',
        ...
    })