builder

package
v1.6.5-rc10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToggleNeedAutoAlias = "NeedAlias"
	ToggleMultiTable    = "MultiTable"
	ToggleUseValues     = "UseValues"
)

Variables

View Source
var (
	RtModel        = reflect.TypeOf((*Model)(nil)).Elem()
	RtDriverValuer = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
)

Functions

func Alias

func Alias(e SqlExpr, name string) *alias

func AsAddition

func AsAddition(e SqlExpr) *addition

func Comment

func Comment(text string) *comment

func ContextWithToggleMultiTable

func ContextWithToggleMultiTable(ctx context.Context, v bool) context.Context

func ContextWithToggleNeedAutoAlias

func ContextWithToggleNeedAutoAlias(ctx context.Context, v bool) context.Context

func ContextWithToggleUseValues

func ContextWithToggleUseValues(ctx context.Context, v bool) context.Context

func ContextWithToggles

func ContextWithToggles(ctx context.Context, toggles Toggles) context.Context

func CrossJoin

func CrossJoin(tar SqlExpr) *join

func EachField

func EachField(ctx context.Context, t typesx.Type, each func(*StructField) bool)

func ForEachFieldValue

func ForEachFieldValue(ctx context.Context, v interface{}, fn func(*FieldValue))

func ForUpdate

func ForUpdate() *addition

func FullJoin

func FullJoin(tar SqlExpr) *join

func GetColumnName

func GetColumnName(name, tag string) string

func GroupBy

func GroupBy(grps ...SqlExpr) *groupby

func InnerJoin

func InnerJoin(tar SqlExpr) *join

func IsNilExpr

func IsNilExpr(e SqlExpr) bool

func Join

func Join(tar SqlExpr, prefixes ...string) *join

func LeftJoin

func LeftJoin(tar SqlExpr) *join

func Limit

func Limit(count int64) *limit

func OnConflict

func OnConflict(cols *Columns) *onconflict

func OrderBy

func OrderBy(orders ...*Order) *orderby

func RightJoin

func RightJoin(tar SqlExpr) *join

func ScanDefToTable

func ScanDefToTable(tbl *Table, i interface{})

func SplitIndexNameAndMethod

func SplitIndexNameAndMethod(v string) (string, string)

SplitIndexNameAndMethod @def index name/method

func TableAliasFromContext

func TableAliasFromContext(ctx context.Context) (string, bool)

func TableNameFromContext

func TableNameFromContext(ctx context.Context) (string, bool)

func ToMap

func ToMap(lst []string) map[string]bool

func Where

func Where(c SqlCondition) *where

func WithTabelAlias

func WithTabelAlias(tbl string) func(ctx context.Context) context.Context

func WithTableName

func WithTableName(tbl string) func(ctx context.Context) context.Context

func WriteAdditions

func WriteAdditions(e *Ex, adds ...Addition)

func WriteAssignments

func WriteAssignments(e *Ex, assignments ...*Assignment)

Types

type Addition

type Addition interface {
	SqlExpr
	AdditionKind() AdditionType
}

type AdditionType

type AdditionType int
const (
	AdditionJoin AdditionType = iota
	AdditionWhere
	AdditionGroupBy
	AdditionCombination
	AdditionOrderBy
	AdditionLimit
	AdditionOnConflict
	AdditionOther
	AdditionComment
)

func (AdditionType) AdditionKind

func (t AdditionType) AdditionKind() AdditionType

type Additions

type Additions []Addition

func (Additions) Len

func (adds Additions) Len() int

func (Additions) Less

func (adds Additions) Less(i, j int) bool

func (Additions) Swap

func (adds Additions) Swap(i, j int)

type Assignment

type Assignment struct {
	AssignmentMarker
	// contains filtered or unexported fields
}

func ColumnsAndValues

func ColumnsAndValues(columns SqlExpr, values ...interface{}) *Assignment

func (*Assignment) Ex

func (a *Assignment) Ex(ctx context.Context) *Ex

func (*Assignment) IsNil

func (a *Assignment) IsNil() bool

type AssignmentMarker

type AssignmentMarker interface {
	// contains filtered or unexported methods
}

type Assignments

type Assignments []*Assignment

type Column

