Documentation
¶
Index ¶
- Constants
- type Condition
- type Const
- type Dialect
- type Expression
- type Function
- type OrCondition
- type Param
- type Translator
- func (tr Translator) Condition2Sql(sb *strings.Builder, c *Condition) error
- func (tr Translator) Expression2Sql(sb *strings.Builder, e *Expression) error
- func (tr Translator) OrCondition2Sql(sb *strings.Builder, oc *OrCondition) error
- func (tr Translator) Param2Sql(sb *strings.Builder, p *Param) error
- func (tr Translator) Params2Sql(sb *strings.Builder, prms []*Param) error
- func (tr Translator) XCondition2Sql(sb *strings.Builder, xc *XCondition) error
- type XCondition
Constants ¶
const ( StringParamID = "__string__" NumberParamID = "__number__" ArrayParamID = "__array__" // PfLValue the parameter can be a lvalue in the condition PfLValue = 1 << 0 // PfRValue the parameter can be a rvalue in the condition PfRValue = 1 << 1 // PfNop the parameter cannot have any operation PfNop = 1 << 2 // PfComparable the parameter can be compared: <, >, !=, =, >=, <= PfComparable = 1 << 3 // PfInArray the IN operation is allowed for the param PfInArray = 1 << 4 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition struct {
FirstParam Param ` @@`
Op string ` {@("<"|">"|">="|"<="|"!="|"="|"IN")`
SecondParam *Param ` @@}`
}
Condition is a unary or binary logical operation which has First mandatory param and optional operation and second param (optional)
type Dialect ¶
type Dialect struct {
// Flags defines how the parameter can be treated. Is it Unary or binary operation, can the parameter
// be a lvalue etc.
Flags int
// Translate is the function (can be nil), which is called for translation the parameter p to the dialect. For example,
// on the ql level the function hasPrefix(path, "abc") may be translated to the Postgres SQL:
// position('abc' in record.path) = 1
Translate func(tr Translator, sb *strings.Builder, p Param) error
}
Dialect describes how the parameter of specific type or name should be treated. Dialect has a name, either predefined for String(StringParamID), Number(NumberParamID) or the Array(ArrayParamID) or it is defined for the specific identifier or function name.
type Expression ¶
type Expression struct {
Or []*OrCondition `@@ { "OR" @@ }`
}
Expression is an AST element which describes a series of OR conditions
type OrCondition ¶
type OrCondition struct {
And []*XCondition `@@ { "AND" @@ }`
}
OrCondition is an AST element which describes a series of AND conditions
type Param ¶
type Param struct {
Const *Const ` @@`
Function *Function ` | @@`
Identifier string ` | @Ident`
Array []*Const `|"[" (@@ {"," @@})?"]"`
}
Param describes a parameter either a constant (string or number), function, identifier or an array of constants
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator struct allows to turn AST objects (Expresssion, Condition etc.) to the SQL statements according to the dialect provided
func NewTranslator ¶
func NewTranslator(dialects map[string]Dialect) Translator
NewTranslator creates new Trnasloator with dialects provided
func (Translator) Condition2Sql ¶
func (tr Translator) Condition2Sql(sb *strings.Builder, c *Condition) error
Condition2Sql turns the AST object c to the query string according to the dialect of the translator
func (Translator) Expression2Sql ¶
func (tr Translator) Expression2Sql(sb *strings.Builder, e *Expression) error
Expression2Sql turns the AST object e to the query string according to the dialect of the translator
func (Translator) OrCondition2Sql ¶
func (tr Translator) OrCondition2Sql(sb *strings.Builder, oc *OrCondition) error
OrCondition2Sql turns the AST object oc to the query string according to the dialect of the translator
func (Translator) Param2Sql ¶
func (tr Translator) Param2Sql(sb *strings.Builder, p *Param) error
Param2Sql turns the AST object p to the query string according to the dialect of the translator
func (Translator) Params2Sql ¶
func (tr Translator) Params2Sql(sb *strings.Builder, prms []*Param) error
Params2Sql turns the AST object prms to the query string according to the dialect of the translator
func (Translator) XCondition2Sql ¶
func (tr Translator) XCondition2Sql(sb *strings.Builder, xc *XCondition) error
XCondition2Sql turns the AST object xc to the query string according to the dialect of the translator
type XCondition ¶
type XCondition struct {
Not bool ` [@"NOT"] `
Cond *Condition `( @@`
Expr *Expression `| "(" @@ ")")`
}
XCondition is an AST element which groups either a Condition object or an Expression object