Documentation
¶
Index ¶
- Variables
- func PredicateToSql(predicate Predicate, allowedFields []Field) (sql string, values []interface{})
- func SortOrderToSql(sortOrder []*SortOrder, allowedFields []Field) (sql string)
- type And
- type Eq
- type Field
- type Fts
- type Ge
- type Gt
- type Le
- type Lt
- type Not
- type Or
- type Predicate
- type PredicateVisitor
- type QueryString
- type SortOrder
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( SortOrderSeparatorExpected error = errors.New("Expected seperator ',' after sorted order.") IdentifierExpected error = errors.New("Expected identifier.") ValueExpected error = errors.New("Expected value.") EndOfStringExpected error = errors.New("Expected end of string.") StringExpected error = errors.New("Expected string.") OperatorExpected error = errors.New("Expected operator.") UnexpectedEndOfPredicate error = errors.New("Unexpected end of predicate.") UnexpectedEndOfSortOrders error = errors.New("Unexpected end of sort orders.") )
Functions ¶
func PredicateToSql ¶
PredicateToSql converts a Predicate to its equivalent SQL form and extracts constant to a seperate array. Each referenced field is matched against a list of allowed fields.
func SortOrderToSql ¶
SortOrderToSql converts an array of SortOrder to its equivalent SQL form. Each referenced field is matched against a list of allowed fields.
Types ¶
type And ¶
type And []Predicate
And is a conjunction predicate.
func (And) Accept ¶
func (p And) Accept(visitor PredicateVisitor)
type Eq ¶
Eq is an equality predicate.
func (Eq) Accept ¶
func (p Eq) Accept(visitor PredicateVisitor)
type Fts ¶
Ge is a full-text search comparison predicate.
func (Fts) Accept ¶
func (p Fts) Accept(visitor PredicateVisitor)
type Ge ¶
Ge is a greater or equal comparison predicate.
func (Ge) Accept ¶
func (p Ge) Accept(visitor PredicateVisitor)
type Gt ¶
Gt is a stricly greater comparison predicate.
func (Gt) Accept ¶
func (p Gt) Accept(visitor PredicateVisitor)
type Le ¶
Le is a less or equal comparison predicate.
func (Le) Accept ¶
func (p Le) Accept(visitor PredicateVisitor)
type Lt ¶
Lt is a strictly less comparison predicate.
func (Lt) Accept ¶
func (p Lt) Accept(visitor PredicateVisitor)
type Not ¶
type Not struct {
Operand Predicate
}
Not is a negation predicate.
func (Not) Accept ¶
func (p Not) Accept(visitor PredicateVisitor)
type Or ¶
type Or []Predicate
Or is a disjunction predicate.
func (Or) Accept ¶
func (p Or) Accept(visitor PredicateVisitor)
type Predicate ¶
type Predicate interface { // Accept implements the visitor pattern for predicates. Accept(visitor PredicateVisitor) }
A Predicate is an expression that can is evaluated as either true or false.
type PredicateVisitor ¶
type PredicateVisitor interface { // VisitNot is called to visit a negation predicate. VisitNot(operand Predicate) // VisitAnd is called to visit a conjunction predicate. VisitAnd(operands []Predicate) // VisitOr is called to visit a disjunction predicate. VisitOr(operands []Predicate) // VisitEq is called to visit an equality predicate. VisitEq(field Field, operands []Value) // VisitLt is called to visit a stricly less than comparison predicate. VisitLt(field Field, operand Value) // VisitLe is called to visit a less or equal comparison predicate. VisitLe(field Field, operand Value) // VisitLe is called to visit a stricly greater comparison predicate. VisitGt(field Field, operand Value) // VisitLe is called to visit a greater or equal comparison predicate. VisitGe(field Field, operand Value) // VisitLe is called to visit a full-text search predicate. VisitFts(field Field, query string) }
PredicateVisitor is an object which can visit any kind of predicate.
type QueryString ¶
type QueryString struct {
// contains filtered or unexported fields
}
QueryString is a parsed query part of a URL.
func NewFromRawQuery ¶
func NewFromRawQuery(rawQuery string) *QueryString
NewFromRawQuery creates a new QueryString from a raw query string.
func NewFromURL ¶
func NewFromURL(url *url.URL) *QueryString
NewFromRawQuery creates a new QueryString from an existing URL object.
func (*QueryString) Contains ¶
func (q *QueryString) Contains(name string) bool
Tests if specified name has been found in query string.
func (*QueryString) Predicate ¶
func (q *QueryString) Predicate(name string) (p Predicate, err error)
Predicate parses the given component of the query as a predicate, then returns it.