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 ¶
func ForEachStructFieldValue ¶
func ForEachStructFieldValue(ctx context.Context, rv reflect.Value, fn func(*StructField))
func GetColumnName ¶
func MultiMayAutoAlias ¶
func MultiMayAutoAlias(columns ...SqlExpr) *exMayAutoAlias
func OnConflict ¶
func OnConflict(columns *Columns) *onConflict
func RangeNotNilExpr ¶
func ScanDefToTable ¶
func TableAliasFromContext ¶
func TableNameFromContext ¶
func Where ¶
func Where(c SqlCondition) *where
func WithTableAlias ¶
func WriteAdditions ¶
func WriteAssignments ¶
func WriteAssignments(e *Ex, assignments ...*Assignment)
Types ¶
type Addition ¶
type Addition interface { SqlExpr AdditionType() AdditionType }
type AdditionType ¶
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 ¶
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 ¶
type CombinationAddition ¶
type CombinationAddition struct { }
func (CombinationAddition) AdditionType ¶
func (CombinationAddition) AdditionType() AdditionType
type CommentAddition ¶
type CommentAddition struct { }
func (CommentAddition) AdditionType ¶
func (CommentAddition) AdditionType() AdditionType
type ComposedCondition ¶
type ComposedCondition struct { SqlConditionMarker // contains filtered or unexported fields }
func (*ComposedCondition) And ¶
func (c *ComposedCondition) And(cond SqlCondition) SqlCondition
func (*ComposedCondition) IsNil ¶
func (c *ComposedCondition) IsNil() bool
func (*ComposedCondition) Or ¶
func (c *ComposedCondition) Or(cond SqlCondition) SqlCondition
func (*ComposedCondition) Xor ¶
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 ¶
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 ¶
func ColumnsByStruct(v interface{}) *Ex
func ResolveExpr ¶
func ResolveExpr(v interface{}) *Ex
func ResolveExprContext ¶
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 ¶
type GroupByAddition struct { }
func (GroupByAddition) AdditionType ¶
func (GroupByAddition) AdditionType() AdditionType
type JoinAddition ¶
type JoinAddition struct{}
func (JoinAddition) AdditionType ¶
func (JoinAddition) AdditionType() AdditionType
type LimitAddition ¶
type LimitAddition struct { }
func (LimitAddition) AdditionType ¶
func (LimitAddition) AdditionType() AdditionType
type OnConflictAddition ¶
type OnConflictAddition struct { }
func (OnConflictAddition) AdditionType ¶
func (OnConflictAddition) AdditionType() AdditionType
type OrderByAddition ¶
type OrderByAddition struct { }
func (OrderByAddition) AdditionType ¶
func (OrderByAddition) AdditionType() AdditionType
type OtherAddition ¶
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 ¶
func (OtherAddition) AdditionType() AdditionType
func (*OtherAddition) IsNil ¶
func (a *OtherAddition) IsNil() bool
type SelectStatement ¶
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 ¶
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 ¶
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 ¶
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 ¶
type TableDefinition ¶
type TableDefinition interface {
T() *Table
}
type Tables ¶
type Tables struct {
// contains filtered or unexported fields
}
func (*Tables) TableNames ¶
type Toggles ¶
func TogglesFromContext ¶
type ValuerExpr ¶
type ValuerExpr interface {
ValueEx() string
}
replace ? as some query snippet
examples: ? => ST_GeomFromText(?)
type WhereAddition ¶
type WhereAddition struct{}
func (WhereAddition) AdditionType ¶
func (WhereAddition) AdditionType() AdditionType
type WithColDescriptions ¶
type WithComments ¶
type WithIndexes ¶
type WithIndexes interface {
Indexes() Indexes
}
type WithPrimaryKey ¶
type WithPrimaryKey interface {
PrimaryKey() []string
}
type WithRelations ¶
type WithStmt ¶
type WithStmt struct {
// contains filtered or unexported fields
}
func WithRecursive ¶
func WithRecursive(t *Table, build BuildSubQuery) *WithStmt
type WithTableDescription ¶
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.