I use GORM and I paginate my data. I get n
rows each time. Unfortunately I need to compare row with previous one. Is there a way in GORM to fetch exclusive n
rows and one from previous call? When I set offset to n+1
it does not get that one previous row.
Example:
// page=1 limit=3
[
{
"id": 1,
"A": 12,
"B": 434,
},
{
"id": 2,
"A": 456,
"B": 786,
},
{
"id": 3,
"A": 23,
"B": 978,
}
]
// ... compare if A is equal in previous object and
return [{
"id": 1,
"A": 12,
"B": 434,
"isGreater": false,
},{
"id": 2,
"A": 456,
"B": 786,
"isGreater": true,
},{
"id": 3,
"A": 23,
"B": 978,
"isGreater": false,
}]
and
// page=2 limit=3
// from db fetch 4 rows
[
{
"id": 3,
"A": 12,
"B": 434,
},
{
"id": 4,
"A": 456,
"B": 786,
},
{
"id": 5,
"A": 23,
"B": 978,
},
{
"id": 6,
"A": 23445,
"B": 978,
}
]
// but return only 3
return [{
"id": 4,
"A": 12,
"B": 434,
"isGreater": false,
},{
"id": 5,
"A": 456,
"B": 786,
"isGreater": true,
},{
"id": 6,
"A": 23,
"B": 978,
"isGreater": true,
}]