Documentation
¶
Overview ¶
Package parse defines a parser for parsing SQL-formatted queries.
The SQL should be formatted as follows:
[[WHERE] <where condition>] [ORDER BY <sort order>] [LIMIT <limit>]
Note that prefixing the WHERE condition with "WHERE" is currently optional, although this might change in the future.
* <where condition>
The following types are supported:
string - surrounded by matching double- (") or single-quotes (')\ integer - must fit in an int64 or a uint64 float - must fit in a float64 boolean - TRUE or FALSE
The following standard SQL operators are supported:
=, != <, >, <=, >= IS, IS NOT IN, NOT IN BETWEEN, NOT BETWEEN AND OR
* <sort order>
This should be formatted
key1 [ASC | DESC], key2 [ASC | DESC], ..., keyn [ASC | DESC]
where ASC and DESC denote increasing and decreasing order, respectively. Precisely what this means is determined by the underlying storage engine and data type. If ASC or DESC is omitted, then ASC is assumed by default.
* <limit>
A non-negative integer (that must fit in an int64) must be provided.
Index ¶
- Constants
- func ParseTokensOrderBy(t *Tokeniser) (sort.OrderBy, error)
- func ParseTokensWhere(t *Tokeniser) (condition.Condition, error)
- func SQLOrderBy(s string) (sort.OrderBy, error)
- func SQLWhere(s string) (condition.Condition, error)
- type BoolToken
- type CommaToken
- type EOFToken
- type Float64Token
- type Int64Token
- type ParseError
- type Query
- type ScanError
- type Scanner
- type StringToken
- type Token
- type Tokeniser
- type Type
- type Uint64Token
- type WordToken
Constants ¶
const ( String = Type(iota) Int64 Uint64 Float64 True False OpenBracket CloseBracket Comma Where Is Eq Lt Gt Le Ge Ne Not And Or In Between Order By Asc Desc Limit EOF )
The valid token types.
Variables ¶
This section is empty.
Functions ¶
func ParseTokensOrderBy ¶
ParseTokensOrderBy parses a stream of tokens into a sort order.
func ParseTokensWhere ¶
ParseTokensWhere parses a stream of tokens into a condition.
func SQLOrderBy ¶
SQLOrderBy parses an SQL-formatted string into a sort order.
Types ¶
type BoolToken ¶
type BoolToken struct {
// contains filtered or unexported fields
}
BoolToken represents a boolean.
func (*BoolToken) FinishPosition ¶
func (t *BoolToken) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*BoolToken) StartPosition ¶
func (t *BoolToken) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.
type CommaToken ¶
type CommaToken struct {
// contains filtered or unexported fields
}
CommaToken represents a comma.
func (*CommaToken) FinishPosition ¶
func (t *CommaToken) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*CommaToken) IsValue ¶
func (*CommaToken) IsValue() bool
IsValue returns true if the token could represent a value.
func (*CommaToken) StartPosition ¶
func (t *CommaToken) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.
func (*CommaToken) String ¶
func (*CommaToken) String() string
String returns the token as a string.
type EOFToken ¶
type EOFToken struct {
// contains filtered or unexported fields
}
EOFToken represents the end of the stream.
func (*EOFToken) FinishPosition ¶
func (t *EOFToken) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*EOFToken) StartPosition ¶
func (t *EOFToken) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.
type Float64Token ¶
type Float64Token struct {
// contains filtered or unexported fields
}
Float64Token represents a float64.
func (*Float64Token) FinishPosition ¶
func (t *Float64Token) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*Float64Token) IsValue ¶
func (*Float64Token) IsValue() bool
IsValue returns true if the token could represent a value.
func (*Float64Token) StartPosition ¶
func (t *Float64Token) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.
func (*Float64Token) String ¶
func (t *Float64Token) String() string
String returns the token as a string.
func (*Float64Token) Value ¶
func (t *Float64Token) Value() interface{}
Value returns the value associated with this token.
type Int64Token ¶
type Int64Token struct {
// contains filtered or unexported fields
}
Int64Token represents an int64.
func (*Int64Token) FinishPosition ¶
func (t *Int64Token) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*Int64Token) IsValue ¶
func (*Int64Token) IsValue() bool
IsValue returns true if the token could represent a value.
func (*Int64Token) StartPosition ¶
func (t *Int64Token) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.
func (*Int64Token) String ¶
func (t *Int64Token) String() string
String returns the token as a string.
func (*Int64Token) Value ¶
func (t *Int64Token) Value() interface{}
Value returns the value associated with this token.
type ParseError ¶
ParseError represents an error whilst parsing input.
func (*ParseError) FinishPosition ¶
func (e *ParseError) FinishPosition() int
FinishPosition returns the finish position (inclusive) of the error in the input.
func (*ParseError) StartPosition ¶
func (e *ParseError) StartPosition() int
StartPosition returns the start position (inclusive) of the error in the input.
type Query ¶
type Query struct { Cond condition.Condition // The condition Order sort.OrderBy // The sort order HasLimit bool // Was a limit specified? Limit int64 // The limit }
Query describes a query.
func ParseTokens ¶
ParseTokens parses a stream of tokens into a query.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner allows for rune-by-rune reading of input.
func NewScanner ¶
NewScanner returns a new scanner wrapping the reader r.
type StringToken ¶
type StringToken struct {
// contains filtered or unexported fields
}
StringToken represents a string.
func (*StringToken) FinishPosition ¶
func (t *StringToken) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*StringToken) IsValue ¶
func (*StringToken) IsValue() bool
IsValue returns true if the token could represent a value.
func (*StringToken) StartPosition ¶
func (t *StringToken) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.
func (*StringToken) String ¶
func (t *StringToken) String() string
String returns the token as a string.
func (*StringToken) Value ¶
func (t *StringToken) Value() interface{}
Value returns the value associated with this token.
type Token ¶
type Token interface { // Type returns the token type. Type() Type // StartPosition returns the initial position (inclusive) of this token in // the stream. StartPosition() int // FinishPosition returns the final position (inclusive) of this token in // the stream. FinishPosition() int // IsValue returns true if the token could represent a value. IsValue() bool // Value returns the value associated with this token (if any). Value() interface{} }
Token is the interface describing a token.
type Tokeniser ¶
type Tokeniser struct {
// contains filtered or unexported fields
}
Tokeniser tokenises a scanner.
func NewTokeniser ¶
NewTokeniser returns a new tokeniser for the given scanner.
type Uint64Token ¶
type Uint64Token struct {
// contains filtered or unexported fields
}
Uint64Token represents a uint64.
func (*Uint64Token) FinishPosition ¶
func (t *Uint64Token) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*Uint64Token) IsValue ¶
func (*Uint64Token) IsValue() bool
IsValue returns true if the token could represent a value.
func (*Uint64Token) StartPosition ¶
func (t *Uint64Token) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.
func (*Uint64Token) String ¶
func (t *Uint64Token) String() string
String returns the token as a string.
func (*Uint64Token) Value ¶
func (t *Uint64Token) Value() interface{}
Value returns the value associated with this token.
type WordToken ¶
type WordToken struct {
// contains filtered or unexported fields
}
WordToken represents a reserved word.
func (*WordToken) FinishPosition ¶
func (t *WordToken) FinishPosition() int
FinishPosition returns the final position (inclusive) of this token in the stream.
func (*WordToken) StartPosition ¶
func (t *WordToken) StartPosition() int
StartPosition returns the initial position (inclusive) of this token in the stream.