type Column struct {
	Name      string
	FieldName string
	Table     *Table

	*ColumnType
	// contains filtered or unexported fields
}

func Col

func Col(name string) *Column

func (*Column) Between

func (c *Column) Between(l, r interface{}) SqlCondition

func (*Column) Dec

func (c *Column) Dec(d int) SqlExpr

func (*Column) Eq

func (c *Column) Eq(v interface{}) SqlCondition

func (*Column) Ex

func (c *Column) Ex(ctx context.Context) *Ex

func (*Column) Expr

func (c *Column) Expr(query string, args ...interface{}) *Ex

func (Column) Field

func (c Column) Field(name string) *Column

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) Inc

func (c *Column) Inc(d int) SqlExpr

func (*Column) IsNil

func (c *Column) IsNil() bool

func (*Column) IsNotNull

func (c *Column) IsNotNull() SqlCondition

func (*Column) IsNull

func (c *Column) IsNull() SqlCondition

func (*Column) LLike

func (c *Column) LLike(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(l, r interface{}) SqlCondition

func (*Column) NotIn

func (c *Column) NotIn(args ...interface{}) SqlCondition

func (*Column) NotLike

func (c *Column) NotLike(v string) SqlCondition

func (Column) Of

func (c Column) Of(t *Table) *Column

func (Column) On

func (c Column) On(t *Table) *Column

func (*Column) RLike

func (c *Column) RLike(v string) SqlCondition

func (*Column) T

func (c *Column) T() *Table

func (Column) Type

func (c Column) Type(v interface{}, tag string) *Column

func (*Column) ValueBy

func (c *Column) ValueBy(v interface{}) *Assignment

type ColumnType

type ColumnType struct {
	Type           typesx.Type
	DataType       string
	Length         uint64
	Decimal        uint64
	Default        *string
	OnUpdate       *string
	Null           bool
	AutoIncrement  bool
	Comment        string
	Desc           []string
	Rel            []string
	DeprecatedActs *DeprecatedActs
}

func AnalyzeColumnType

func AnalyzeColumnType(t typesx.Type, tag string) *ColumnType

type Columns

type Columns struct {
	// contains filtered or unexported fields
}

func Cols

func Cols(names ...string) *Columns

func (*Columns) Add

func (c *Columns) Add(cols ...*Column)

func (*Columns) AutoIncrement

func (c *Columns) AutoIncrement() *Column

func (*Columns) Clone

func (c *Columns) Clone() *Columns

func (*Columns) Col

func (c *Columns) Col(name string) *Column

func (*Columns) ColByFieldName

func (c *Columns) ColByFieldName(name string) *Column

func (*Columns) ColNames

func (c *Columns) ColNames() []string

func (*Columns) Cols

func (c *Columns) Cols(names ...string) (*Columns, error)

func (*Columns) ColsByFieldNames

func (c *Columns) ColsByFieldNames(names ...string) (*Columns, error)

func (*Columns) Ex

func (c *Columns) Ex(ctx context.Context) *Ex

func (*Columns) FieldNames

func (c *Columns) FieldNames() []string

func (*Columns) IsNil

func (c *Columns) IsNil() bool

func (*Columns) Len

func (c *Columns) Len() int

func (*Columns) List

func (c *Columns) List() []*Column

func (*Columns) MustCols

func (c *Columns) MustCols(names ...string) *Columns

func (*Columns) MustColsByFieldNames

func (c *Columns) MustColsByFieldNames(names ...string) *Columns

func (*Columns) Range

func (c *Columns) Range(f func(*Column, int))

type CondCompose

type CondCompose struct {
	SqlConditionMarker
	// contains filtered or unexported fields
}

func ComposeConditions

func ComposeConditions(op string, conds ...SqlCondition) *CondCompose

func (*CondCompose) And

func (c *CondCompose) And(cond SqlCondition) SqlCondition

func (*CondCompose) Ex

func (c *CondCompose) Ex(ctx context.Context) *Ex

func (*CondCompose) IsNil

func (c *CondCompose) IsNil() bool

func (*CondCompose) Or

func (*CondCompose) Xor

func (c *CondCompose) Xor(cond SqlCondition) SqlCondition

type Condition

type Condition struct {
	SqlConditionMarker
	// contains filtered or unexported fields
}

func AsCond

func AsCond(e SqlExpr) *Condition

func (*Condition) And

func (c *Condition) And(cond SqlCondition) SqlCondition

func (*Condition) Ex

func (c *Condition) Ex(ctx context.Context) *Ex

func (*Condition) IsNil

func (c *Condition) IsNil() bool

func (*Condition) Or

func (c *Condition) Or(cond SqlCondition) SqlCondition

func (*Condition) Xor

func (c *Condition) Xor(cond SqlCondition) SqlCondition

type DataTypeDescriber

type DataTypeDescriber interface {
	DataType(driver string) string
}

type DeprecatedActs

type DeprecatedActs struct {
	RenameTo string `name:"rename"`
}

type Dialect

type Dialect interface {
	DriverName() string
	PrimaryKeyName() string
	IsErrorUnknownDatabase(error) bool
	IsErrorConflict(error) bool
	CreateDatabase(string) SqlExpr
	CreateSchema(string) SqlExpr
	DropDatabase(string) SqlExpr
	CreateTableIsNotExists(t *Table) []SqlExpr
	DropTable(*Table) SqlExpr
	TruncateTable(*Table) SqlExpr
	AddColumn(*Column) SqlExpr
	RenameColumn(*Column, *Column) SqlExpr
	ModifyColumn(*Column, *Column) SqlExpr
	DropColumn(*Column) SqlExpr
	AddIndex(*Key) SqlExpr
	DropIndex(*Key) SqlExpr
	DataType(*ColumnType) SqlExpr
}

type Ex

type Ex struct {
	// contains filtered or unexported fields
}

func ColumnsByStruct

func ColumnsByStruct(v interface{}) *Ex

func ExactlyExpr

func ExactlyExpr(query string, args ...interface{}) *Ex

func Expr

func Expr(query string, args ...interface{}) *Ex

func ResolveExpr

func ResolveExpr(v interface{}) *Ex

func ResolveExprContext

func ResolveExprContext(ctx context.Context, v interface{}) *Ex

func (*Ex) AppendArgs

func (e *Ex) AppendArgs(args ...interface{})

func (*Ex) Args

func (e *Ex) Args() []interface{}

func (*Ex) ArgsLen

func (e *Ex) ArgsLen() int

func (*Ex) Err

func (e *Ex) Err() error

func (*Ex) Ex

func (e *Ex) Ex(ctx context.Context) *Ex

func (*Ex) Grow

func (e *Ex) Grow(n int)

func (*Ex) IsNil

func (e *Ex) IsNil() bool

func (*Ex) Query

func (e *Ex) Query() string

func (*Ex) SetExactly

func (e *Ex) SetExactly(exactly bool)

func (*Ex) WriteComments

func (e *Ex) WriteComments(comments []byte)

func (*Ex) WriteEnd

func (e *Ex) WriteEnd()

func (*Ex) WriteExpr

func (e *Ex) WriteExpr(expr SqlExpr)

func (*Ex) WriteGroup

func (e *Ex) WriteGroup(f func(e *Ex))

func (*Ex) WriteHolder

func (e *Ex) WriteHolder(idx int)

func (*Ex) WriteQuery

func (e *Ex) WriteQuery(query string)

func (*Ex) WriteQueryByte

func (e *Ex) WriteQueryByte(b byte)

func (*Ex) WriteQueryRune

func (e *Ex) WriteQueryRune(r rune)

type FieldValue

type FieldValue struct {
	Field     StructField
	TableName string
	Value     reflect.Value
}

type FieldValues

type FieldValues map[string]interface{}

func FieldValueFromStruct

func FieldValueFromStruct(v interface{}, names []string) FieldValues

func FieldValueFromStructByNoneZero

func FieldValueFromStructByNoneZero(v interface{}, excludes ...string) FieldValues

type FieldsFactory

type FieldsFactory struct {
	// contains filtered or unexported fields
}

func (*FieldsFactory) TableFieldsFor

func (ft *FieldsFactory) TableFieldsFor(ctx context.Context, t typesx.Type) []*StructField

type Function

type Function struct {
	// contains filtered or unexported fields
}

func Avg

func Avg(es ...SqlExpr) *Function

func Count

func Count(es ...SqlExpr) *Function

func Distinct

func Distinct(es ...SqlExpr) *Function

func First

func First(es ...SqlExpr) *Function

func Func

func Func(name string, es ...SqlExpr) *Function

func Last

func Last(es ...SqlExpr) *Function

func Max

func Max(es ...SqlExpr) *Function

func Min

func Min(es ...SqlExpr) *Function

func Sum

func Sum(es ...SqlExpr) *Function

func (*Function) Ex

func (f *Function) Ex(ctx context.Context) *Ex

func (*Function) IsNil

func (f *Function) IsNil() bool

type IndexDef

type IndexDef struct {
	FieldNames []string
	ColNames   []string
	Expr       string
}

IndexDef @def index xxx/BTREE FieldA FieldB ...

func ParseIndexDef

func ParseIndexDef(names ...string) *IndexDef

func (IndexDef) TableExpr

func (i IndexDef) TableExpr(t *Table) *Ex

func (IndexDef) ToDefs

func (i IndexDef) ToDefs() []string

type IndexDefine

type IndexDefine struct {
	Kind   string
	Name   string
	Method string
	IndexDef
}

func ParseIndexDefine

func ParseIndexDefine(def string) *IndexDefine

func (IndexDefine) ID

func (i IndexDefine) ID() string

type Indexes

type Indexes map[string][]string

type Key

type Key struct {
	Table    *Table
	Name     string
	IsUnique bool
	Method   string
	Def      IndexDef
}

func Index

func Index(name string, cols *Columns, exprs ...string) *Key

func PrimaryKey

func PrimaryKey(cols *Columns) *Key

func UniqueIndex

func UniqueIndex(name string, cols *Columns, exprs ...string) *Key

func (Key) IsPrimary

func (k Key) IsPrimary() bool

func (Key) On

func (k Key) On(t *Table) *Key

func (*Key) T

func (k *Key) T() *Table

func (Key) Using

func (k Key) Using(method string) *Key

type Keys

type Keys struct {
	// contains filtered or unexported fields
}

func (*Keys) Add

func (ks *Keys) Add(keys ...*Key)

func (*Keys) Clone

func (ks *Keys) Clone() *Keys

func (*Keys) Key

func (ks *Keys) Key(name string) *Key

func (*Keys) Len

func (ks *Keys) Len() int

func (*Keys) Range

func (ks *Keys) Range(f func(k *Key, idx int))

type Model

type Model interface {
	TableName() string
}

type Order

type Order struct {
	// contains filtered or unexported fields
}

func AscOrder

func AscOrder(target SqlExpr) *Order

func DescOrder

func DescOrder(target SqlExpr) *Order

func (*Order) Ex

func (o *Order) Ex(ctx context.Context) *Ex

func (*Order) IsNil

func (o *Order) IsNil() bool

type SelectStatement

type SelectStatement interface {
	SqlExpr
	// contains filtered or unexported methods
}

type SqlAssignment

type SqlAssignment interface {
	SqlExpr
	AssignmentMarker
}

type SqlCondition

var EmptyCondition SqlCondition = (*Condition)(nil)

func And

func And(conds ...SqlCondition) SqlCondition

func Or

func Or(conds ...SqlCondition) SqlCondition

func Xor

func Xor(conds ...SqlCondition) SqlCondition

type SqlConditionMarker

type SqlConditionMarker interface {
	// contains filtered or unexported methods
}

type SqlExpr

type SqlExpr interface {
	IsNil() bool
	Ex(ctx context.Context) *Ex
}

func ExprBy

func ExprBy(build func(context.Context) *Ex) SqlExpr

func Multi

func Multi(es ...SqlExpr) SqlExpr

func MultiWith

func MultiWith(connector string, es ...SqlExpr) SqlExpr

type StmtDelete

type StmtDelete struct {
	// contains filtered or unexported fields
}

func Delete

func Delete() *StmtDelete

func (*StmtDelete) Ex

func (s *StmtDelete) Ex(ctx context.Context) *Ex

func (StmtDelete) From

func (s StmtDelete) From(tbl *Table, adds ...Addition) *StmtDelete

func (*StmtDelete) IsNil

func (s *StmtDelete) IsNil() bool

type StmtInsert

type StmtInsert struct {
	// contains filtered or unexported fields
}

func Insert

func Insert(modifiers ...string) *StmtInsert

func (*StmtInsert) Ex

func (s *StmtInsert) Ex(ctx context.Context) *Ex

func (StmtInsert) Into

func (s StmtInsert) Into(tbl *Table, adds ...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(e SqlExpr, modifiers ...string) *StmtSelect

func (*StmtSelect) Ex

func (s *StmtSelect) Ex(ctx context.Context) *Ex

func (StmtSelect) From

func (s StmtSelect) From(tbl *Table, adds ...Addition) *StmtSelect

func (*StmtSelect) IsNil

func (s *StmtSelect) IsNil() bool

type StmtUpdate

type StmtUpdate struct {
	// contains filtered or unexported fields
}

func Update

func Update(tbl *Table, modifiers ...string) *StmtUpdate

func (*StmtUpdate) Ex

func (s *StmtUpdate) Ex(ctx context.Context) *Ex

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, adds ...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 ColumnType
}

func StructFieldsFor

func StructFieldsFor(ctx context.Context, t typesx.Type) []*StructField

func (*StructField) FieldModelValue

func (sf *StructField) FieldModelValue(v reflect.Value) reflect.Value

func (*StructField) FieldValue

func (sf *StructField) FieldValue(v reflect.Value) reflect.Value

type Table

type Table struct {
	Name      string
	Desc      []string
	Schema    string
	ModelName string
	Model     Model

	Columns
	Keys
}

func T

func T(tblName string, defs ...TableDefinition) *Table

func TableFromModel

func TableFromModel(m Model) *Table

func (*Table) AddCol

func (t *Table) AddCol(c *Column)

func (*Table) AddKey

func (t *Table) AddKey(k *Key)

func (*Table) AssignmentsByFieldValues

func (t *Table) AssignmentsByFieldValues(fvs FieldValues) Assignments

func (*Table) ColumnsAndValuesByFieldValues

func (t *Table) ColumnsAndValuesByFieldValues(fvs FieldValues) (*Columns, []interface{})

func (*Table) Diff

func (t *Table) Diff(prevT *Table, d Dialect) (exprList []SqlExpr)

func (*Table) Ex

func (t *Table) Ex(ctx context.Context) *Ex

func (*Table) Expr

func (t *Table) Expr(query string, args ...interface{}) *Ex

func (*Table) IsNil

func (t *Table) IsNil() bool

func (*Table) TableName

func (t *Table) TableName() string

func (Table) WithSchema

func (t Table) WithSchema(schema string) *Table

type TableDefinition

type TableDefinition interface{ T() *Table }

type Tables

type Tables struct {
	// contains filtered or unexported fields
}

func (*Tables) Add

func (t *Tables) Add(tables ...*Table)

func (*Tables) Model

func (t *Tables) Model(typename string) *Table

func (*Tables) Range

func (t *Tables) Range(f func(*Table, int))

func (*Tables) Remove

func (t *Tables) Remove(name string)

func (*Tables) Table

func (t *Tables) Table(name string) *Table

func (*Tables) TableNames

func (t *Tables) TableNames() []string

type Toggles

type Toggles map[string]bool

func TogglesFromContext

func TogglesFromContext(ctx context.Context) Toggles

func (Toggles) Is

func (toggles Toggles) Is(k string) bool

func (Toggles) Merge

func (toggles Toggles) Merge(follows Toggles) Toggles

type ValueExpr

type ValueExpr interface {
	ValueEx() string
}

type WithColDesc

type WithColDesc interface {
	ColDesc() map[string][]string
}

type WithColRel

type WithColRel interface {
	ColRel() map[string][]string
}

type WithComments

type WithComments interface {
	Comments() map[string]string
}

type WithIndexes

type WithIndexes interface {
	Indexes() Indexes
}

type WithPrimaryKey

type WithPrimaryKey interface {
	PrimaryKey() []string
}

type WithTableDesc

type WithTableDesc interface {
	TableDesc() []string
}

type WithUniqueIndexes

type WithUniqueIndexes interface {
	UniqueIndexes() Indexes
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL