Documentation ¶
Index ¶
Constants ¶
const ( UnknownQueryType = iota SelectQuery )
const ( SELECT = "SELECT" FROM = "FROM" WHERE = "WHERE" AS = "AS" OFFSET = "OFFSET" LIMIT = "LIMIT" EQ = "=" NE = "!=" GT = ">" LT = "<" GTE = ">=" LTE = "<=" AND = "AND" OR = "OR" LIKE = "LIKE" ILIKE = "ILIKE" ASTERISK = "*" COMMA = "," DOT = "." LP = "(" RP = ")" SC = ";" SQUOTE = '\'' MINUS = '-' ESCAPE = '\\' )
Reserved Words constants
Variables ¶
var ( ErrEmptyQuery = errors.New("empty query is invalid") ErrMissingTopic = errors.New("topic name cannot be empty") ErrUnhandledStep = errors.New("parser has reached an unhandled state") ErrNoFieldsSelected = errors.New("SELECT requires field projection or *") ErrInvalidSelectAllFields = errors.New("cannot select * and specify fields") ErrNonNumeric = errors.New("cannot parse non-numeric token as a number") )
var (
Empty = Token{"", EmptyToken, 0}
)
var ReservedWordType = map[string]TokenType{ SELECT: ReservedWord, FROM: ReservedWord, WHERE: ReservedWord, AS: ReservedWord, OFFSET: ReservedWord, LIMIT: ReservedWord, EQ: OperatorToken, NE: OperatorToken, GT: OperatorToken, LT: OperatorToken, GTE: OperatorToken, LTE: OperatorToken, AND: OperatorToken, OR: OperatorToken, LIKE: OperatorToken, ILIKE: OperatorToken, ASTERISK: Asterisk, COMMA: Punctuation, DOT: Punctuation, LP: Punctuation, RP: Punctuation, SC: Punctuation, }
var ReservedWords = []string{ SELECT, FROM, WHERE, AS, OFFSET, LIMIT, EQ, NE, GTE, LTE, GT, LT, AND, OR, LIKE, ILIKE, ASTERISK, COMMA, DOT, LP, RP, SC, }
NOTE: GT and LT must follow GTE and LTE in this list (or in general, any word that is a prefix of another word must follow that word to ensure parsing is correct).
Functions ¶
func InvalidState ¶
InvalidState is a developer error; it means that the parser proceeded to a step but modified the underlying state of the parsing incorrectly. This is not a user error, e.g. due to syntax, so invalid state usually panics.
Types ¶
type Query ¶
type Query struct { Type QueryType Topic Topic Conditions []Condition Fields []Token Aliases map[string]string Offset uint64 HasOffset bool Limit uint64 HasLimit bool Raw string }
Query is a parsed representation of an EnSQL statement that can be used to process EnSQL requests. All elements from the SQL statement must be represented in the query (including things like comments if supported by EnSQL). The raw sql is also available on the query for debugging purposes.
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
func Error ¶
func Error(pos int, near, msg string) *SyntaxError
func Errorf ¶
func Errorf(pos int, near, format string, args ...interface{}) *SyntaxError
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type Token ¶
A token represents a parsed element from the SQL and is returned from peek. The token string may not match the original string in the query (for example it might be uppercased or have quotations or whitespace stripped). When evaluating tokens, both the token type and the token itself should be used in concert to ensure correct normalization has occurred. The length is used to advance the parser index and may not match the length of the parsed token string.
func Tokenize ¶
Tokenize returns the tokens parsed from the input string with no validation or FSM. This function is primarily used by tests but can also be used by debugging tools to determine how a SQL query is being parsed.
func (Token) ParseFloat ¶
Parse a numeric token as a float using strconv.ParseFloat. Generally, the bitSize should be 64 (e.g. double) unless otherwise defined by the schema.