()
| 274 | } |
| 275 | |
| 276 | func (pag *paginator) buildWithCursor() (*paginatorQuery, error) { |
| 277 | pq, err := immutable.FastForward(pag) |
| 278 | if err != nil { |
| 279 | return nil, err |
| 280 | } |
| 281 | |
| 282 | pqq := pq.(*paginatorQuery) |
| 283 | |
| 284 | if pqq.cursorReverseOrder { |
| 285 | orderBy := pqq.cursorColumn |
| 286 | |
| 287 | if orderBy == "" { |
| 288 | return nil, errMissingCursorColumn |
| 289 | } |
| 290 | |
| 291 | if strings.HasPrefix(orderBy, "-") { |
| 292 | orderBy = orderBy[1:] |
| 293 | } else { |
| 294 | orderBy = "-" + orderBy |
| 295 | } |
| 296 | |
| 297 | pqq.sel = pqq.sel.OrderBy(orderBy) |
| 298 | } |
| 299 | |
| 300 | if pqq.pageSize > 0 { |
| 301 | pqq.sel = pqq.sel.Limit(int(pqq.pageSize)) |
| 302 | if pqq.pageNumber > 1 { |
| 303 | pqq.sel = pqq.sel.Offset(int(pqq.pageSize * (pqq.pageNumber - 1))) |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if pqq.cursorCond != nil { |
| 308 | pqq.sel = pqq.sel.Where(pqq.cursorCond).Offset(0) |
| 309 | } |
| 310 | |
| 311 | if pqq.cursorColumn != "" { |
| 312 | if pqq.cursorReverseOrder { |
| 313 | pqq.sel = pqq.sel.(*selector).SQL(). |
| 314 | SelectFrom(db.Raw("? AS p0", pqq.sel)). |
| 315 | OrderBy(pqq.cursorColumn) |
| 316 | } else { |
| 317 | pqq.sel = pqq.sel.OrderBy(pqq.cursorColumn) |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | return pqq, nil |
| 322 | } |
| 323 | |
| 324 | func (pag *paginator) Prev() immutable.Immutable { |
| 325 | if pag == nil { |
no test coverage detected