queryme

package
v0.0.0-...-c53d5a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2016 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func PredicateToSql(predicate Predicate, allowedFields []Field) (sql string, values []interface{})

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

func SortOrderToSql(sortOrder []*SortOrder, allowedFields []Field) (sql string)

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

type Eq struct {
	Field    Field
	Operands []Value
}

Eq is an equality predicate.

func (Eq) Accept

func (p Eq) Accept(visitor PredicateVisitor)

type Field

type Field string

A Field is the name of a field.

func Fields

func Fields(predicate Predicate) []Field

Fields returns all fields referenced in the predicate.

type Fts

type Fts struct {
	Field Field
	Query string
}

Ge is a full-text search comparison predicate.

func (Fts) Accept

func (p Fts) Accept(visitor PredicateVisitor)

type Ge

type Ge struct {
	Field   Field
	Operand Value
}

Ge is a greater or equal comparison predicate.

func (Ge) Accept

func (p Ge) Accept(visitor PredicateVisitor)

type Gt

type Gt struct {
	Field   Field
	Operand Value
}

Gt is a stricly greater comparison predicate.

func (Gt) Accept

func (p Gt) Accept(visitor PredicateVisitor)

type Le

type Le struct {
	Field   Field
	Operand Value
}

Le is a less or equal comparison predicate.

func (Le) Accept

func (p Le) Accept(visitor PredicateVisitor)

type Lt

type Lt struct {
	Field   Field
	Operand Value
}

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.

func (*QueryString) Raw

func (q *QueryString) Raw(name string) (string, bool)

Returns raw query string value.

func (*QueryString) SortOrder

func (q *QueryString) SortOrder(name string) (os []*SortOrder, err error)

Predicate parses the given component of the query as a sort order, then returns it.

type SortOrder

type SortOrder struct {
	Field     Field
	Ascending bool
}

A SortOrder is an ordering over a field.

type Value

type Value interface{}

A Value is any constant used in queries.

func ParseIdentifier

func ParseIdentifier(s string) (Value, error)

func ParseValue

func ParseValue(s string) (Value, error)

func ParseValues

func ParseValues(s string) ([]Value, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL