builder

package
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2018 License: MIT Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UpdateNeedLimitByWhere = errors.New("no where limit for update")
)

Functions

func AsAddition

func AsAddition(expr SqlExpr) *otherAddition

func AscOrder

func AscOrder(expr SqlExpr) *order

func Comment

func Comment(c string) comment

func DescOrder

func DescOrder(expr SqlExpr) *order

func ForEachStructFieldValue

func ForEachStructFieldValue(rv reflect.Value, fn func(structFieldValue reflect.Value, structField reflect.StructField, columnName string, tagValue string))

func ForUpdate

func ForUpdate() *otherAddition

func GetColumnName

func GetColumnName(fieldName, tagValue string) string

func GroupBy

func GroupBy(groups ...SqlExpr) *groupBy

func Limit

func Limit(rowCount int64) *limit

func OnConflict

func OnConflict(columns *Columns) *onConflict

func OnDuplicateKeyUpdate

func OnDuplicateKeyUpdate(assignments ...*Assignment) *otherAddition

func OrderBy

func OrderBy(orders ...*order) *orderBy

func ResolveIndexNameAndMethod

func ResolveIndexNameAndMethod(n string) (name string, method string)

func Returning

func Returning(expr SqlExpr) *otherAddition

func ScanDefToTable

func ScanDefToTable(rv reflect.Value, table *Table)

func ToMap

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

func Where

func Where(c SqlCondition) *where

Types

type Addition

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

type Additions

type Additions []Addition

func (Additions) Expr

func (additions Additions) Expr() *Ex

func (Additions) IsNil

func (additions Additions) IsNil() bool

func (Additions) Len

func (additions Additions) Len() int

func (Additions) Less

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

func (Additions) Swap

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

type AliasEx added in v2.2.0

type AliasEx struct {
	Name string
	SqlExpr
}

func Alias added in v2.2.0

func Alias(expr SqlExpr, name string) *AliasEx

func (*AliasEx) Expr added in v2.2.0

func (expr *AliasEx) Expr() *Ex

type Assignment

type Assignment struct {
	SqlExpr
	SqlAssignmentMarker
}

func AsAssignment

func AsAssignment(ex SqlExpr) *Assignment

func ColumnsAndValues

func ColumnsAndValues(cols *Columns, values ...interface{}) *Assignment

func (*Assignment) IsNil

func (a *Assignment) IsNil() bool

type Assignments

type Assignments []*Assignment

func (Assignments) Expr

func (assigns Assignments) Expr() *Ex

func (Assignments) IsNil

func (assigns Assignments) IsNil() bool

type Column

type Column struct {
	Name      string
	FieldName string
	Table     *Table
	Exactly   bool
	*ColumnType
}

func Col

func Col(name string) *Column

func (*Column) Between

func (c *Column) Between(leftValue interface{}, rightValue interface{}) *Condition

func (*Column) Desc

func (c *Column) Desc(d int) *Ex

func (*Column) Eq

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

func (*Column) Ex added in v2.2.1

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

func (*Column) Expr

func (c *Column) Expr() *Ex

func (Column) Field

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

func (*Column) Gt

func (c *Column) Gt(v interface{}) *Condition

func (*Column) Gte

func (c *Column) Gte(v interface{}) *Condition

func (*Column) In

func (c *Column) In(args ...interface{}) *Condition

func (*Column) Incr

func (c *Column) Incr(d int) *Ex

func (*Column) IsNil

func (c *Column) IsNil() bool

func (*Column) IsNotNull

func (c *Column) IsNotNull() *Condition

func (*Column) IsNull

func (c *Column) IsNull() *Condition

func (*Column) LeftLike

func (c *Column) LeftLike(v string) *Condition

func (*Column) Like

func (c *Column) Like(v string) *Condition

func (*Column) Lt

func (c *Column) Lt(v interface{}) *Condition

func (*Column) Lte

func (c *Column) Lte(v interface{}) *Condition

func (*Column) Neq

func (c *Column) Neq(v interface{}) *Condition

func (*Column) NotBetween

