Documentation ¶
Overview ¶
Package sqlbuilder GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Index ¶
- Variables
- func ContextWithToggles(ctx context.Context, toggles Toggles) context.Context
- func EachStructField(ctx context.Context, tpe typesx.Type, each func(p *StructField) bool)
- func ForEachStructFieldValue(ctx context.Context, v interface{}, fn func(*StructFieldValue))
- func GetColumnName(fieldName, tagValue string) string
- func IsNilExpr(e SqlExpr) bool
- func RangeNotNilExpr(exprs []SqlExpr, each func(e SqlExpr, i int))
- func ResolveIndexNameAndMethod(n string) (name string, method string)
- func TableAliasFromContext(ctx context.Context) string
- func TableNameFromContext(ctx context.Context) string
- func ToMap(list []string) map[string]bool
- 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 ColOptionFunc
- type Column
- type ColumnCollection
- type ColumnCollectionManger
- type ColumnDef
- type ColumnSetter
- type ColumnValueExpr
- func Between[T comparable](leftValue T, rightValue T) ColumnValueExpr[T]
- func Des[T any](v T) ColumnValueExpr[T]
- func Eq[T comparable](expect T) ColumnValueExpr[T]
- func EqCol[T comparable](expect TypedColumn[T]) ColumnValueExpr[T]
- func Gt[T comparable](min T) ColumnValueExpr[T]
- func Gte[T comparable](min T) ColumnValueExpr[T]
- func In[T any](values ...T) ColumnValueExpr[T]
- func Incr[T any](v T) ColumnValueExpr[T]
- func IsNotNull[T any]() ColumnValueExpr[T]
- func IsNull[T any]() ColumnValueExpr[T]
- func LeftLike[T ~string](s T) ColumnValueExpr[T]
- func Like[T ~string](s T) ColumnValueExpr[T]
- func Lt[T comparable](max T) ColumnValueExpr[T]
- func Lte[T comparable](max T) ColumnValueExpr[T]
- func Neq[T any](expect T) ColumnValueExpr[T]
- func NeqCol[T comparable](expect TypedColumn[T]) ColumnValueExpr[T]
- func NotBetween[T comparable](leftValue T, rightValue T) ColumnValueExpr[T]
- func NotIn[T any](values ...T) ColumnValueExpr[T]
- func NotLike[T ~string](s T) ColumnValueExpr[T]
- func RightLike[T ~string](s T) ColumnValueExpr[T]
- func Value[T any](v T) ColumnValueExpr[T]
- type CombinationAddition
- type ComposedCondition
- func (c *ComposedCondition) And(cond SqlCondition) SqlCondition
- func (c *ComposedCondition) Ex(ctx context.Context) *Ex
- func (c *ComposedCondition) IsNil() bool
- func (c *ComposedCondition) Or(cond SqlCondition) SqlCondition
- func (v ComposedCondition) RuntimeDoc(names ...string) ([]string, bool)
- func (c *ComposedCondition) Xor(cond SqlCondition) SqlCondition
- type Condition
- type DataTypeDescriber
- type DeprecatedActions
- type Ex
- func (e *Ex) AppendArgs(args ...any)
- func (e *Ex) Args() []any
- func (e *Ex) ArgsLen() int
- func (e *Ex) Err() error
- func (e *Ex) Ex(ctx context.Context) *Ex
- func (e *Ex) Grow(n int)
- func (e *Ex) IsNil() bool
- func (e *Ex) Query() string
- func (e *Ex) QueryGrow(n int)
- func (e *Ex) SetExactly(exactly bool)
- func (e *Ex) WhiteComments(comments []byte)
- func (e *Ex) WriteByte(b byte) error
- func (e *Ex) WriteEnd()
- func (e *Ex) WriteExpr(expr SqlExpr)
- func (e *Ex) WriteGroup(fn func(e *Ex))
- func (e *Ex) WriteHolder(idx int)
- func (e *Ex) WriteQuery(s string)
- func (e *Ex) WriteQueryByte(b byte)
- func (e *Ex) WriteString(s string) (int, error)
- 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 IndexDefine
- type IndexOptionFunc
- type Indexes
- type JoinAddition
- type Key
- type KeyCollection
- type KeyCollectionManager
- type KeyDef
- type LimitAddition
- type Model
- type NamedArg
- type NamedArgSet
- type OnConflictAddition
- type Order
- type OtherAddition
- type SelectStatement
- type SqlCondition
- type SqlConditionMarker
- type SqlExpr
- type StmtDelete
- type StmtInsert
- type StmtSelect
- type StmtUpdate
- type StructField
- type StructFieldValue
- type StructFieldsFactory
- type Table
- type TableDefinition
- type TableExprParse
- type TableWithTableName
- type Tables
- type Toggles
- type TypedColumn
- type ValuerExpr
- 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 EachStructField ¶
func ForEachStructFieldValue ¶
func ForEachStructFieldValue(ctx context.Context, v interface{}, fn func(*StructFieldValue))
func GetColumnName ¶
func RangeNotNilExpr ¶
func TableAliasFromContext ¶
func TableNameFromContext ¶
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 )
func (AdditionType) RuntimeDoc ¶
func (AdditionType) RuntimeDoc(names ...string) ([]string, bool)
type Assignment ¶
type Assignment interface { SqlExpr SqlAssignment() }
func ColumnsAndValues ¶
func ColumnsAndValues(columnOrColumns SqlExpr, values ...any) Assignment
type Assignments ¶
type Assignments []Assignment
func AssignmentsByFieldValues ¶
func AssignmentsByFieldValues(t Table, fieldValues FieldValues) (assignments Assignments)
func (Assignments) RuntimeDoc ¶
func (Assignments) RuntimeDoc(names ...string) ([]string, bool)
type BuildSubQuery ¶
func (BuildSubQuery) RuntimeDoc ¶
func (BuildSubQuery) RuntimeDoc(names ...string) ([]string, bool)
type ColOptionFunc ¶
type ColOptionFunc func(c ColumnSetter)
func ColDef ¶
func ColDef(def ColumnDef) ColOptionFunc
func ColField ¶
func ColField(fieldName string) ColOptionFunc
func ColTypeOf ¶
func ColTypeOf(v any, tagValue string) ColOptionFunc
func (ColOptionFunc) RuntimeDoc ¶
func (ColOptionFunc) RuntimeDoc(names ...string) ([]string, bool)
type Column ¶
type Column interface { SqlExpr TableDefinition Def() ColumnDef Expr(query string, args ...any) *Ex Of(table Table) Column With(optionFns ...ColOptionFunc) Column MatchName(name string) bool Name() string FieldName() string }
func Col ¶
func Col(name string, fns ...ColOptionFunc) Column
type ColumnCollection ¶
type ColumnCollection interface { SqlExpr Of(t Table) ColumnCollection F(name string) Column Col(name string) Column Cols(names ...string) ColumnCollection RangeCol(cb func(col Column, idx int) bool) Len() int }
func Cols ¶
func Cols(names ...string) ColumnCollection
func ColumnCollectionFromList ¶
func ColumnCollectionFromList(list []Column) ColumnCollection
func ColumnsAndValuesByFieldValues ¶
func ColumnsAndValuesByFieldValues(t Table, fieldValues FieldValues) (cols ColumnCollection, args []interface{})
type ColumnCollectionManger ¶
type ColumnCollectionManger interface {
AddCol(cols ...Column)
}
type ColumnDef ¶
type ColumnDef struct { Type typex.Type DataType string Length uint64 Decimal uint64 Default *string OnUpdate *string Null bool AutoIncrement bool DeprecatedActions *DeprecatedActions Comment string Description []string Relation []string }
func ColumnDefFromTypeAndTag ¶
type ColumnSetter ¶
type ColumnValueExpr ¶
+gengo:runtimedoc=false
func Between ¶
func Between[T comparable](leftValue T, rightValue T) ColumnValueExpr[T]
func Des ¶
func Des[T any](v T) ColumnValueExpr[T]
func Eq ¶
func Eq[T comparable](expect T) ColumnValueExpr[T]
func EqCol ¶
func EqCol[T comparable](expect TypedColumn[T]) ColumnValueExpr[T]
func Gt ¶
func Gt[T comparable](min T) ColumnValueExpr[T]
func Gte ¶
func Gte[T comparable](min T) ColumnValueExpr[T]
func In ¶
func In[T any](values ...T) ColumnValueExpr[T]
func Incr ¶
func Incr[T any](v T) ColumnValueExpr[T]
func IsNotNull ¶
func IsNotNull[T any]() ColumnValueExpr[T]
func IsNull ¶
func IsNull[T any]() ColumnValueExpr[T]
func LeftLike ¶
func LeftLike[T ~string](s T) ColumnValueExpr[T]
func Like ¶
func Like[T ~string](s T) ColumnValueExpr[T]
func Lt ¶
func Lt[T comparable](max T) ColumnValueExpr[T]
func Lte ¶
func Lte[T comparable](max T) ColumnValueExpr[T]
func Neq ¶
func Neq[T any](expect T) ColumnValueExpr[T]
func NeqCol ¶
func NeqCol[T comparable](expect TypedColumn[T]) ColumnValueExpr[T]
func NotBetween ¶
func NotBetween[T comparable](leftValue T, rightValue T) ColumnValueExpr[T]
func NotIn ¶
func NotIn[T any](values ...T) ColumnValueExpr[T]
func NotLike ¶
func NotLike[T ~string](s T) ColumnValueExpr[T]
func RightLike ¶
func RightLike[T ~string](s T) ColumnValueExpr[T]
func Value ¶
func Value[T any](v T) ColumnValueExpr[T]
type CombinationAddition ¶
type CombinationAddition interface { Addition All(stmtSelect SelectStatement) CombinationAddition Distinct(stmtSelect SelectStatement) CombinationAddition }
func Expect ¶
func Expect() CombinationAddition
func Intersect ¶
func Intersect() CombinationAddition
func Union ¶
func Union() CombinationAddition
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) RuntimeDoc ¶
func (v ComposedCondition) RuntimeDoc(names ...string) ([]string, bool)
func (*ComposedCondition) Xor ¶
func (c *ComposedCondition) Xor(cond SqlCondition) SqlCondition
type Condition ¶
type Condition struct { SqlConditionMarker // contains filtered or unexported fields }
type DataTypeDescriber ¶
type DeprecatedActions ¶
type DeprecatedActions struct {
RenameTo string `name:"rename"`
}
func (DeprecatedActions) RuntimeDoc ¶
func (v DeprecatedActions) RuntimeDoc(names ...string) ([]string, bool)
type Ex ¶
type Ex struct {
// contains filtered or unexported fields
}
func ColumnsByStruct ¶
func ColumnsByStruct(v interface{}) *Ex
func ExactlyExpr ¶
func ResolveExpr ¶
func (*Ex) AppendArgs ¶
func (*Ex) SetExactly ¶
func (*Ex) WhiteComments ¶
func (*Ex) WriteGroup ¶
func (*Ex) WriteHolder ¶
func (*Ex) WriteQuery ¶
func (*Ex) WriteQueryByte ¶
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)
func (FieldValues) RuntimeDoc ¶
func (FieldValues) RuntimeDoc(names ...string) ([]string, bool)
type GroupByAddition ¶
type GroupByAddition interface { Addition Having(cond SqlExpr) GroupByAddition }
func GroupBy ¶
func GroupBy(groups ...SqlExpr) GroupByAddition
type IndexDefine ¶
func ParseIndexDefine ¶
func ParseIndexDefine(def string) *IndexDefine
ParseIndexDefine @def index i_xxx/BTREE Name @def index i_xxx/GIST TEST/gist_trgm_ops
func (IndexDefine) ID ¶
func (i IndexDefine) ID() string
func (IndexDefine) RuntimeDoc ¶
func (v IndexDefine) RuntimeDoc(names ...string) ([]string, bool)
type IndexOptionFunc ¶
type IndexOptionFunc func(k *key)
func IndexColNameAndOptions ¶
func IndexColNameAndOptions(colNameAndOptions ...string) IndexOptionFunc
func IndexUnique ¶
func IndexUnique(unique bool) IndexOptionFunc
func IndexUsing ¶
func IndexUsing(method string) IndexOptionFunc
func (IndexOptionFunc) RuntimeDoc ¶
func (IndexOptionFunc) RuntimeDoc(names ...string) ([]string, bool)
type JoinAddition ¶
type JoinAddition interface { Addition On(joinCondition SqlExpr) JoinAddition Using(joinColumnList ...Column) JoinAddition }
func CrossJoin ¶
func CrossJoin(table SqlExpr) JoinAddition
func FullJoin ¶
func FullJoin(table SqlExpr) JoinAddition
func InnerJoin ¶
func InnerJoin(table SqlExpr) JoinAddition
func Join ¶
func Join(table SqlExpr, prefixes ...string) JoinAddition
func LeftJoin ¶
func LeftJoin(table SqlExpr) JoinAddition
func RightJoin ¶
func RightJoin(table SqlExpr) JoinAddition
type Key ¶
type Key interface { SqlExpr TableDefinition Of(table Table) Key IsPrimary() bool IsUnique() bool Name() string Columns() ColumnCollection }
func Index ¶
func Index(name string, columns ColumnCollection, optFns ...IndexOptionFunc) Key
func PrimaryKey ¶
func PrimaryKey(columns ColumnCollection, optFns ...IndexOptionFunc) Key
func UniqueIndex ¶
func UniqueIndex(name string, columns ColumnCollection, optFns ...IndexOptionFunc) Key
type KeyCollection ¶
type KeyCollection interface { Of(t Table) KeyCollection K(name string) Key RangeKey(func(k Key, i int) bool) Keys(names ...string) KeyCollection Len() int }
type KeyCollectionManager ¶
type KeyCollectionManager interface {
AddKey(keys ...Key)
}
type LimitAddition ¶
type LimitAddition interface { Addition Offset(offset int64) LimitAddition }
func Limit ¶
func Limit(rowCount int64) LimitAddition
type NamedArgSet ¶
func (NamedArgSet) RuntimeDoc ¶
func (NamedArgSet) RuntimeDoc(names ...string) ([]string, bool)
type OnConflictAddition ¶
type OnConflictAddition interface { Addition DoNothing() OnConflictAddition DoUpdateSet(assignments ...Assignment) OnConflictAddition }
func OnConflict ¶
func OnConflict(columns ColumnCollection) OnConflictAddition
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
func (OtherAddition) RuntimeDoc ¶
func (v OtherAddition) RuntimeDoc(names ...string) ([]string, bool)
type SelectStatement ¶
type SelectStatement interface { SqlExpr // contains filtered or unexported methods }
type SqlCondition ¶
type SqlCondition interface { SqlExpr SqlConditionMarker }
func And ¶
func And(conditions ...SqlExpr) SqlCondition
func EmptyCond ¶
func EmptyCond() SqlCondition
func Or ¶
func Or(conditions ...SqlExpr) SqlCondition
func Xor ¶
func Xor(conditions ...SqlExpr) SqlCondition
type SqlConditionMarker ¶
type SqlConditionMarker interface {
// contains filtered or unexported methods
}
type SqlExpr ¶
func MultiMayAutoAlias ¶
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 ColumnCollection, values ...interface{}) *StmtInsert
type StmtSelect ¶
type StmtSelect struct { SelectStatement // contains filtered or unexported fields }
func Select ¶
func Select(sqlExpr SqlExpr, modifiers ...SqlExpr) *StmtSelect
func (StmtSelect) From ¶
func (s StmtSelect) From(table Table, additions ...Addition) *StmtSelect
func (*StmtSelect) IsNil ¶
func (s *StmtSelect) IsNil() bool
func (StmtSelect) RuntimeDoc ¶
func (v StmtSelect) RuntimeDoc(names ...string) ([]string, 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 SqlExpr, additions ...Addition) *StmtUpdate
type StructField ¶
type StructField struct { Name string FieldName string Type typesx.Type Field typesx.StructField Tags map[string]reflectx.StructTag Loc []int ModelLoc []int ColumnType ColumnDef }
func StructFieldsFor ¶
func StructFieldsFor(ctx context.Context, typ typesx.Type) []*StructField
func (*StructField) FieldModelValue ¶
func (p *StructField) FieldModelValue(structReflectValue reflect.Value) reflect.Value
func (*StructField) FieldValue ¶
func (p *StructField) FieldValue(structReflectValue reflect.Value) reflect.Value
func (StructField) RuntimeDoc ¶
func (v StructField) RuntimeDoc(names ...string) ([]string, bool)
type StructFieldValue ¶
type StructFieldValue struct { Field StructField TableName string Value reflect.Value }
func (StructFieldValue) RuntimeDoc ¶
func (v StructFieldValue) RuntimeDoc(names ...string) ([]string, bool)
type StructFieldsFactory ¶
type StructFieldsFactory struct {
// contains filtered or unexported fields
}
func (*StructFieldsFactory) TableFieldsFor ¶
func (tf *StructFieldsFactory) TableFieldsFor(ctx context.Context, typ typesx.Type) []*StructField
type Table ¶
type Table interface { SqlExpr // TableName of table TableName() string // K // get index by key name // primaryKey could be use `pk` K(k string) Key // F // get col by col name or struct field names F(name string) Column // Cols // get cols by col names or struct field name Cols(names ...string) ColumnCollection // Keys // get indexes by index names Keys(names ...string) KeyCollection }
func T ¶
func T(tableName string, tableDefinitions ...TableDefinition) Table
func TableFromModel ¶
type TableDefinition ¶
type TableDefinition interface {
T() Table
}
type TableExprParse ¶
type TableWithTableName ¶
type Tables ¶
type Tables struct {
// contains filtered or unexported fields
}
func (*Tables) TableNames ¶
type Toggles ¶
func TogglesFromContext ¶
type TypedColumn ¶
type TypedColumn[T any] interface { Column V(op ColumnValueExpr[T]) SqlExpr By(ops ...ColumnValueExpr[T]) Assignment }
func CastCol ¶
func CastCol[T any](col Column) TypedColumn[T]
func TypedCol ¶
func TypedCol[T any](name string, fns ...ColOptionFunc) TypedColumn[T]
func TypedColOf ¶
func TypedColOf[T any](t Table, name string) TypedColumn[T]
type ValuerExpr ¶
type ValuerExpr interface {
ValueEx() string
}
ValuerExpr replace ? as some query snippet
examples: ? => ST_GeomFromText(?)
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
- column_type.go
- condition.go
- def_column.go
- def_column__typed.go
- def_column_collection.go
- def_key.go
- def_key_collection.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
- utils_field.go
- zz_generated.runtimedoc.go
Click to show internal directories.
Click to hide internal directories.