Documentation ¶
Index ¶
- Constants
- Variables
- func AscOrder(expr SqlExpr) *order
- func Comment(c string) comment
- func DescOrder(expr SqlExpr) *order
- func FlattenArgs(query string, args ...interface{}) (finalQuery string, finalArgs []interface{})
- func ForEachStructField(structType reflect.Type, ...)
- func ForEachStructFieldValue(rv reflect.Value, ...)
- func ForUpdate() *otherAddition
- func GroupBy(groups ...SqlExpr) *groupBy
- func HolderRepeat(length int) string
- func Join(table *Table, modifies ...string) *join
- func Limit(rowCount int32) *limit
- func LockInShareMode() *otherAddition
- func OnDuplicateKeyUpdate(assignments ...*Assignment) *otherAddition
- func OrderBy(orders ...*order) *orderBy
- func ScanDefToTable(rv reflect.Value, table *Table)
- func Where(c *Condition) *where
- type Addition
- type Additions
- type Assignment
- type Assignments
- type Column
- func (c *Column) Between(leftValue interface{}, rightValue interface{}) *Condition
- func (c *Column) Def() *Expression
- func (c *Column) Desc(d int) *Expression
- func (c Column) Enum(enum enumeration.Enum) *Column
- func (c *Column) Eq(value interface{}) *Condition
- func (c *Column) Expr() *Expression
- func (c Column) Field(fieldName string) *Column
- func (c *Column) Gt(v interface{}) *Condition
- func (c *Column) Gte(v interface{}) *Condition
- func (c *Column) In(args ...interface{}) *Condition
- func (c *Column) Incr(d int) *Expression
- func (c *Column) IsNotNull() *Condition
- func (c *Column) IsNull() *Condition
- func (c *Column) IsValidDef() bool
- func (c *Column) LeftLike(v string) *Condition
- func (c *Column) Like(v string) *Condition
- func (c *Column) Lt(v interface{}) *Condition
- func (c *Column) Lte(v interface{}) *Condition
- func (c *Column) Neq(v interface{}) *Condition
- func (c *Column) NotBetween(leftValue interface{}, rightValue interface{}) *Condition
- func (c *Column) NotIn(args ...interface{}) *Condition
- func (c *Column) NotLike(v string) *Condition
- func (c *Column) RightLike(v string) *Condition
- func (c *Column) String() string
- func (c Column) Type(tpe string) *Column
- func (c *Column) ValueBy(v interface{}) *Assignment
- type Columns
- func (cols *Columns) Add(columns ...*Column)
- func (cols *Columns) AutoIncrement() (col *Column)
- func (cols *Columns) Clone() *Columns
- func (cols *Columns) Col(columnName string) (col *Column)
- func (cols *Columns) Cols(colNames ...string) (columns *Columns)
- func (cols Columns) Diff(targetCols Columns) columnsDiffResult
- func (cols Columns) Expr() (e *Expression)
- func (cols *Columns) F(fileName string) (col *Column)
- func (cols *Columns) FieldNames() []string
- func (cols *Columns) Fields(fieldNames ...string) (columns *Columns)
- func (cols Columns) Group() (e *Expression)
- func (cols *Columns) IsEmpty() bool
- func (cols *Columns) Len() int
- func (cols *Columns) List() (l []*Column)
- func (cols *Columns) Range(cb func(col *Column, idx int))
- func (cols *Columns) Remove(name string)
- type CondRule
- type CondRules
- type Condition
- type Database
- type DatabaseDefiner
- type DiffOptions
- type Expression
- func AddCol(c *Column) *Expression
- func AddKey(key *Key) *Expression
- func DropCol(c *Column) *Expression
- func DropKey(key *Key) *Expression
- func Expr(query string, args ...interface{}) *Expression
- func ExprErr(err error) *Expression
- func ExprFrom(v interface{}) *Expression
- func JoinExpr(joiner string, sqlExprs ...SqlExpr) (*Expression, error)
- func ModifyCol(c *Column) *Expression
- func MustJoinExpr(joiner string, sqlExprs ...SqlExpr) *Expression
- type FieldNames
- type FieldValues
- type Function
- func Avg(sqlExprs ...SqlExpr) *Function
- func Count(sqlExprs ...SqlExpr) *Function
- func Distinct(sqlExprs ...SqlExpr) *Function
- func First(sqlExprs ...SqlExpr) *Function
- func Func(name string, sqlExprs ...SqlExpr) *Function
- func Last(sqlExprs ...SqlExpr) *Function
- func Max(sqlExprs ...SqlExpr) *Function
- func Min(sqlExprs ...SqlExpr) *Function
- func Sum(sqlExprs ...SqlExpr) *Function
- type IndexDeclarer
- type Indexes
- type Key
- type Keys
- func (keys *Keys) Add(nextKeys ...*Key)
- func (keys *Keys) Clone() *Keys
- func (keys Keys) Diff(targetKeys Keys) keysDiffResult
- func (keys *Keys) IsEmpty() bool
- func (keys *Keys) Key(keyName string) (key *Key, exists bool)
- func (keys *Keys) Len() int
- func (keys *Keys) Range(cb func(key *Key, idx int))
- func (keys *Keys) Remove(name string)
- type Model
- type SqlExpr
- func AlterTable(t *Table) SqlExpr
- func CreateDatebase(d DatabaseDefiner) SqlExpr
- func CreateDatebaseIfNotExists(d DatabaseDefiner) SqlExpr
- func CreateTable(t *Table) SqlExpr
- func CreateTableIsNotExists(t *Table) SqlExpr
- func DropDatabase(d DatabaseDefiner) SqlExpr
- func DropTable(t *Table) SqlExpr
- func TruncateTable(t *Table) SqlExpr
- type StmtDelete
- type StmtInsert
- type StmtSelect
- type StmtUpdate
- type Table
- func (t *Table) AssignmentsByFieldValues(fieldValues FieldValues) (assignments Assignments)
- func (t *Table) ColumnsAndValuesByFieldValues(fieldValues FieldValues) (columns *Columns, args []interface{})
- func (t *Table) Cond(query string, args ...interface{}) *Condition
- func (t Table) Define(defs ...TableDef) *Table
- func (t *Table) Diff(table *Table, opts DiffOptions) (exprs []SqlExpr)
- func (t *Table) Ex(query string, args ...interface{}) *Expression
- func (t *Table) Expr() *Expression
- func (t *Table) FullName() string
- func (t *Table) TableName() string
- type TableDef
- type Tables
- type ValuerExpr
- type WithComments
- type WithIndexes
- type WithPrimaryKey
- type WithSpatialIndexes
- type WithUniqueIndexes
Constants ¶
View Source
const ( PRIMARY keyType = "PRIMARY" INDEX keyType = "INDEX" UNIQUE_INDEX keyType = "UNIQUE INDEX" SPATIAL_INDEX keyType = "SPATIAL INDEX" )
View Source
const ( ALL = "ALL" DISTINCT = "DISTINCT" DISTINCTROW = "DISTINCTROW" LOW_PRIORITY = "LOW_PRIORITY" DELAYED = "LOW_PRIORITY" HIGH_PRIORITY = "HIGH_PRIORITY" QUICK = "QUICK" STRAIGHT_JOIN = "STRAIGHT_JOIN" SQL_SMALL_RESULT = "SQL_SMALL_RESULT" SQL_BIG_RESULT = "SQL_BIG_RESULT" SQL_BUFFER_RESULT = "SQL_BUFFER_RESULT" IGNORE = "IGNORE" )
Variables ¶
View Source
var (
UpdateNeedLimitByWhere = fmt.Errorf("no where limit for update")
)
Functions ¶
func FlattenArgs ¶
func ForEachStructField ¶
func ForEachStructField(structType reflect.Type, fn func(structField reflect.StructField, columnName string))
func ForEachStructFieldValue ¶
func HolderRepeat ¶
func LockInShareMode ¶
func LockInShareMode() *otherAddition
func OnDuplicateKeyUpdate ¶
func OnDuplicateKeyUpdate(assignments ...*Assignment) *otherAddition
func ScanDefToTable ¶
Types ¶
type Additions ¶
type Additions []Addition
func (Additions) Expr ¶
func (a Additions) Expr() *Expression
type Assignment ¶
type Assignment Expression
func ColumnsAndValues ¶
func ColumnsAndValues(cols *Columns, values ...interface{}) *Assignment
func (Assignment) Expr ¶
func (a Assignment) Expr() *Expression
type Assignments ¶
type Assignments []*Assignment
func (Assignments) Expr ¶
func (assigns Assignments) Expr() (e *Expression)
type Column ¶
type Column struct { Table *Table Name string FieldName string datatypes.ColumnType }
func (*Column) Def ¶
func (c *Column) Def() *Expression
func (*Column) Desc ¶
func (c *Column) Desc(d int) *Expression
func (*Column) Expr ¶
func (c *Column) Expr() *Expression
func (*Column) Incr ¶
func (c *Column) Incr(d int) *Expression
func (*Column) IsValidDef ¶
func (*Column) NotBetween ¶
func (*Column) ValueBy ¶
func (c *Column) ValueBy(v interface{}) *Assignment
type Columns ¶
type Columns struct {
// contains filtered or unexported fields
}
func (*Columns) AutoIncrement ¶
func (Columns) Expr ¶
func (cols Columns) Expr() (e *Expression)
func (*Columns) FieldNames ¶
func (Columns) Group ¶
func (cols Columns) Group() (e *Expression)
type CondRules ¶
type CondRules struct {
// contains filtered or unexported fields
}
func NewCondRules ¶
func NewCondRules() *CondRules
type Condition ¶
type Condition Expression
func (*Condition) Expr ¶
func (c *Condition) Expr() *Expression
type DatabaseDefiner ¶
type DatabaseDefiner interface {
DBName() string
}
type DiffOptions ¶
type DiffOptions struct {
DropColumn bool
}
type Expression ¶
func AddCol ¶
func AddCol(c *Column) *Expression
func AddKey ¶
func AddKey(key *Key) *Expression
func DropCol ¶
func DropCol(c *Column) *Expression
func DropKey ¶
func DropKey(key *Key) *Expression
func Expr ¶
func Expr(query string, args ...interface{}) *Expression
func ExprErr ¶
func ExprErr(err error) *Expression
func ExprFrom ¶
func ExprFrom(v interface{}) *Expression
func ModifyCol ¶
func ModifyCol(c *Column) *Expression
func MustJoinExpr ¶
func MustJoinExpr(joiner string, sqlExprs ...SqlExpr) *Expression
func (*Expression) Expr ¶
func (e *Expression) Expr() *Expression
type FieldNames ¶
type FieldNames []string
func (FieldNames) Map ¶
func (fieldNames FieldNames) Map() map[string]bool
type FieldValues ¶
type FieldValues map[string]interface{}
func FieldValuesFromStructBy ¶
func FieldValuesFromStructBy(structValue interface{}, fieldNames []string) (fieldValues FieldValues)
func FieldValuesFromStructByNonZero ¶
func FieldValuesFromStructByNonZero(structValue interface{}, excludes ...string) (fieldValues FieldValues)
type Function ¶
type Function struct { Name string // contains filtered or unexported fields }
func (*Function) Expr ¶
func (f *Function) Expr() *Expression
type IndexDeclarer ¶
type IndexDeclarer func() (indexName string, fieldNames FieldNames)
type Indexes ¶
type Indexes map[string]FieldNames
type Key ¶
func PrimaryKey ¶
func PrimaryKey() *Key
func SpatialIndex ¶ added in v1.1.0
func UniqueIndex ¶
func (*Key) Def ¶
func (key *Key) Def() *Expression
func (*Key) IsValidDef ¶
type SqlExpr ¶
type SqlExpr interface {
Expr() *Expression
}
func AlterTable ¶
func CreateDatebase ¶
func CreateDatebase(d DatabaseDefiner) SqlExpr
func CreateDatebaseIfNotExists ¶
func CreateDatebaseIfNotExists(d DatabaseDefiner) SqlExpr
func CreateTable ¶
func CreateTableIsNotExists ¶
func DropDatabase ¶
func DropDatabase(d DatabaseDefiner) SqlExpr
func TruncateTable ¶
type StmtDelete ¶
type StmtDelete struct {
// contains filtered or unexported fields
}
func Delete ¶
func Delete(modifiers ...string) *StmtDelete
func (*StmtDelete) Expr ¶
func (s *StmtDelete) Expr() *Expression
func (StmtDelete) From ¶
func (s StmtDelete) From(table *Table, additions ...Addition) *StmtDelete
type StmtInsert ¶
type StmtInsert struct {
// contains filtered or unexported fields
}
https://dev.mysql.com/doc/refman/5.6/en/insert.html
func Insert ¶
func Insert(modifiers ...string) *StmtInsert
func (*StmtInsert) Expr ¶
func (s *StmtInsert) Expr() *Expression
func (StmtInsert) Into ¶
func (s StmtInsert) Into(table *Table, additions ...Addition) *StmtInsert
func (StmtInsert) Set ¶
func (s StmtInsert) Set(assignments ...*Assignment) *StmtInsert
func (StmtInsert) Values ¶
func (s StmtInsert) Values(cols *Columns, values ...interface{}) *StmtInsert
type StmtSelect ¶
type StmtSelect struct {
// contains filtered or unexported fields
}
https://dev.mysql.com/doc/refman/5.7/en/select.html
func Select ¶
func Select(sqlExpr SqlExpr, modifiers ...string) *StmtSelect
func (*StmtSelect) Expr ¶
func (s *StmtSelect) Expr() *Expression
func (StmtSelect) From ¶
func (s StmtSelect) From(table *Table, additions ...Addition) *StmtSelect
type StmtUpdate ¶
type StmtUpdate struct {
// contains filtered or unexported fields
}
func Update ¶
func Update(table *Table, modifiers ...string) *StmtUpdate
func (*StmtUpdate) Expr ¶
func (s *StmtUpdate) Expr() *Expression
func (StmtUpdate) Set ¶
func (s StmtUpdate) Set(assignments ...*Assignment) *StmtUpdate
func (StmtUpdate) Where ¶
func (s StmtUpdate) Where(c *Condition, additions ...Addition) *StmtUpdate
type Table ¶
func (*Table) AssignmentsByFieldValues ¶
func (t *Table) AssignmentsByFieldValues(fieldValues FieldValues) (assignments Assignments)
func (*Table) ColumnsAndValuesByFieldValues ¶
func (t *Table) ColumnsAndValuesByFieldValues(fieldValues FieldValues) (columns *Columns, args []interface{})
func (*Table) Ex ¶
func (t *Table) Ex(query string, args ...interface{}) *Expression
replace go struct field name with table column name
func (*Table) Expr ¶
func (t *Table) Expr() *Expression
type TableDef ¶
type TableDef interface { IsValidDef() bool Def() *Expression }
type Tables ¶
func (Tables) TableNames ¶
type ValuerExpr ¶ added in v1.1.0
type ValuerExpr interface {
ValueEx() string
}
type WithComments ¶
type WithIndexes ¶
type WithIndexes interface {
Indexes() Indexes
}
type WithPrimaryKey ¶
type WithPrimaryKey interface {
PrimaryKey() FieldNames
}
type WithSpatialIndexes ¶ added in v1.1.0
type WithSpatialIndexes interface {
SpatialIndexes() Indexes
}
type WithUniqueIndexes ¶
type WithUniqueIndexes interface {
UniqueIndexes() Indexes
}
Click to show internal directories.
Click to hide internal directories.