Implement skipper interface

This commit is contained in:
Nikita Tokarchuk
2019-01-25 01:07:27 +01:00
parent 5a3ee358b5
commit 704ce76c11
5 changed files with 37 additions and 0 deletions
+2
View File
@@ -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
View File
@@ -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 {
+22
View File
@@ -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
}