woodpecker/vendor/github.com/woodpecker-ci/expr/selector.go
6543 75513575be
Use go's vendoring (#284)
* store dependency's in git

* since we vendor ... rm tech-depts

* aad make target 'vendor' to update vendor folder (manual task)
2021-08-30 19:14:04 +02:00

51 lines
1.4 KiB
Go

package expr
import "github.com/woodpecker-ci/expr/parse"
// Selector reprents a parsed SQL selector statement.
type Selector struct {
*parse.Tree
}
// Parse parses the SQL statement and returns a new Statement object.
func Parse(b []byte) (selector *Selector, err error) {
selector = new(Selector)
selector.Tree, err = parse.Parse(b)
return
}
// ParseString parses the SQL statement and returns a new Statement object.
func ParseString(s string) (selector *Selector, err error) {
return Parse([]byte(s))
}
// Eval evaluates the SQL statement using the provided data and returns true
// if all conditions are satisfied. If a runtime error is experiences a false
// value is returned along with an error message.
func (s *Selector) Eval(row Row) (match bool, err error) {
defer errRecover(&err)
state := &state{vars: row}
match = state.walk(s.Root)
return
}
// Row defines a row of columnar data.
//
// Note that the field name and field values are represented as []byte
// since stomp header names and values are represented as []byte to avoid
// extra allocations when converting from []byte to string.
type Row interface {
Field([]byte) []byte
}
// NewRow return a Row bound to a map of key value strings.
func NewRow(m map[string]string) Row {
return mapRow(m)
}
type mapRow map[string]string
func (m mapRow) Field(name []byte) []byte {
return []byte(m[string(name)])
}