Documentation ¶
Index ¶
- Constants
- Variables
- func NewWriter(q Query, database, prefix, namespace, driver string) *writer
- func Print(v interface{}) error
- func Sprint(v interface{}) (string, error)
- func ToSql(q Query, database, prefix, namespace, driver string) (string, []interface{}, error)
- func ValidateSelect(q *SelectQuery, options *ValidateOptions) error
- type AddColumnQuery
- type AddConstraintQuery
- type AddFKQuery
- type AllColumnsExpr
- type AlterDropQuery
- type BetweenExpr
- type BinaryExpr
- type CallExpr
- type Column
- type ColumnNameExpr
- type ColumnType
- type ColumnValue
- type ConstantExpr
- type Constraint
- type CreateColumn
- type CreateDatabaseQuery
- type CreateTableConstraint
- type CreateTableQuery
- type DateIntervalExpr
- type DeleteQuery
- func (q *DeleteQuery) And(code string, params ...interface{}) error
- func (q *DeleteQuery) AndQuery(filter *SelectQuery)
- func (q *DeleteQuery) Join(code string, params ...interface{}) error
- func (q *DeleteQuery) Limit(rowCount int)
- func (q *DeleteQuery) LimitOffset(offset, rowCount int)
- func (q *DeleteQuery) Or(code string, params ...interface{}) error
- func (q *DeleteQuery) OrQuery(filter *SelectQuery)
- func (q *DeleteQuery) Parameters() []interface{}
- func (q *DeleteQuery) Position() Position
- func (q *DeleteQuery) Where(code string, params ...interface{}) error
- type DropDatabaseQuery
- type DropTableQuery
- type Error
- type Expr
- type ForeginKey
- type FromAsExpr
- type GroupConcatExpr
- type IdentExpr
- type InExpr
- type InsertQuery
- type Join
- type Limit
- type ModifyColumnQuery
- type Node
- type OrderColumn
- type ParameterExpr
- type ParamsQuery
- type ParenExpr
- type Parser
- type Position
- type Printer
- type Query
- type QueryTable
- type RenameColumnQuery
- type SelectColumnExpr
- type SelectQuery
- func (q *SelectQuery) AddColumns(code string) error
- func (q *SelectQuery) And(code string, params ...interface{}) error
- func (q *SelectQuery) AndQuery(filter *SelectQuery)
- func (q *SelectQuery) GroupBy(code string) error
- func (q *SelectQuery) Having(code string, params ...interface{}) error
- func (q *SelectQuery) Join(code string, params ...interface{}) error
- func (q *SelectQuery) Limit(rowCount int)
- func (q *SelectQuery) LimitOffset(offset, rowCount int)
- func (q *SelectQuery) Or(code string, params ...interface{}) error
- func (q *SelectQuery) OrQuery(filter *SelectQuery)
- func (q *SelectQuery) OrderBy(code string) error
- func (q *SelectQuery) Parameters() []interface{}
- func (q *SelectQuery) Position() Position
- func (q *SelectQuery) SetColumns(code string) error
- func (q *SelectQuery) SetFrom(code string) error
- func (q *SelectQuery) Where(code string, params ...interface{}) error
- type ShowQuery
- type SqlFrom
- type Table
- type TableName
- type Token
- type Type
- type UnaryExpr
- type UpdateQuery
- func (q *UpdateQuery) AddColumns(code string, params ...interface{}) error
- func (q *UpdateQuery) And(code string, params ...interface{}) error
- func (q *UpdateQuery) AndQuery(filter *SelectQuery)
- func (q *UpdateQuery) Join(code string, params ...interface{}) error
- func (q *UpdateQuery) Limit(rowCount int)
- func (q *UpdateQuery) LimitOffset(offset, rowCount int)
- func (q *UpdateQuery) Or(code string, params ...interface{}) error
- func (q *UpdateQuery) OrQuery(filter *SelectQuery)
- func (q *UpdateQuery) Parameters() []interface{}
- func (q *UpdateQuery) Position() Position
- func (q *UpdateQuery) SetColumns(code string, params ...interface{}) error
- func (q *UpdateQuery) Where(code string, params ...interface{}) error
- type ValidateOptions
- type ValidateTable
- type WherePart
Constants ¶
View Source
const EOF_LINE int = -1
Variables ¶
View Source
var ValidFuncs []string
Functions ¶
func ValidateSelect ¶
func ValidateSelect(q *SelectQuery, options *ValidateOptions) error
Types ¶
type AddColumnQuery ¶
type AddColumnQuery struct { Pos Position Database string Table string Column *CreateColumn }
func (*AddColumnQuery) Parameters ¶
func (q *AddColumnQuery) Parameters() []interface{}
func (*AddColumnQuery) Position ¶
func (q *AddColumnQuery) Position() Position
type AddConstraintQuery ¶
type AddConstraintQuery struct { Pos Position Type string Database string Table string Name string Columns []*ColumnNameExpr }
func (*AddConstraintQuery) Parameters ¶
func (q *AddConstraintQuery) Parameters() []interface{}
func (*AddConstraintQuery) Position ¶
func (q *AddConstraintQuery) Position() Position
type AddFKQuery ¶
type AddFKQuery struct { Pos Position Type string Database string Table string Name string Column string RefDatabase string RefTable string RefColumn string DeleteCascade bool }
func (*AddFKQuery) Parameters ¶
func (q *AddFKQuery) Parameters() []interface{}
func (*AddFKQuery) Position ¶
func (q *AddFKQuery) Position() Position
type AllColumnsExpr ¶
func (*AllColumnsExpr) Position ¶
func (q *AllColumnsExpr) Position() Position
type AlterDropQuery ¶
func (*AlterDropQuery) Parameters ¶
func (q *AlterDropQuery) Parameters() []interface{}
func (*AlterDropQuery) Position ¶
func (q *AlterDropQuery) Position() Position
type BetweenExpr ¶
func (*BetweenExpr) Position ¶
func (i *BetweenExpr) Position() Position
type BinaryExpr ¶
func (*BinaryExpr) Position ¶
func (i *BinaryExpr) Position() Position
type ColumnNameExpr ¶
func GetFilterColumns ¶
func GetFilterColumns(q Query) []*ColumnNameExpr
func NameExprColumns ¶
func NameExprColumns(e Expr) []*ColumnNameExpr
ExprColumns returns the column names in an expression.
func (*ColumnNameExpr) FullName ¶
func (i *ColumnNameExpr) FullName() string
func (*ColumnNameExpr) Position ¶
func (i *ColumnNameExpr) Position() Position
type ColumnType ¶
type ColumnType byte
const ( Int ColumnType = iota BigInt Decimal Char Varchar Text MediumText Bool Blob MediumBlob DatTime )
type ConstantExpr ¶
func (*ConstantExpr) Position ¶
func (i *ConstantExpr) Position() Position
type Constraint ¶
type CreateColumn ¶
type CreateDatabaseQuery ¶
func (*CreateDatabaseQuery) Parameters ¶
func (q *CreateDatabaseQuery) Parameters() []interface{}
func (*CreateDatabaseQuery) Position ¶
func (q *CreateDatabaseQuery) Position() Position
type CreateTableConstraint ¶
type CreateTableConstraint interface {
// contains filtered or unexported methods
}
type CreateTableQuery ¶
type CreateTableQuery struct { Pos Position Database string Name string Columns []*CreateColumn Constraints []CreateTableConstraint IfNotExists bool }
func (*CreateTableQuery) Parameters ¶
func (q *CreateTableQuery) Parameters() []interface{}
func (*CreateTableQuery) Position ¶
func (q *CreateTableQuery) Position() Position
type DateIntervalExpr ¶
func (*DateIntervalExpr) Position ¶
func (i *DateIntervalExpr) Position() Position
type DeleteQuery ¶
type DeleteQuery struct { Pos Position Alias []string Table *Table WherePart *WherePart LimitPart *Limit }
func (*DeleteQuery) And ¶
func (q *DeleteQuery) And(code string, params ...interface{}) error
func (*DeleteQuery) AndQuery ¶
func (q *DeleteQuery) AndQuery(filter *SelectQuery)
func (*DeleteQuery) Join ¶
func (q *DeleteQuery) Join(code string, params ...interface{}) error
func (*DeleteQuery) Limit ¶
func (q *DeleteQuery) Limit(rowCount int)
func (*DeleteQuery) LimitOffset ¶
func (q *DeleteQuery) LimitOffset(offset, rowCount int)
func (*DeleteQuery) Or ¶
func (q *DeleteQuery) Or(code string, params ...interface{}) error
func (*DeleteQuery) OrQuery ¶
func (q *DeleteQuery) OrQuery(filter *SelectQuery)
func (*DeleteQuery) Parameters ¶
func (q *DeleteQuery) Parameters() []interface{}
func (*DeleteQuery) Position ¶
func (q *DeleteQuery) Position() Position
func (*DeleteQuery) Where ¶
func (q *DeleteQuery) Where(code string, params ...interface{}) error
type DropDatabaseQuery ¶
func (*DropDatabaseQuery) Parameters ¶
func (q *DropDatabaseQuery) Parameters() []interface{}
func (*DropDatabaseQuery) Position ¶
func (q *DropDatabaseQuery) Position() Position
type DropTableQuery ¶
func (*DropTableQuery) Parameters ¶
func (q *DropTableQuery) Parameters() []interface{}
func (*DropTableQuery) Position ¶
func (q *DropTableQuery) Position() Position
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
All expression nodes implement the Expr interface.
type ForeginKey ¶
type FromAsExpr ¶
func (*FromAsExpr) Position ¶
func (a *FromAsExpr) Position() Position
type GroupConcatExpr ¶
type GroupConcatExpr struct { Pos Position Distinct bool Expressions []Expr OrderByPart []*OrderColumn Separator string }
func (*GroupConcatExpr) Position ¶
func (i *GroupConcatExpr) Position() Position
type InsertQuery ¶
type InsertQuery struct { Pos Position Table *TableName Columns []*ColumnNameExpr Values []Expr Select *SelectQuery // in case is a insert from a select }
func (*InsertQuery) AddColumn ¶
func (q *InsertQuery) AddColumn(name string, value interface{}) error
func (*InsertQuery) Parameters ¶
func (q *InsertQuery) Parameters() []interface{}
func (*InsertQuery) Position ¶
func (q *InsertQuery) Position() Position
type ModifyColumnQuery ¶
type ModifyColumnQuery struct { Pos Position Database string Table string Column *CreateColumn }
func (*ModifyColumnQuery) Parameters ¶
func (q *ModifyColumnQuery) Parameters() []interface{}
func (*ModifyColumnQuery) Position ¶
func (q *ModifyColumnQuery) Position() Position
type Node ¶
type Node interface {
Position() Position
}
All node types implement the Node interface.
type OrderColumn ¶
type ParameterExpr ¶
func (*ParameterExpr) Position ¶
func (q *ParameterExpr) Position() Position
type ParamsQuery ¶
type ParamsQuery interface {
GetParams() []interface{}
}
type Parser ¶
type Parser struct { // If it replaces values with parameters ReplaceParams bool Params []interface{} // contains filtered or unexported fields }
func NewStrParser ¶
func (*Parser) AssertParamsSet ¶
func (*Parser) ParseQuery ¶
ParseQuery parses a single query.
type Query ¶
type Query interface { Node Parameters() []interface{} // contains filtered or unexported methods }
All SQL queries implement the Query interface.
type QueryTable ¶
func GetSelectMainTable ¶
func GetSelectMainTable(q Query) *QueryTable
Return the table in a basic SELECT FROM table
func GetTables ¶
func GetTables(q Query) []*QueryTable
type RenameColumnQuery ¶
type RenameColumnQuery struct { Pos Position Database string Table string Name string Column *CreateColumn }
func (*RenameColumnQuery) Parameters ¶
func (q *RenameColumnQuery) Parameters() []interface{}
func (*RenameColumnQuery) Position ¶
func (q *RenameColumnQuery) Position() Position
type SelectColumnExpr ¶
func (*SelectColumnExpr) Position ¶
func (q *SelectColumnExpr) Position() Position
type SelectQuery ¶
type SelectQuery struct { Pos Position Distinct bool ForUpdate bool Columns []Expr From []SqlFrom WherePart *WherePart GroupByPart []Expr HavingPart *WherePart OrderByPart []*OrderColumn LimitPart *Limit UnionPart []*SelectQuery }
func Select ¶
func Select(code string, params ...interface{}) (*SelectQuery, error)
func Where ¶
func Where(code string, params ...interface{}) (*SelectQuery, error)
Where parses a select query filter
func (*SelectQuery) AddColumns ¶
func (q *SelectQuery) AddColumns(code string) error
func (*SelectQuery) And ¶
func (q *SelectQuery) And(code string, params ...interface{}) error
func (*SelectQuery) AndQuery ¶
func (q *SelectQuery) AndQuery(filter *SelectQuery)
func (*SelectQuery) GroupBy ¶
func (q *SelectQuery) GroupBy(code string) error
func (*SelectQuery) Having ¶
func (q *SelectQuery) Having(code string, params ...interface{}) error
func (*SelectQuery) Join ¶
func (q *SelectQuery) Join(code string, params ...interface{}) error
func (*SelectQuery) Limit ¶
func (q *SelectQuery) Limit(rowCount int)
func (*SelectQuery) LimitOffset ¶
func (q *SelectQuery) LimitOffset(offset, rowCount int)
func (*SelectQuery) Or ¶
func (q *SelectQuery) Or(code string, params ...interface{}) error
func (*SelectQuery) OrQuery ¶
func (q *SelectQuery) OrQuery(filter *SelectQuery)
func (*SelectQuery) OrderBy ¶
func (q *SelectQuery) OrderBy(code string) error
func (*SelectQuery) Parameters ¶
func (q *SelectQuery) Parameters() []interface{}
func (*SelectQuery) Position ¶
func (q *SelectQuery) Position() Position
func (*SelectQuery) SetColumns ¶
func (q *SelectQuery) SetColumns(code string) error
func (*SelectQuery) SetFrom ¶
func (q *SelectQuery) SetFrom(code string) error
func (*SelectQuery) Where ¶
func (q *SelectQuery) Where(code string, params ...interface{}) error
type ShowQuery ¶
func (*ShowQuery) Parameters ¶
func (q *ShowQuery) Parameters() []interface{}
type Type ¶
type Type byte
const ( NOTSET Type = iota ERROR EOF COMMENT // -- // Keywords CREATE SHOW DROP ALTER TABLE DATABASE NOT EXISTS CONSTRAINT INTEGER BIGINT DECIMAL CHAR VARCHAR TEXT MEDIUMTEXT BOOL BLOB MEDIUMBLOB DATETIME DEFAULT UNSIGNED SELECT DISTINCT INSERT INTO VALUES UPDATE SET DELETE FROM WHERE GROUP HAVING JOIN LEFT RIGHT INNER OUTER CROSS ON AS IN NOTIN BETWEEN LIKE IS ISNOT NOTLIKE ORDER BY ASC DESC RANDOM LIMIT UNION AND OR NULL TRUE FALSE FOR IDENT // fields, tables... INT // 12345 FLOAT // 123.45 STRING // "abc" // Operators and delimiters ADD // + SUB // - MUL // * DIV // / MOD // % LSF // << left shift RSF // >> right shift ANB // & binary AND EQL // = LSS // < GTR // > NT // ! NEQ // != LEQ // <= GEQ // >= LPAREN // ( LBRACK // [ LBRACE // { COMMA // , PERIOD // . RPAREN // ) COLON // ; SEMICOLON // ; QUESTION // ? )
type UpdateQuery ¶
type UpdateQuery struct { Pos Position Table *Table Columns []ColumnValue WherePart *WherePart LimitPart *Limit }
func (*UpdateQuery) AddColumns ¶
func (q *UpdateQuery) AddColumns(code string, params ...interface{}) error
func (*UpdateQuery) And ¶
func (q *UpdateQuery) And(code string, params ...interface{}) error
func (*UpdateQuery) AndQuery ¶
func (q *UpdateQuery) AndQuery(filter *SelectQuery)
func (*UpdateQuery) Join ¶
func (q *UpdateQuery) Join(code string, params ...interface{}) error
func (*UpdateQuery) Limit ¶
func (q *UpdateQuery) Limit(rowCount int)
func (*UpdateQuery) LimitOffset ¶
func (q *UpdateQuery) LimitOffset(offset, rowCount int)
func (*UpdateQuery) Or ¶
func (q *UpdateQuery) Or(code string, params ...interface{}) error
func (*UpdateQuery) OrQuery ¶
func (q *UpdateQuery) OrQuery(filter *SelectQuery)
func (*UpdateQuery) Parameters ¶
func (q *UpdateQuery) Parameters() []interface{}
func (*UpdateQuery) Position ¶
func (q *UpdateQuery) Position() Position
func (*UpdateQuery) SetColumns ¶
func (q *UpdateQuery) SetColumns(code string, params ...interface{}) error
func (*UpdateQuery) Where ¶
func (q *UpdateQuery) Where(code string, params ...interface{}) error
type ValidateOptions ¶
type ValidateOptions struct { Tables []*ValidateTable // contains filtered or unexported fields }
type ValidateTable ¶
Click to show internal directories.
Click to hide internal directories.