builder

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PRIMARY       keyType = "PRIMARY"
	INDEX         keyType = "INDEX"
	UNIQUE_INDEX  keyType = "UNIQUE INDEX"
	SPATIAL_INDEX keyType = "SPATIAL INDEX"
)
View Source
const (
	ALL      = "ALL"
	DISTINCT = "DISTINCT"

	DISTINCTROW = "DISTINCTROW"

	LOW_PRIORITY  = "LOW_PRIORITY"
	DELAYED       = "LOW_PRIORITY"
	HIGH_PRIORITY = "HIGH_PRIORITY"

	QUICK = "QUICK"

	STRAIGHT_JOIN = "STRAIGHT_JOIN"

	SQL_SMALL_RESULT  = "SQL_SMALL_RESULT"
	SQL_BIG_RESULT    = "SQL_BIG_RESULT"
	SQL_BUFFER_RESULT = "SQL_BUFFER_RESULT"

	IGNORE = "IGNORE"
)

Variables

View Source
var (
	UpdateNeedLimitByWhere = fmt.Errorf("no where limit for update")
)

Functions

func AscOrder

func AscOrder(expr SqlExpr) *order

func Comment

func Comment(c string) comment

func DescOrder

func DescOrder(expr SqlExpr) *order

func FlattenArgs

func FlattenArgs(query string, args ...interface{}) (finalQuery string, finalArgs []interface{})

func ForEachStructField

func ForEachStructField(structType reflect.Type, fn func(structField reflect.StructField, columnName string))

func ForEachStructFieldValue

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

func ForUpdate

func ForUpdate() *otherAddition

func GroupBy

func GroupBy(groups ...SqlExpr) *groupBy

func HolderRepeat

func HolderRepeat(length int) string

func Join

func Join(table *Table, modifies ...string) *join

func Limit

func Limit(rowCount int32) *limit

func LockInShareMode

func LockInShareMode() *otherAddition

func OnDuplicateKeyUpdate

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

func OrderBy

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

func ScanDefToTable

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

func Where

func Where(c *Condition) *where

Types

type Addition

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

type Additions

type Additions []Addition

func (Additions) Expr

func (a Additions) Expr() *Expression

func (Additions) Len

func (a Additions) Len() int

func (Additions) Less

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

func (Additions) Swap

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

type Assignment

type Assignment Expression

func ColumnsAndValues

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

func (Assignment) Expr

func (a Assignment) Expr() *Expression

type Assignments

type Assignments []*Assignment

func (Assignments) Expr

func (assigns Assignments) Expr() (e *Expression)

type Column

type Column struct {
	Table     *Table
	Name      string
	FieldName string
	datatypes.ColumnType
}

func Col

func Col(table *Table, columnName string) *Column

func (*Column) Between

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

func (*Column) Def

func (c *Column) Def() *Expression

func (*Column) Desc

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

func (Column) Enum

func (c Column) Enum(enum enumeration.Enum) *Column

func (*Column) Eq

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

func (*Column) Expr

func (c *Column) Expr() *Expression

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) *Expression

func (*Column) IsNotNull

func (c *Column) IsNotNull() *Condition

func (*Column) IsNull

func (c *Column) IsNull() *Condition

func (*Column) IsValidDef

func (c *Column) IsValidDef() bool

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

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

func (*Column) String

func (c *Column) String() string

func (Column) Type

func (c Column) Type(tpe string) *Column

func (*Column) ValueBy

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

type Columns

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

func Cols

func Cols(t *Table, columnNames ...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 *Columns)

func (Columns) Diff

func (cols Columns) Diff(targetCols Columns) columnsDiffResult

func (Columns) Expr

func (cols Columns) Expr() (e *Expression)

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 *Columns)

func (Columns) Group

func (cols Columns) Group() (e *Expression)

func (*Columns) IsEmpty

func (cols *Columns) IsEmpty() 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 {
	// contains filtered or unexported fields
}

func NewCondRules

func NewCondRules() *CondRules

func (*CondRules) ToCond

func (rules *CondRules) ToCond() *Condition

func (*CondRules) When

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

type Condition

type Condition Expression

func And

func And(condList ...*Condition) (cond *Condition)

func Or

func Or(condList ...*Condition) (cond *Condition)

func Xor

func Xor(condList ...*Condition) (cond *Condition)

func (Condition) And

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

func (*Condition) Expr

func (c *Condition) Expr() *Expression

func (Condition) Or

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

func (Condition) Xor

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

type Database

type Database struct {
	Name string
	Tables
}

func DB

func DB(name string) *Database

func (*Database) DBName

func (d *Database) DBName() string

func (*Database) Register

func (d *Database) Register(table *Table) *Database

func (*Database) Table

func (d *Database) Table(name string) *Table

type DatabaseDefiner

type DatabaseDefiner interface {
	DBName() string
}

type DiffOptions

type DiffOptions struct {
	DropColumn bool
}

type Expression

type Expression struct {
	Query string
	Args  []interface{}
	Err   error
}

func AddCol

func AddCol(c *Column) *Expression

func AddKey

func AddKey(key *Key) *Expression

func DropCol

func DropCol(c *Column) *Expression

func DropKey

func DropKey(key *Key) *Expression

func Expr

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

func ExprErr

func ExprErr(err error) *Expression

func ExprFrom

func ExprFrom(v interface{}) *Expression

func JoinExpr

func JoinExpr(joiner string, sqlExprs ...SqlExpr) (*Expression, error)

func ModifyCol

func ModifyCol(c *Column) *Expression

func MustJoinExpr

func MustJoinExpr(joiner string, sqlExprs ...SqlExpr) *Expression

func (*Expression) Expr

func (e *Expression) Expr() *Expression

type FieldNames

type FieldNames []string

func (FieldNames) Map

func (fieldNames FieldNames) Map() map[string]bool

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

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() *Expression

type IndexDeclarer

type IndexDeclarer func() (indexName string, fieldNames FieldNames)

type Indexes

type Indexes map[string]FieldNames

type Key

type Key struct {
	Name string
	Columns
	Type keyType
}

func Index

func Index(name string) *Key

func PrimaryKey

func PrimaryKey() *Key

func SpatialIndex added in v1.1.0

func SpatialIndex(name string) *Key

func UniqueIndex

func UniqueIndex(name string) *Key

func (*Key) Def

func (key *Key) Def() *Expression

func (*Key) IsValidDef

func (key *Key) IsValidDef() bool

func (*Key) String

func (key *Key) String() string

func (*Key) WithCols

func (key *Key) WithCols(columns ...*Column) *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) Diff

func (keys Keys) Diff(targetKeys Keys) keysDiffResult

func (*Keys) IsEmpty

func (keys *Keys) IsEmpty() bool

func (*Keys) Key

func (keys *Keys) Key(keyName string) (key *Key, exists bool)

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 SqlExpr

type SqlExpr interface {
	Expr() *Expression
}

func AlterTable

func AlterTable(t *Table) SqlExpr

func CreateDatebase

func CreateDatebase(d DatabaseDefiner) SqlExpr

func CreateDatebaseIfNotExists

func CreateDatebaseIfNotExists(d DatabaseDefiner) SqlExpr

func CreateTable

func CreateTable(t *Table) SqlExpr

func CreateTableIsNotExists

func CreateTableIsNotExists(t *Table) SqlExpr

func DropDatabase

func DropDatabase(d DatabaseDefiner) SqlExpr

func DropTable

func DropTable(t *Table) SqlExpr

func TruncateTable

func TruncateTable(t *Table) SqlExpr

type StmtDelete

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

func Delete

func Delete(modifiers ...string) *StmtDelete

func (*StmtDelete) Expr

func (s *StmtDelete) Expr() *Expression

func (StmtDelete) From

func (s StmtDelete) From(table *Table, additions ...Addition) *StmtDelete

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() *Expression

func (StmtInsert) Into

func (s StmtInsert) Into(table *Table, additions ...Addition) *StmtInsert

func (StmtInsert) Set

func (s StmtInsert) Set(assignments ...*Assignment) *StmtInsert

func (StmtInsert) Values

func (s StmtInsert) Values(cols *Columns, values ...interface{}) *StmtInsert

type StmtSelect

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

https://dev.mysql.com/doc/refman/5.7/en/select.html

func Select

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

func (*StmtSelect) Expr

func (s *StmtSelect) Expr() *Expression

func (StmtSelect) From

func (s StmtSelect) From(table *Table, additions ...Addition) *StmtSelect

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() *Expression

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 {
	DB   *Database
	Name string
	Columns
	Keys
	Engine  string
	Charset string
}

func T

func T(db *Database, tableName string) *Table

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

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

func (Table) Define

func (t Table) Define(defs ...TableDef) *Table

func (*Table) Diff

func (t *Table) Diff(table *Table, opts DiffOptions) (exprs []SqlExpr)

func (*Table) Ex

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

replace go struct field name with table column name

func (*Table) Expr

func (t *Table) Expr() *Expression

func (*Table) FullName

func (t *Table) FullName() string

func (*Table) TableName

func (t *Table) TableName() string

type TableDef

type TableDef interface {
	IsValidDef() bool
	Def() *Expression
}

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 added in v1.1.0

type ValuerExpr interface {
	ValueEx() string
}

type WithComments

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

type WithIndexes

type WithIndexes interface {
	Indexes() Indexes
}

type WithPrimaryKey

type WithPrimaryKey interface {
	PrimaryKey() FieldNames
}

type WithSpatialIndexes added in v1.1.0

type WithSpatialIndexes interface {
	SpatialIndexes() Indexes
}

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