Closed abhiturbot closed 2 years ago
Hello @abhiturbot, nice to hear from you.
I find there are some misuses for this library:
You don't need to Find
before paginating, paginator will do that for you. You can remove .Find(&workspaces)
in first argument.
You should define order beside the paging key by Rule
, instead of on gorm DB instance, for example:
paginator.New(
&paginator.Config{
Rules: []paginator.Rule{
{
Key: "Type",
Order: paginator.ASC,
},
{
Key: "Handle",
Order: paginator.ASC,
},
{
Key: "IdentityWorkspaceHandle",
Order: paginator.ASC,
SQLRepr: "identity_workspace.handle",
},
},
},
)
Be careful that key name in Rule
is the field name on Workspace
model struct.
You can refer to usage by example section in README for more configuring details.
Hope these help. 😃
I would close this issue first. Feel free to reopen it for further discussion 😃
I was trying to do pagination by specifying order by clause
result, cursor, err := paginate(nextToken, limit, nil)(gormdb.Debug().Joins("Identity").Where("identity_id = ? OR identity_id IN (?)", userId, subQuery).Order("type, handle , identity_workspace.handle asc").Find(&workspaces), &workspaces)
The query formed from the above code is
I see a weird issue, it seems the results on the first page are correct, but on the second page, it returns duplicate rows.
For example Result in the first page with a limit of 4
Second page
The second page is returning
which is incorrect.