Documentation ¶
Overview ¶
Package parse is a simple sql lexer/parser with limited functionality it can handle queries like :
select fields from table where "field" = 'string' and (another_field=100 or boolean_field) order by field_1 desc , field_2 asc limit 10, 100
the result is some sort of abstract source tree :) the package is based on net/html and rob pike talk about writing lexer in go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTokenString ¶
GetTokenString is a simple function to handle the quoted strings, it remove the single or double quote from the string and remove escape sequence
Types ¶
type Field ¶
type Field struct { Table string // table name if it is a table field Alias string // alias if this has an alias (not supported yet) Item Item // Token Item, it can be alpha, string literal, number or bool Parameters Fields // Parameters is only valid for function fields }
Field is the fields inside select and functions, for functions the parameters is valid
type ItemType ¶
type ItemType int
ItemType is each lexeme type, also error and eof. any new keyword should be here first
const ( // ItemEOF eof is zero, so any data from closed channel (with zero value) is eof ItemEOF ItemType = iota // ItemError when there is an error ItemError // ItemWhiteSpace any whitespace sequence ItemWhiteSpace // ItemSelect sql select stmt ItemSelect // ItemFrom sql from stmt ItemFrom // ItemWhere sql where stmt ItemWhere // ItemOrder sql order stmt ItemOrder // ItemBy sql by stmt ItemBy // ItemOr sql or stmt ItemOr // ItemAnd sql and stmt ItemAnd // ItemIs sql is stmt ItemIs // ItemNull sql null stmt ItemNull // ItemNot sql not stmt ItemNot // ItemLimit sql limit stmt ItemLimit // ItemAsc sql asc stmt ItemAsc // ItemDesc sql desc stmt ItemDesc // ItemLike sql like stmt ItemLike // ItemAlpha is a string ItemAlpha // ItemNumber is a number ItemNumber // ItemFalse is the bool expression (false) ItemFalse // ItemTrue is the true ItemTrue // ItemEqual is = ItemEqual // ItemGreater is > ItemGreater // ItemLesser is < ItemLesser // ItemGreaterEqual is >= ItemGreaterEqual // ItemLesserEqual is <= ItemLesserEqual // ItemNotEqual is <> ItemNotEqual // ItemParenOpen is ( ItemParenOpen // ItemParenClose is ) ItemParenClose // ItemComma is , ItemComma // ItemWildCard is * ItemWildCard // ItemLiteral1 is 'string in single quote' ItemLiteral1 // ItemLiteral2 is "string in double quote" ItemLiteral2 // ItemSemicolon is ; ItemSemicolon // ItemDot is . ItemDot // ItemDollarSign is the $ followed by the number ItemQuestionMark // ItemFunc is the function ItemFunc )
type Order ¶
type Order struct { Field string // Field name Index int // Index in the actual table DESC bool // order asc or desc }
Order is one order in the order array
type Orders ¶
type Orders []Order
Orders group of orders, the first order is more important than the next
type SelectStmt ¶
type SelectStmt struct { Table string // Which table tos elect from Fields Fields // Which field are requested Where Stack // Where stack (need more work on where stack ) Order Orders // Orders in order part, if any Start int // the start column , -1 means no start specified Count int // the count to show, -1 means no count specified // contains filtered or unexported fields }
SelectStmt is the select query
func (*SelectStmt) ParamCount ¶
func (ss *SelectStmt) ParamCount() int
ParamCount return the number of parameters required for this