1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00
ferret/pkg/runtime/expressions/clauses/limit.go
2018-09-18 16:42:38 -04:00

33 lines
679 B
Go

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)
}