MCPcopy Index your code
hub / github.com/upper/db / buildWithCursor

Method buildWithCursor

internal/sqlbuilder/paginate.go:276–322  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

274}
275
276func (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
324func (pag *paginator) Prev() immutable.Immutable {
325 if pag == nil {

Callers 13

AllMethod · 0.95
OneMethod · 0.95
IteratorMethod · 0.95
IteratorContextMethod · 0.95
StringMethod · 0.95
ArgumentsMethod · 0.95
CompileMethod · 0.95
QueryMethod · 0.95
QueryContextMethod · 0.95
QueryRowMethod · 0.95
QueryRowContextMethod · 0.95
PrepareMethod · 0.95

Calls 8

FastForwardFunction · 0.92
RawMethod · 0.80
OrderByMethod · 0.65
LimitMethod · 0.65
OffsetMethod · 0.65
WhereMethod · 0.65
SelectFromMethod · 0.65
SQLMethod · 0.65

Tested by

no test coverage detected