1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/runtime/expressions/clauses/limit.go

33 lines
679 B
Go
Raw Normal View History

2018-09-18 22:42:38 +02:00
package clauses
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/collections"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
type LimitClause struct {
*baseClause
count int
offset int
}
func NewLimitClause(
src core.SourceMap,
dataSource collections.IterableExpression,
count int,
offset int,
) *LimitClause {
return &LimitClause{&baseClause{src, dataSource}, count, offset}
}
func (clause *LimitClause) Iterate(ctx context.Context, scope *core.Scope) (collections.Iterator, error) {
src, err := clause.dataSource.Iterate(ctx, scope)
if err != nil {
return nil, err
}
return collections.NewLimitIterator(src, clause.count, clause.offset)
}