Documentation
¶
Index ¶
- func BoolExpr(l *Lexer, be *BooleanExpression) bool
- func ColumnOrGroup(l *Lexer, stmt *Statement) bool
- func CompExpr(l *Lexer, be *BooleanExpression) bool
- func FromStmt(l *Lexer, stmt *Statement) bool
- func GetValue(s string) any
- func InCompExpr(l *Lexer, be *BooleanExpression, id string) bool
- func OptJoinStmt(l *Lexer, stmt *Statement) bool
- func OptWhereStmt(l *Lexer, stmt *Statement) bool
- func SelectStmt(l *Lexer, stmt *Statement) bool
- func SimpleCompExpr(l *Lexer, be *BooleanExpression, id string) bool
- type BooleanComposite
- type BooleanExpression
- type Column
- type Comparision
- type EmptyComparision
- type InComparision
- type Lexer
- type Statement
- func (stmt *Statement) GetGroup() (bson.D, error)
- func (stmt *Statement) GetLookup() (bson.D, error)
- func (stmt *Statement) GetSelect() (bson.D, error)
- func (stmt *Statement) IsAggregate() bool
- func (stmt *Statement) ToMongoAggregate() (mongo.Pipeline, error)
- func (stmt *Statement) ToMongoFind() (bson.D, bson.D, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolExpr ¶
func BoolExpr(l *Lexer, be *BooleanExpression) bool
BoolExpr -> CompExpr { BoolOp CompExpr } BoolOp -> <AND> | <OR>
func ColumnOrGroup ¶
ColumnOrGroup -> <ID> OptGroup OptGroup -> <(> <ID> <)> | eps
func CompExpr ¶
func CompExpr(l *Lexer, be *BooleanExpression) bool
CompExpr -> <(> BoolExpr <)> | InCompExpr | SimpleCompExpr
func InCompExpr ¶
func InCompExpr(l *Lexer, be *BooleanExpression, id string) bool
InCompExpr -> <ID> (<NOT> | eps) <IN> <(> ValueList <)> ValueList -> <ID> { <,> <ID> }
func OptJoinStmt ¶
OptJoinStmt -> <JOIN> <ID> <ON> <ID> <=> <ID> | eps
func OptWhereStmt ¶
OptWhereStmt -> <WHERE> BoolExpr | eps
func SelectStmt ¶
SelectStmt -> <SELECT> Columns Columns -> ColumnOrGroup { <,> ColumnOrGroup } | <*>
func SimpleCompExpr ¶
func SimpleCompExpr(l *Lexer, be *BooleanExpression, id string) bool
SimpleCompExpr -> <ID> CompOp <ID> | <ID> <IS> (<NOT> | eps) <NULL>
Types ¶
type BooleanComposite ¶
type BooleanComposite struct { BoolOp string SubExpr []BooleanExpression }
struct BooleanComposite represents a boolean expression with many sub boolean expressions and an operator joining them (such as AND or OR).
type BooleanExpression ¶
A BooleanExpression represents a parsed boolean comparision that can be converted to a mongoDB bson document given the tables related in the query (for _id management and joined table reference).
func ParseBoolExpr ¶
func ParseBoolExpr(sql string) (BooleanExpression, error)
ParseBoolExpr parses a boolean expression only, returning the describing BooleanExpression.
ParseBoolExpr -> BoolExpr
type Column ¶
struct Column represents a parsed SQL column (select entry), which is either an identifier or an identifier with a group function associated. Note that naming columns is not supported.
type Comparision ¶
struct Comparision represents a simple comparision such as "A > 10", having an identifier on the left, a value on the right, and a boolean operator.
type EmptyComparision ¶
type EmptyComparision struct{}
struct EmptyComparision represents a comparision that is always true
type InComparision ¶
struct InComparision represents a comparision using IN or NOT IN, such as "A IN (1, 2, 3, 4)".
type Lexer ¶
type Lexer struct { Value string // the current value read as a string Token rune // the current token mostly as returned from the scanner // contains filtered or unexported fields }
struct Lexer implements a simple lexer for the sqlparser using a text scanner.
type Statement ¶
type Statement struct { SelectColumn []Column FromTable string JoinTable string JoinFromAttr string JoinToAttr string Where BooleanExpression }
struct Statement represents a parsed SQL statement, with selection columns, a single origin table, a single (optional) joined table with a single join condition, and a filtering expression.
func Parse ¶
Parse parses an SQL string and returns the statement that describes it.
Parse -> SelectStmt FromStmt OptJoinStmt OptWhereStmt
func (*Statement) GetGroup ¶
GetGroup gets the document paired with the $group operator for a mongoDB aggregation for a Statement.
func (*Statement) GetLookup ¶
GetLookup gets the document paired with the $lookup operator for a mongoDB aggregation for a Statement.
func (*Statement) GetSelect ¶
GetSelect gets the bson representing the find key selection document, or the $project value in an aggregation pipeline.
func (*Statement) IsAggregate ¶
IsAggregate returns if the Statement is an aggregation or a find. A Statement is an aggregation only if it has either a join or a group function in it.
func (*Statement) ToMongoAggregate ¶
ToMongoAggregate gets the Pipeline representing an aggregation for a Statement.