mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Implement skipper interface
This commit is contained in:
@@ -45,6 +45,8 @@ func applyLimits(q *Query, f interface{}) bool {
|
||||
q.limiter = f
|
||||
case Sorter:
|
||||
q.sorter = f
|
||||
case Skipper:
|
||||
q.skipper = f
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ type Query struct {
|
||||
m bson.M
|
||||
limiter Limiter
|
||||
sorter Sorter
|
||||
skipper Skipper
|
||||
}
|
||||
|
||||
// And function pushes the elem query to the $and array of the query
|
||||
@@ -52,6 +53,16 @@ func (q *Query) Sorter() interface{} {
|
||||
return q.sorter.Sort()
|
||||
}
|
||||
|
||||
// Skipper is a skipper for a query
|
||||
func (q *Query) Skipper() *int64 {
|
||||
|
||||
if q.skipper == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return q.skipper.Skip()
|
||||
}
|
||||
|
||||
// Empty checks the query for any content
|
||||
func (q *Query) Empty() bool {
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package query
|
||||
|
||||
// Skipper is a filter to skip the result
|
||||
type Skipper interface {
|
||||
Skip() *int64
|
||||
}
|
||||
|
||||
// Skip is a simple implementation of the Skipper filter
|
||||
type Skip int64
|
||||
|
||||
var _ Skipper = Skip(0)
|
||||
|
||||
// Skip returns a skip number
|
||||
func (l Skip) Skip() *int64 {
|
||||
|
||||
lim := int64(l)
|
||||
if lim <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &lim
|
||||
}
|
||||
Reference in New Issue
Block a user