Documentation ¶
Index ¶
- Variables
- func IsExpression(value interface{}) bool
- func Register(name string, grammar Grammar)
- type Aggregate
- type Column
- type Command
- type Config
- type Connection
- type Constraint
- type Expression
- type From
- type Grammar
- type Having
- type Index
- type Join
- type Name
- type Option
- type Order
- type Primary
- type Query
- func (query *Query) AddBinding(typ string, value interface{})
- func (query *Query) AddColumn(column interface{}) *Query
- func (query *Query) Clone() *Query
- func (query *Query) CopyAggregate() Aggregate
- func (query *Query) CopyBindings() map[string][]interface{}
- func (query *Query) CopyColumns() []interface{}
- func (query *Query) CopyDistinctColumns() []interface{}
- func (query *Query) CopyFrom() From
- func (query *Query) CopyGroups() []interface{}
- func (query *Query) CopyHavings() []Having
- func (query *Query) CopyJoins() []Join
- func (query *Query) CopyLock() interface{}
- func (query *Query) CopyOrders() []Order
- func (query *Query) CopyUnionOrders() []Order
- func (query *Query) CopyUnions() []Union
- func (query *Query) CopyWheres() []Where
- func (query *Query) GetBindings(key ...string) []interface{}
- type Quoter
- type Select
- type Table
- func (table *Table) AddCommand(name string, success func(), fail func(), params ...interface{})
- func (table *Table) GetColumn(name string) *Column
- func (table *Table) GetIndex(name string) *Index
- func (table *Table) GetName() string
- func (table *Table) GetPrimary(name string, columns ...*Column) *Primary
- func (table *Table) HasColumn(name string) bool
- func (table *Table) HasIndex(name string) bool
- func (table *Table) NewColumn(name string) *Column
- func (table *Table) NewIndex(name string, columns ...*Column) *Index
- func (table *Table) NewPrimary(name string, columns ...*Column) *Primary
- func (table *Table) PushColumn(column *Column) *Table
- func (table *Table) PushIndex(index *Index) *Table
- type Union
- type Version
- type Where
Constants ¶
This section is empty.
Variables ¶
var BindingKeys = []string{
"select", "from", "join", "where",
"groupBy", "having",
"order",
"union", "unionOrder",
"sql",
}
BindingKeys the binding key orders
var Grammars = map[string]Grammar{}
Grammars loaded grammar driver
var Operators = []string{
"=", "<", ">", "<=", ">=", "<>", "!=", "<=>",
"like", "like binary", "not like", "ilike",
"&", "|", "^", "<<", ">>",
"rlike", "not rlike", "regexp", "not regexp",
"~", "~*", "!~", "!~*", "similar to",
"not similar to", "not ilike", "~~*", "!~~*",
}
Operators the default Operators
Functions ¶
func IsExpression ¶ added in v0.5.1
func IsExpression(value interface{}) bool
IsExpression Determine if the given value is a raw expression.
Types ¶
type Aggregate ¶ added in v0.5.1
type Aggregate struct { Func string // AVG, COUNT, MIN, MAX, SUM Columns []interface{} // The columns for Aggregate }
Aggregate An aggregate function and column to be run.
type Column ¶ added in v0.0.3
type Column struct { DBName string `db:"db_name"` TableName string `db:"table_name"` Name string `db:"name"` Position int `db:"position"` Default interface{} `db:"default"` DefaultRaw string `db:"default_raw"` Nullable bool `db:"nullable"` IsUnsigned bool `db:"unsigned"` Type string `db:"type"` Length *int `db:"length"` OctetLength *int `db:"octet_length"` Precision *int `db:"precision"` Scale *int `db:"scale"` DateTimePrecision *int `db:"datetime_precision"` Charset *string `db:"charset"` Collation *string `db:"collation"` Key *string `db:"key"` Extra *string `db:"extra"` Comment *string `db:"comment"` Primary bool `db:"primary"` TypeName string `db:"type_name"` MaxLength int DefaultLength int MaxPrecision int DefaultPrecision int MaxScale int DefaultScale int MaxDateTimePrecision int DefaultDateTimePrecision int Option []string Table *Table Indexes []*Index Constraint *Constraint }
Column the table Column
type Command ¶ added in v0.0.3
type Command struct { Name string // The command name Params []interface{} // The command parameters Success func() // Success callback function Fail func() // Fail callback function }
Command The Command that should be run for the table.
type Config ¶
type Config struct { Driver string `json:"driver"` // The driver name. mysql,pgsql,sqlite3,oci,sqlsrv DSN string `json:"dsn,omitempty"` // The driver wrapper. sqlite:///:memory:, mysql://localhost:4486/foo?charset=UTF8 Name string `json:"name,omitempty"` ReadOnly bool `json:"readonly,omitempty"` }
Config the Connection configuration
type Connection ¶ added in v0.0.3
Connection the database connection
type Constraint ¶ added in v0.0.3
type Constraint struct { SchemaName string TableName string ColumnName string Type string Args []string Table *Table }
Constraint the table constraint
func NewConstraint ¶ added in v0.0.3
func NewConstraint(schemaName string, tableName string, columnName string) *Constraint
NewConstraint make a new constraint intstance
type Expression ¶ added in v0.5.1
type Expression struct {
Value interface{}
}
Expression the raw query expression.
func NewExpression ¶ added in v0.5.1
func NewExpression(value interface{}) Expression
NewExpression make a new expression instance
func Raw ¶ added in v0.5.1
func Raw(value interface{}) Expression
Raw make a new expression instance
func (Expression) GetValue ¶ added in v0.5.1
func (expression Expression) GetValue() string
GetValue Get the value of the expression.
type Grammar ¶ added in v0.0.3
type Grammar interface { NewWith(db *sqlx.DB, config *Config, option *Option) (Grammar, error) NewWithRead(write *sqlx.DB, writeConfig *Config, read *sqlx.DB, readConfig *Config, option *Option) (Grammar, error) Wrap(value interface{}) string WrapTable(value interface{}) string OnConnected() error GetVersion() (*Version, error) GetDatabase() string GetSchema() string GetOperators() []string // Grammar for migrating GetTables() ([]string, error) TableExists(name string) (bool, error) GetTable(name string) (*Table, error) CreateTable(table *Table) error AlterTable(table *Table) error DropTable(name string) error DropTableIfExists(name string) error RenameTable(old string, new string) error GetColumnListing(dbName string, tableName string) ([]*Column, error) // Grammar for querying CompileInsert(query *Query, columns []interface{}, values [][]interface{}) (string, []interface{}) CompileInsertOrIgnore(query *Query, columns []interface{}, values [][]interface{}) (string, []interface{}) CompileInsertGetID(query *Query, columns []interface{}, values [][]interface{}, sequence string) (string, []interface{}) CompileInsertUsing(query *Query, columns []interface{}, sql string) string CompileUpsert(query *Query, columns []interface{}, values [][]interface{}, uniqueBy []interface{}, updateValues interface{}) (string, []interface{}) CompileUpdate(query *Query, values map[string]interface{}) (string, []interface{}) CompileDelete(query *Query) (string, []interface{}) CompileTruncate(query *Query) ([]string, [][]interface{}) CompileSelect(query *Query) string CompileSelectOffset(query *Query, offset *int) string CompileExists(query *Query) string ProcessInsertGetID(sql string, bindings []interface{}, sequence string) (int64, error) }
Grammar the SQL Grammar inteface
type Having ¶ added in v0.5.1
type Having struct { Type string Column interface{} Operator string Value interface{} Boolean string Offset int Values []interface{} Not bool SQL string }
Having The having constraints for the query.
type Index ¶ added in v0.0.3
type Index struct { DBName string `db:"db_name"` TableName string `db:"table_name"` ColumnName string `db:"column_name"` Name string `db:"index_name"` SEQ int `db:"seq_in_index"` SeqColumn int `db:"seq_in_column"` Collation string `db:"collation"` Nullable bool `db:"nullable"` Unique bool `db:"unique"` Primary bool `db:"primary"` SubPart int `db:"sub_part"` Type string `db:"type"` IndexType string `db:"index_type"` Comment *string `db:"comment"` IndexComment *string `db:"index_comment"` Table *Table Columns []*Column }
Index the talbe index
type Join ¶ added in v0.5.1
type Join struct { Type string // inner, left, right, cross Name interface{} // The table the join clause is joining to. Query *Query Alias string SQL interface{} Offset int }
Join the join clause for the query
type Name ¶ added in v0.5.1
Name the from attribute ( table_name as t1, column_name as c1...)
type Option ¶ added in v0.0.3
type Option struct { Prefix string `json:"prefix,omitempty"` // Table prifix Collation string `json:"collation,omitempty"` Charset string `json:"charset,omitempty"` }
Option the database configuration
type Primary ¶ added in v0.0.3
type Primary struct { DBName string `db:"db_name"` TableName string `db:"table_name"` Name string `db:"primary_name"` Table *Table Columns []*Column }
Primary the table primary key
type Query ¶ added in v0.5.1
type Query struct { UseWriteConnection bool // Whether to use write connection for the select. default is false Lock interface{} // Indicates whether row locking is being used. From From // The table which the query is targeting. Columns []interface{} // The columns that should be returned. (Name or Expression) Aggregate Aggregate // An aggregate function and column to be run. Wheres []Where // The where constraints for the query. Joins []Join // The table joins for the query. Unions []Union // The query union statements. UnionLimit int // The maximum number of union records to return. UnionOffset int // The number of union records to skip. UnionOrders []Order // The orderings for the union query. Orders []Order // The orderings for the query. Limit int // The maximum number of records to return. Offset int // The number of records to skip. Groups []interface{} // The groupings for the query. Havings []Having // The having constraints for the query. Bindings map[string][]interface{} // The current query value bindings. Distinct bool // Indicates if the query returns distinct results. Occasionally contains the columns that should be distinct. default is false DistinctColumns []interface{} // Indicates if the query returns distinct results. Occasionally contains the columns that should be distinct. IsJoinClause bool // Determine if the query is a join clause. BindingOffset int // The Binding offset before select SQL string // The SQL STMT }
Query the query builder
func (*Query) AddBinding ¶ added in v0.5.1
AddBinding Add a binding to the query.
func (*Query) CopyAggregate ¶ added in v0.5.1
CopyAggregate copy Aggregate
func (*Query) CopyBindings ¶ added in v0.5.1
CopyBindings copy Bindings
func (*Query) CopyColumns ¶ added in v0.5.1
func (query *Query) CopyColumns() []interface{}
CopyColumns copy columns
func (*Query) CopyDistinctColumns ¶ added in v0.5.1
func (query *Query) CopyDistinctColumns() []interface{}
CopyDistinctColumns copy DistinctColumns
func (*Query) CopyGroups ¶ added in v0.5.1
func (query *Query) CopyGroups() []interface{}
CopyGroups copy Groups
func (*Query) CopyHavings ¶ added in v0.5.1
CopyHavings copy Havings
func (*Query) CopyLock ¶ added in v0.5.1
func (query *Query) CopyLock() interface{}
CopyLock copy Lock
func (*Query) CopyOrders ¶ added in v0.5.1
CopyOrders copy Orders
func (*Query) CopyUnionOrders ¶ added in v0.5.1
CopyUnionOrders copy UnionOrders
func (*Query) CopyUnions ¶ added in v0.5.1
CopyUnions copy unions
func (*Query) CopyWheres ¶ added in v0.5.1
CopyWheres copy wheres
func (*Query) GetBindings ¶ added in v0.5.1
GetBindings Get the current query value bindings in a flattened array.
type Quoter ¶ added in v0.0.3
type Quoter interface { Bind(db *sqlx.DB, prefix string, dbRead ...*sqlx.DB) Quoter ID(value string) string VAL(value interface{}) string // operates on both string and []byte and int or other types. Wrap(value interface{}) string WrapTable(value interface{}) string WrapUnion(sql string) string IsExpression(value interface{}) bool Parameter(value interface{}, num int) string Parameterize(values []interface{}, offset int) string Columnize(columns []interface{}) string }
Quoter the database quoting query text intrface
type Table ¶ added in v0.0.3
type Table struct { DBName string `db:"db_name"` SchemaName string `db:"schema_name"` TableName string `db:"table_name"` Comment string `db:"table_comment"` Type string `db:"table_type"` Engine string `db:"engine"` CreateTime time.Time `db:"create_time"` CreateOptions string `db:"create_options"` Collation string `db:"collation"` Charset string `db:"charset"` Rows int `db:"table_rows"` RowLength int `db:"avg_row_length"` IndexLength int `db:"index_length"` AutoIncrement int `db:"auto_increment"` Primary *Primary ColumnMap map[string]*Column IndexMap map[string]*Index Columns []*Column Indexes []*Index Commands []*Command }
Table the table struct
func (*Table) AddCommand ¶ added in v0.0.3
AddCommand Add a new command to the table.
The commands must be:
AddColumn(column *Column) for adding a column ModifyColumn(column *Column) for modifying a colu RenameColumn(old string,new string) for renaming a column DropColumn(name string) for dropping a column CreateIndex(index *Index) for creating a index DropIndex( name string) for dropping a index RenameIndex(old string,new string) for renaming a index
func (*Table) GetPrimary ¶ added in v0.0.3
GetPrimary get the primary key instance
func (*Table) NewPrimary ¶ added in v0.0.3
NewPrimary create a new primary intstance
func (*Table) PushColumn ¶ added in v0.0.3
PushColumn push a column instance to the table columns
type Version ¶ added in v0.0.3
type Version struct { Driver string semver.Version }
Version the database version
type Where ¶ added in v0.5.1
type Where struct { Type string // basic, nested, sub, null, notnull ... Column interface{} First interface{} // for comparing the two columns Second interface{} // for comparing the two columns SQL string Operator string Boolean string Wheres []Where Query *Query Value interface{} Values []interface{} ValuesIn interface{} Not bool Offset int }
Where The where constraint for the query.