Documentation ¶
Index ¶
- Variables
- func Alias(expr SqlExpr, name string) *exAlias
- func Comment(c string) *comment
- func ContextWithToggles(ctx context.Context, toggles Toggles) context.Context
- func CrossJoin(table SqlExpr) *join
- func Expect() *combination
- func ForEachStructFieldValue(ctx context.Context, rv reflect.Value, fn func(*StructField))
- func FullJoin(table SqlExpr) *join
- func GetColumnName(fieldName, tagValue string) string
- func GroupBy(groups ...SqlExpr) *groupBy
- func InnerJoin(table SqlExpr) *join
- func Intersect() *combination
- func IsNilExpr(e SqlExpr) bool
- func Join(table SqlExpr, prefixes ...string) *join
- func LeftJoin(table SqlExpr) *join
- func Limit(rowCount int64) *limit
- func MultiMayAutoAlias(columns ...SqlExpr) *exMayAutoAlias
- func OnConflict(columns *Columns) *onConflict
- func OrderBy(orders ...*Order) *orderBy
- func RangeNotNilExpr(exprs []SqlExpr, each func(e SqlExpr, i int))
- func ResolveIndexNameAndMethod(n string) (name string, method string)
- func RightJoin(table SqlExpr) *join
- func ScanDefToTable(rv reflect.Value, table *Table)
- func TableAliasFromContext(ctx context.Context) string
- func TableNameFromContext(ctx context.Context) string
- func ToMap(list []string) map[string]bool
- func Union() *combination
- func Where(c SqlCondition) *where
- func WithTableAlias(tableName string) func(ctx context.Context) context.Context
- func WithTableName(tableName string) func(ctx context.Context) context.Context
- func WriteAdditions(e *Ex, additions ...Addition)
- func WriteAssignments(e *Ex, assignments ...*Assignment)
- type Addition
- type AdditionType
- type Additions
- type Assignment
- type Assignments
- type BuildSubQuery
- type Column
- func (c *Column) Between(leftValue interface{}, rightValue interface{}) SqlCondition
- func (c *Column) Desc(d int) SqlExpr
- func (c *Column) Eq(v interface{}) SqlCondition
- func (c *Column) Ex(ctx context.Context) *Ex
- func (c *Column) Expr(query string, args ...interface{}) *Ex
- func (c Column) Field(fieldName string) *Column
- func (c Column) Full() *Column
- func (c *Column) Gt(v interface{}) SqlCondition
- func (c *Column) Gte(v interface{}) SqlCondition
- func (c *Column) In(args ...interface{}) SqlCondition
- func (c *Column) Incr(d int) SqlExpr
- func (c *Column) IsNil() bool
- func (c *Column) IsNotNull() SqlCondition
- func (c *Column) IsNull() SqlCondition
- func (c *Column) LeftLike(v string) SqlCondition
- func (c *Column) Like(v string) SqlCondition
- func (c *Column) Lt(v interface{}) SqlCondition
- func (c *Column) Lte(v interface{}) SqlCondition
- func (c *Column) Neq(v interface{}) SqlCondition
- func (c *Column) NotBetween(leftValue interface{}, rightValue interface{}) SqlCondition
- func (c *Column) NotIn(args ...interface{}) SqlCondition
- func (c *Column) NotLike(v string) SqlCondition
- func (c *Column) Of(table *Table) *Column
- func (c Column) On(table *Table) *Column
- func (c *Column) RightLike(v string) SqlCondition
- func (c *Column) T() *Table
- func (c Column) Type(v interface{}, tagValue string) *Column
- func (c *Column) ValueBy(v interface{}) *Assignment
- type ColumnType
- 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, error)
- func (cols *Columns) Ex(ctx context.Context) *Ex
- func (cols *Columns) F(fileName string) (col *Column)
- func (cols *Columns) FieldNames() []string
- func (cols *Columns) Fields(fieldNames ...string) (*Columns, error)
- func (cols *Columns) IsNil() bool
- func (cols *Columns) Len() int
- func (cols *Columns) List() (l []*Column)
- func (cols *Columns) MustFields(fieldNames ...string) *Columns
- func (cols *Columns) Range(cb func(col *Column, idx int))
- func (cols *Columns) Remove(name string)
- type CombinationAddition
- type CommentAddition
- type ComposedCondition
- type Condition
- type DataTypeDescriber
- type DeprecatedActions
- type Dialect
- type Ex
- func (e *Ex) AppendArgs(args ...interface{})
- func (e *Ex) Args() []interface{}
- func (e *Ex) ArgsLen() int
- func (e *Ex) Err() error
- func (e Ex) Ex(ctx context.Context) *Ex
- func (e *Ex) IsNil() bool
- func (e *Ex) Query() string
- func (e *Ex) WhiteComments(comments []byte)
- func (e *Ex) WriteEnd()
- func (e *Ex) WriteExpr(expr SqlExpr)
- func (e *Ex) WriteGroup(fn func(e *Ex))
- func (e *Ex) WriteHolder(idx int)
- 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 GroupByAddition
- type Indexes
- type JoinAddition
- type Key
- type Keys
- type LimitAddition
- type Model
- type OnConflictAddition
- type Order
- type OrderByAddition
- type OtherAddition
- type SelectStatement
- type SqlAssignment
- type SqlAssignmentMarker
- type SqlCondition
- type SqlConditionMarker
- type SqlExpr
- type StmtDelete
- type StmtInsert
- type StmtSelect
- type StmtUpdate
- type StructField
- type Table
- func (t *Table) AddCol(d *Column)
- func (t *Table) AddKey(key *Key)
- func (t *Table) AssignmentsByFieldValues(fieldValues FieldValues) (assignments Assignments)
- func (t *Table) ColumnsAndValuesByFieldValues(fieldValues FieldValues) (columns *Columns, args []interface{})
- func (t *Table) Diff(prevTable *Table, dialect Dialect) (exprList []SqlExpr)
- func (t *Table) Ex(ctx context.Context) *Ex
- func (t *Table) Expr(query string, args ...interface{}) *Ex
- func (t *Table) IsNil() bool
- func (t *Table) TableName() string
- func (t Table) WithSchema(schema string) *Table
- type TableDefinition
- type Tables
- func (tables *Tables) Add(tabs ...*Table)
- func (tables *Tables) Model(structName string) *Table
- func (tables *Tables) Range(cb func(tab *Table, idx int))
- func (tables *Tables) Remove(name string)
- func (tables *Tables) Table(tableName string) *Table
- func (tables *Tables) TableNames() (names []string)
- type Toggles
- type ValuerExpr
- type WhereAddition
- type WithColDescriptions
- type WithComments
- type WithIndexes
- type WithPrimaryKey
- type WithRelations
- type WithStmt
- type WithTableDescription
- type WithUniqueIndexes
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ToggleMultiTable = "MultiTable" ToggleNeedAutoAlias = "NeedAlias" ToggleUseValues = "UseValues" )
View Source
var (
UpdateNeedLimitByWhere = errors.New("no where limit for update")
)
Functions ¶
func ContextWithToggles ¶ added in v2.13.0
func ForEachStructFieldValue ¶
func ForEachStructFieldValue(ctx context.Context, rv reflect.Value, fn func(*StructField))
func GetColumnName ¶
func MultiMayAutoAlias ¶ added in v2.13.0
func MultiMayAutoAlias(columns ...SqlExpr) *exMayAutoAlias
func OnConflict ¶
func OnConflict(columns *Columns) *onConflict
func RangeNotNilExpr ¶ added in v2.13.0
func ScanDefToTable ¶
func TableAliasFromContext ¶ added in v2.19.0
func TableNameFromContext ¶ added in v2.18.0
func Where ¶
func Where(c SqlCondition) *where
func WithTableAlias ¶ added in v2.19.0
func WithTableName ¶ added in v2.18.0
func WriteAdditions ¶ added in v2.13.0
func WriteAssignments ¶ added in v2.13.0
func WriteAssignments(e *Ex, assignments ...*Assignment)
Types ¶
type Addition ¶
type Addition interface { SqlExpr AdditionType() AdditionType }
type AdditionType ¶ added in v2.17.2
type AdditionType int
const ( AdditionJoin AdditionType = iota AdditionWhere AdditionGroupBy AdditionCombination AdditionOrderBy AdditionLimit AdditionOnConflict AdditionOther AdditionComment )
type Assignment ¶
type Assignment struct { SqlAssignmentMarker // contains filtered or unexported fields }
func ColumnsAndValues ¶
func ColumnsAndValues(columnOrColumns SqlExpr, values ...interface{}) *Assignment
func (*Assignment) IsNil ¶
func (a *Assignment) IsNil() bool
type Assignments ¶
type Assignments []*Assignment
type BuildSubQuery ¶ added in v2.14.0
type Column ¶
type Column struct { Name string FieldName string Table *Table Description []string Relation []string *ColumnType // contains filtered or unexported fields }
func (*Column) Between ¶
func (c *Column) Between(leftValue interface{}, rightValue interface{}) SqlCondition
func (*Column) Eq ¶
func (c *Column) Eq(v interface{}) SqlCondition
func (*Column) Gt ¶
func (c *Column) Gt(v interface{}) SqlCondition
func (*Column) Gte ¶
func (c *Column) Gte(v interface{}) SqlCondition
func (*Column) In ¶
func (c *Column) In(args ...interface{}) SqlCondition
func (*Column) IsNotNull ¶
func (c *Column) IsNotNull() SqlCondition
func (*Column) IsNull ¶
func (c *Column) IsNull() SqlCondition
func (*Column) LeftLike ¶
func (c *Column) LeftLike(v string) SqlCondition
func (*Column) Like ¶
func (c *Column) Like(v string) SqlCondition
func (*Column) Lt ¶
func (c *Column) Lt(v interface{}) SqlCondition
func (*Column) Lte ¶
func (c *Column) Lte(v interface{}) SqlCondition
func (*Column) Neq ¶
func (c *Column) Neq(v interface{}) SqlCondition
func (*Column) NotBetween ¶
func (c *Column) NotBetween(leftValue interface{}, rightValue interface{}) SqlCondition
func (*Column) NotIn ¶
func (c *Column) NotIn(args ...interface{}) SqlCondition
func (*Column) NotLike ¶
func (c *Column) NotLike(v string) SqlCondition
func (*Column) RightLike ¶
func (c *Column) RightLike(v string) SqlCondition
func (*Column) ValueBy ¶
func (c *Column) ValueBy(v interface{}) *Assignment
type ColumnType ¶
type ColumnType struct { Type reflect.Type GetDataType func(engine string) string Length uint64 Decimal uint64 Default *string OnUpdate *string Null bool AutoIncrement bool Comment string DeprecatedActions *DeprecatedActions }
func ColumnTypeFromTypeAndTag ¶
func ColumnTypeFromTypeAndTag(typ reflect.Type, nameAndFlags string) *ColumnType
type Columns ¶
type Columns struct {
// contains filtered or unexported fields
}
func (*Columns) AutoIncrement ¶
func (*Columns) FieldNames ¶
func (*Columns) MustFields ¶ added in v2.11.0
type CombinationAddition ¶ added in v2.14.0
type CombinationAddition struct { }
func (CombinationAddition) AdditionType ¶ added in v2.17.2
func (CombinationAddition) AdditionType() AdditionType
type CommentAddition ¶ added in v2.13.0
type CommentAddition struct { }
func (CommentAddition) AdditionType ¶ added in v2.17.2
func (CommentAddition) AdditionType() AdditionType
type ComposedCondition ¶ added in v2.13.0
type ComposedCondition struct { SqlConditionMarker // contains filtered or unexported fields }
func (*ComposedCondition) And ¶ added in v2.13.0
func (c *ComposedCondition) And(cond SqlCondition) SqlCondition
func (*ComposedCondition) Ex ¶ added in v2.13.0
func (c *ComposedCondition) Ex(ctx context.Context) *Ex
func (*ComposedCondition) IsNil ¶ added in v2.13.0
func (c *ComposedCondition) IsNil() bool
func (*ComposedCondition) Or ¶ added in v2.13.0
func (c *ComposedCondition) Or(cond SqlCondition) SqlCondition
func (*ComposedCondition) Xor ¶ added in v2.13.0
func (c *ComposedCondition) Xor(cond SqlCondition) SqlCondition
type Condition ¶
type Condition struct { SqlConditionMarker // contains filtered or unexported fields }
func (*Condition) And ¶
func (c *Condition) And(cond SqlCondition) SqlCondition
func (*Condition) Or ¶
func (c *Condition) Or(cond SqlCondition) SqlCondition
func (*Condition) Xor ¶
func (c *Condition) Xor(cond SqlCondition) SqlCondition
type DataTypeDescriber ¶
type DeprecatedActions ¶ added in v2.12.0
type DeprecatedActions struct {
RenameTo string `name:"rename"`
}
type Dialect ¶
type Dialect interface { DriverName() string PrimaryKeyName() string IsErrorUnknownDatabase(err error) bool IsErrorConflict(err error) bool CreateDatabase(dbName string) SqlExpr CreateSchema(schemaName string) SqlExpr DropDatabase(dbName string) SqlExpr CreateTableIsNotExists(t *Table) []SqlExpr DropTable(t *Table) SqlExpr TruncateTable(t *Table) SqlExpr AddColumn(col *Column) SqlExpr RenameColumn(col *Column, target *Column) SqlExpr ModifyColumn(col *Column, prev *Column) SqlExpr DropColumn(col *Column) SqlExpr AddIndex(key *Key) SqlExpr DropIndex(key *Key) SqlExpr DataType(columnType *ColumnType) SqlExpr }
type Ex ¶
func ColumnsByStruct ¶ added in v2.18.0
func ColumnsByStruct(v interface{}) *Ex
func ResolveExpr ¶ added in v2.13.0
func ResolveExpr(v interface{}) *Ex
func ResolveExprContext ¶ added in v2.13.0
func (*Ex) AppendArgs ¶
func (e *Ex) AppendArgs(args ...interface{})
func (*Ex) WhiteComments ¶
func (*Ex) WriteGroup ¶
func (*Ex) WriteHolder ¶
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 GroupByAddition ¶ added in v2.8.0
type GroupByAddition struct { }
func (GroupByAddition) AdditionType ¶ added in v2.17.2
func (GroupByAddition) AdditionType() AdditionType
type JoinAddition ¶ added in v2.13.0
type JoinAddition struct{}
func (JoinAddition) AdditionType ¶ added in v2.17.2
func (JoinAddition) AdditionType() AdditionType
type LimitAddition ¶ added in v2.8.0
type LimitAddition struct { }
func (LimitAddition) AdditionType ¶ added in v2.17.2
func (LimitAddition) AdditionType() AdditionType
type OnConflictAddition ¶ added in v2.8.0
type OnConflictAddition struct { }
func (OnConflictAddition) AdditionType ¶ added in v2.17.2
func (OnConflictAddition) AdditionType() AdditionType
type OrderByAddition ¶ added in v2.8.0
type OrderByAddition struct { }
func (OrderByAddition) AdditionType ¶ added in v2.17.2
func (OrderByAddition) AdditionType() AdditionType
type OtherAddition ¶ added in v2.8.0
type OtherAddition struct {
SqlExpr
}
func AsAddition ¶
func AsAddition(expr SqlExpr) *OtherAddition
func ForUpdate ¶
func ForUpdate() *OtherAddition
func OnDuplicateKeyUpdate ¶
func OnDuplicateKeyUpdate(assignments ...*Assignment) *OtherAddition
func Returning ¶
func Returning(expr SqlExpr) *OtherAddition
func (OtherAddition) AdditionType ¶ added in v2.17.2
func (OtherAddition) AdditionType() AdditionType
func (*OtherAddition) IsNil ¶ added in v2.8.0
func (a *OtherAddition) IsNil() bool
type SelectStatement ¶ added in v2.14.3
type SelectStatement interface { SqlExpr // contains filtered or unexported methods }
type SqlAssignment ¶
type SqlAssignment interface { SqlExpr SqlAssignmentMarker }
type SqlAssignmentMarker ¶
type SqlAssignmentMarker interface {
// contains filtered or unexported methods
}
type SqlCondition ¶
type SqlCondition interface { SqlExpr SqlConditionMarker And(cond SqlCondition) SqlCondition Or(cond SqlCondition) SqlCondition Xor(cond SqlCondition) SqlCondition }
func And ¶
func And(conditions ...SqlCondition) SqlCondition
func EmptyCond ¶ added in v2.13.0
func EmptyCond() SqlCondition
func Or ¶
func Or(conditions ...SqlCondition) SqlCondition
func Xor ¶
func Xor(conditions ...SqlCondition) SqlCondition
type SqlConditionMarker ¶
type SqlConditionMarker interface {
// contains filtered or unexported methods
}
type StmtDelete ¶
type StmtDelete struct {
// contains filtered or unexported fields
}
func Delete ¶
func Delete() *StmtDelete
func (StmtDelete) From ¶
func (s StmtDelete) From(table *Table, additions ...Addition) *StmtDelete
func (*StmtDelete) IsNil ¶
func (s *StmtDelete) IsNil() bool
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) Into ¶
func (s StmtInsert) Into(table *Table, additions ...Addition) *StmtInsert
func (*StmtInsert) IsNil ¶
func (s *StmtInsert) IsNil() bool
func (StmtInsert) Values ¶
func (s StmtInsert) Values(cols *Columns, values ...interface{}) *StmtInsert
type StmtSelect ¶
type StmtSelect struct { SelectStatement // contains filtered or unexported fields }
func Select ¶
func Select(sqlExpr SqlExpr, modifiers ...string) *StmtSelect
func (StmtSelect) From ¶
func (s StmtSelect) From(table *Table, additions ...Addition) *StmtSelect
func (*StmtSelect) IsNil ¶
func (s *StmtSelect) IsNil() bool
type StmtUpdate ¶
type StmtUpdate struct {
// contains filtered or unexported fields
}
func Update ¶
func Update(table *Table, modifiers ...string) *StmtUpdate
func (*StmtUpdate) IsNil ¶
func (s *StmtUpdate) IsNil() bool
func (StmtUpdate) Set ¶
func (s StmtUpdate) Set(assignments ...*Assignment) *StmtUpdate
func (StmtUpdate) Where ¶
func (s StmtUpdate) Where(c SqlCondition, additions ...Addition) *StmtUpdate
type StructField ¶ added in v2.18.0
type Table ¶
type Table struct { Name string Description []string Schema string ModelName string Model Model Columns Keys }
func T ¶
func T(tableName string, tableDefinitions ...TableDefinition) *Table
func TableFromModel ¶ added in v2.13.0
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) WithSchema ¶ added in v2.2.0
type TableDefinition ¶
type TableDefinition interface {
T() *Table
}
type Tables ¶
type Tables struct {
// contains filtered or unexported fields
}
func (*Tables) TableNames ¶
type Toggles ¶ added in v2.13.0
func TogglesFromContext ¶ added in v2.13.0
type ValuerExpr ¶
type ValuerExpr interface {
ValueEx() string
}
replace ? as some query snippet
examples: ? => ST_GeomFromText(?)
type WhereAddition ¶ added in v2.8.0
type WhereAddition struct{}
func (WhereAddition) AdditionType ¶ added in v2.17.2
func (WhereAddition) AdditionType() AdditionType
type WithColDescriptions ¶ added in v2.3.0
type WithComments ¶
type WithIndexes ¶
type WithIndexes interface {
Indexes() Indexes
}
type WithPrimaryKey ¶
type WithPrimaryKey interface {
PrimaryKey() []string
}
type WithRelations ¶ added in v2.3.0
type WithStmt ¶ added in v2.13.0
type WithStmt struct {
// contains filtered or unexported fields
}
func With ¶ added in v2.13.0
func With(t *Table, build BuildSubQuery, modifiers ...string) *WithStmt
func WithRecursive ¶ added in v2.13.0
func WithRecursive(t *Table, build BuildSubQuery) *WithStmt
type WithTableDescription ¶ added in v2.4.0
type WithTableDescription interface {
TableDescription() []string
}
type WithUniqueIndexes ¶
type WithUniqueIndexes interface {
UniqueIndexes() Indexes
}
Source Files ¶
- addition.go
- addition_combination.go
- addition_comment.go
- addition_group_by.go
- addition_join.go
- addition_limit.go
- addition_on_conflict.go
- addition_order_by.go
- addition_where.go
- alias.go
- assignment.go
- condition.go
- def_column.go
- def_columns.go
- def_key.go
- def_table.go
- expr.go
- functions.go
- interfaces.go
- stmt_delete.go
- stmt_insert.go
- stmt_select.go
- stmt_update.go
- stmt_with.go
- toggles.go
- utils.go
Click to show internal directories.
Click to hide internal directories.