Skip to content

Commit

Permalink
feat: seek and limit (#5)
Browse files Browse the repository at this point in the history
* feat: seek ident string

* feat: limit default value to 10
  • Loading branch information
suryakencana007 authored Sep 10, 2021
1 parent 08394f9 commit f392c39
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions select.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tyr

import (
"fmt"
"strconv"

"github.com/kubuskotak/tyr/dialect"
Expand Down Expand Up @@ -293,10 +294,13 @@ func (b *SelectStmt) Suffix(suffix string, value ...interface{}) *SelectStmt {
}

// Seek fetches a page in key set way for a large set of data.
func (b *SelectStmt) Seek(column string, cursor, limit uint64) *SelectStmt {
func (b *SelectStmt) Seek(col string, cursor, limit uint64) *SelectStmt {
if limit == 0 { // default limit
limit = 10
}
nextCursor := cursor + limit
b.Limit(limit)
b.WhereCond = append(b.WhereCond, And(Gt(column, cursor), Lte(column, nextCursor)))
b.WhereCond = append(b.WhereCond, Expr(fmt.Sprintf("%s > ? AND %s <= ?", col, col), cursor, nextCursor))
return b
}

Expand Down

0 comments on commit f392c39

Please sign in to comment.