func (c *Column) NotBetween(leftValue interface{}, rightValue interface{}) *Condition

func (*Column) NotIn

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

func (*Column) NotLike

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

func (*Column) Of added in v2.2.0

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

func (Column) On

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

func (*Column) RightLike

func (c *Column) RightLike(v string) *Condition

func (*Column) T

func (c *Column) T() *Table

func (Column) Type

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

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

	Null          bool
	AutoIncrement bool
	Comment       string
}

func ColumnTypeFromTypeAndTag

func ColumnTypeFromTypeAndTag(typ reflect.Type, nameAndFlags string) *ColumnType

type Columns

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

func Cols

func Cols(names ...string) *Columns

func (*Columns) Add

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

func (*Columns) AutoIncrement

func (cols *Columns) AutoIncrement() (col *Column)

func (*Columns) Clone

func (cols *Columns) Clone() *Columns

func (*Columns) Col

func (cols *Columns) Col(columnName string) (col *Column)

func (*Columns) Cols

func (cols *Columns) Cols(colNames ...string) (*Columns, error)

func (*Columns) Expr

func (cols *Columns) Expr() *Ex

func (*Columns) F

func (cols *Columns) F(fileName string) (col *Column)

func (*Columns) FieldNames

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

func (*Columns) Fields

func (cols *Columns) Fields(fieldNames ...string) (*Columns, error)

func (*Columns) IsNil

func (cols *Columns) IsNil() bool

func (*Columns) Len

func (cols *Columns) Len() int

func (*Columns) List

func (cols *Columns) List() (l []*Column)

func (*Columns) Range

func (cols *Columns) Range(cb func(col *Column, idx int))

func (*Columns) Remove

func (cols *Columns) Remove(name string)

type CondRule

type CondRule struct {
	When       bool
	Conditions []*Condition
}

type CondRules

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

func NewCondRules

func NewCondRules() *CondRules

func (*CondRules) Expr

func (rules *CondRules) Expr() *Ex

func (*CondRules) IsNil

func (rules *CondRules) IsNil() bool

func (*CondRules) When

func (rules *CondRules) When(rule bool, conditions ...*Condition) *CondRules

type Condition

type Condition struct {
	SqlExpr
	SqlConditionMarker
}

func And

func And(condList ...SqlCondition) *Condition

func AsCond

func AsCond(ex SqlExpr) *Condition

func Or

func Or(condList ...SqlCondition) *Condition

func Xor

func Xor(condList ...SqlCondition) *Condition

func (Condition) And

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

func (*Condition) IsNil

func (c *Condition) IsNil() bool

func (Condition) Or

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

func (Condition) Xor

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

type DataTypeDescriber

type DataTypeDescriber interface {
	DataType(driverName string) string
}

type Dialect

type Dialect interface {
	DriverName() string
	BindVar(i int) 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
	ModifyColumn(col *Column) SqlExpr
	DropColumn(col *Column) SqlExpr
	AddIndex(key *Key) SqlExpr
	DropIndex(key *Key) SqlExpr
	DataType(columnType *ColumnType) SqlExpr
}

type Ex

type Ex struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

func Expr

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

func ExprFrom

func ExprFrom(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) Expr

func (e *Ex) Expr() *Ex

func (*Ex) Flatten

func (e *Ex) Flatten() *Ex

func (*Ex) IsNil

func (e *Ex) IsNil() bool

func (*Ex) Query

func (e *Ex) Query() string

func (*Ex) ReplaceValueHolder

func (e *Ex) ReplaceValueHolder(bindVar func(idx int) string) *Ex

func (*Ex) WhiteComments

func (e *Ex) WhiteComments(comments string)

func (*Ex) WriteEnd

func (e *Ex) WriteEnd()

func (*Ex) WriteExpr

func (e *Ex) WriteExpr(expr SqlExpr)

func (*Ex) WriteGroup

func (e *Ex) WriteGroup(fn func(e *Ex))

func (*Ex) WriteHolder

func (e *Ex) WriteHolder(idx int)

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
	Exprs []SqlExpr
}

func Avg

func Avg(sqlExprs ...SqlExpr) *Function

