2016-10-17 07:14:01 +03:00
|
|
|
package ast
|
|
|
|
|
2020-08-23 14:16:16 +03:00
|
|
|
import "github.com/neilotoole/sq/libsq/ast/internal/slq"
|
2016-10-17 07:14:01 +03:00
|
|
|
|
2020-08-06 20:58:47 +03:00
|
|
|
// RowRange models a range, effectively {OFFSET,LIMIT}.
|
2016-10-17 07:14:01 +03:00
|
|
|
type RowRange struct {
|
2020-08-06 20:58:47 +03:00
|
|
|
baseNode
|
2016-10-17 07:14:01 +03:00
|
|
|
Offset int
|
|
|
|
Limit int
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:58:47 +03:00
|
|
|
func newRowRange(ctx *slq.RowRangeContext, offset, limit int) *RowRange {
|
2016-10-17 07:14:01 +03:00
|
|
|
rr := &RowRange{}
|
|
|
|
rr.ctx = ctx
|
|
|
|
rr.Offset = offset
|
|
|
|
rr.Limit = limit
|
|
|
|
return rr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rr *RowRange) String() string {
|
|
|
|
return rr.Text()
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:58:47 +03:00
|
|
|
func (rr *RowRange) Range() (offset, limit int) {
|
2016-10-17 07:14:01 +03:00
|
|
|
offset = rr.Offset
|
|
|
|
limit = rr.Limit
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rr *RowRange) SetParent(parent Node) error {
|
|
|
|
seg, ok := parent.(*Segment)
|
|
|
|
if !ok {
|
2020-08-06 20:58:47 +03:00
|
|
|
return errorf("%T requires parent of type *%s", rr, typeSegment)
|
2016-10-17 07:14:01 +03:00
|
|
|
}
|
|
|
|
rr.parent = seg
|
|
|
|
return nil
|
|
|
|
}
|