Documentation ¶
Index ¶
- type OperatorType
- type SyntaxError
- type Term
- type Value
- func (v Value) AsBool() bool
- func (v Value) AsBoolList() []bool
- func (v Value) AsFloat() float64
- func (v Value) AsFloatList() []float64
- func (v Value) AsInt() int64
- func (v Value) AsIntList() []int64
- func (v Value) AsString() string
- func (v Value) AsStringList() []string
- func (v Value) AsTime() time.Time
- func (v Value) AsTimeList() []time.Time
- func (v Value) IsBool() bool
- func (v Value) IsBoolList() bool
- func (v Value) IsFloat() bool
- func (v Value) IsFloatList() bool
- func (v Value) IsInt() bool
- func (v Value) IsIntList() bool
- func (v Value) IsNull() bool
- func (v Value) IsString() bool
- func (v Value) IsStringList() bool
- func (v Value) IsTime() bool
- func (v Value) IsTimeList() bool
- func (v Value) Type() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OperatorType ¶
type OperatorType int
const ( Equals OperatorType = iota NotEquals Less LessOrEquals Greater GreaterOrEquals In NotIn Match NotMatch )
func (OperatorType) String ¶
func (o OperatorType) String() string
type SyntaxError ¶
type SyntaxError struct {
Message string
}
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type Term ¶
type Term struct { Attribute string Operator OperatorType Value Value }
Term ...
func Parse ¶
Parse filter string and returns list of Term
Example ¶
package main import ( "fmt" "strings" "github.com/doublecloud/transfer/library/go/yandex/cloud/filter" ) func main() { terms, err := filter.Parse("id != 1 anD status = 'Ok'") if err != nil { panic(err) } query := "SELECT * FROM table WHERE " var where []string for _, term := range terms { switch term.Attribute { case "id": // checks are skipped where = append(where, fmt.Sprintf("id != %d", term.Value.AsInt())) case "status": // checks are skipped where = append(where, fmt.Sprintf("status = %s", term.Value.AsString())) } } query += strings.Join(where, " AND ") fmt.Println(query) }
Output: SELECT * FROM table WHERE id != 1 AND status = Ok
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
func (Value) AsBoolList ¶
func (Value) AsFloatList ¶
func (Value) AsStringList ¶
func (Value) AsTimeList ¶
func (Value) IsBoolList ¶
func (Value) IsFloatList ¶
func (Value) IsStringList ¶
func (Value) IsTimeList ¶
Click to show internal directories.
Click to hide internal directories.