func Count

func Count(sqlExprs ...SqlExpr) *Function

func Distinct

func Distinct(sqlExprs ...SqlExpr) *Function

func First

func First(sqlExprs ...SqlExpr) *Function

func Func

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

func Last

func Last(sqlExprs ...SqlExpr) *Function

func Max

func Max(sqlExprs ...SqlExpr) *Function

func Min

func Min(sqlExprs ...SqlExpr) *Function

func Sum

func Sum(sqlExprs ...SqlExpr) *Function

func (*Function) Expr

func (f *Function) Expr() *Ex

func (*Function) IsNil

func (f *Function) IsNil() bool

type Indexes

type Indexes map[string][]string

type Key

type Key struct {
	Columns *Columns
	Table   *Table

	Name     string
	IsUnique bool
	Method   string
}

func Index

func Index(name string, columns *Columns) *Key

func PrimaryKey

func PrimaryKey(columns *Columns) *Key

func UniqueIndex

func UniqueIndex(name string, columns *Columns) *Key

func (*Key) IsPrimary

func (key *Key) IsPrimary() bool

func (Key) On

func (key Key) On(table *Table) *Key

func (*Key) T

func (key *Key) T() *Table

func (Key) Using

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

type Keys

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

func (*Keys) Add

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

func (*Keys) Clone

func (keys *Keys) Clone() *Keys

func (*Keys) IsEmpty

func (keys *Keys) IsEmpty() bool

func (*Keys) Key

func (keys *Keys) Key(keyName string) (key *Key)

func (*Keys) Len

func (keys *Keys) Len() int

func (*Keys) Range

func (keys *Keys) Range(cb func(key *Key, idx int))

func (*Keys) Remove

func (keys *Keys) Remove(name string)

type Model

type Model interface {
	TableName() string
}

type SqlAssignment

type SqlAssignment interface {
	SqlExpr
	SqlAssignmentMarker
}

type SqlAssignmentMarker

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

type SqlCondition

type SqlCondition interface {
	SqlExpr
	SqlConditionMarker
}

type SqlConditionMarker

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

type SqlExpr

type SqlExpr interface {
	IsNil() bool
	Expr() *Ex
}

func MultiExpr added in v2.2.0

func MultiExpr(exprs ...SqlExpr) SqlExpr

type StmtDelete

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

func Delete

func Delete() *StmtDelete

func (*StmtDelete) Expr

func (s *StmtDelete) Expr() *Ex

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

func (s *StmtInsert) Expr() *Ex

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 {
	// contains filtered or unexported fields
}

func Select

func Select(sqlExpr SqlExpr, modifiers ...string) *StmtSelect

func (*StmtSelect) Expr

func (s *StmtSelect) Expr() *Ex

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

func (s *StmtUpdate) Expr() *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 *Condition, additions ...Addition) *StmtUpdate

type Table

type Table struct {
	Name   string
	Schema string
	Model  Model
	Columns
	Keys
}

func T

func T(tableName string, tableDefinitions ...TableDefinition) *Table

func (*Table) AddCol

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

func (*Table) AddKey

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

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

func (t *Table) Diff(prevTable *Table, dialect Dialect, skipDropColumn bool) (exprList []SqlExpr)

func (*Table) Ex

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

replace go struct field name with table column name

func (*Table) Expr

func (t *Table) Expr() *Ex

func (*Table) IsNil

func (t *Table) IsNil() bool

func (Table) WithSchema added in v2.2.0

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

type TableDefinition

type TableDefinition interface {
	T() *Table
}

type Tables

type Tables map[string]*Table

func (Tables) Add

func (tables Tables) Add(table *Table)

func (Tables) TableNames

func (tables Tables) TableNames() (names []string)

type ValuerExpr

type ValuerExpr interface {
	ValueEx() string
}

replace ? as some query snippet

examples: ? => ST_GeomFromText(?)

type WithComments

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

type WithIndexes

type WithIndexes interface {
	Indexes() Indexes
}

type WithPrimaryKey

type WithPrimaryKey interface {
	PrimaryKey() []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