builder

package
v0.0.0-...-61829c1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PRIMARY      keyType = "PRIMARY"
	INDEX        keyType = "INDEX"
	UNIQUE_INDEX keyType = "UNIQUE INDEX"
)

Variables

View Source
var Configuration = &struct {
	DropColumnWhenMigration bool
}{}
View Source
var (
	DeleteNeedLimitByWhere = fmt.Errorf("no where limit for delete")
)
View Source
var (
	InsertValuesLengthNotMatch = fmt.Errorf("value length is not equal Col length")
)
View Source
var (
	UpdateNeedLimitByWhere = fmt.Errorf("no where limit for update")
)

Functions

func HolderRepeat

func HolderRepeat(length int) string

func Star

func Star() star

Types

type Assignment

type Assignment Expression

func (Assignment) Expr

func (a Assignment) Expr() *Expression

type Assignments

type Assignments []*Assignment

func (Assignments) Expr

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

type CanExpr

type CanExpr interface {
	Expr() *Expression
}

type Column

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

func Col

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

func (*Column) Add

func (c *Column) Add() *Expression

func (*Column) Between

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

func (*Column) By

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

func (Column) Def

func (c Column) Def() *Expression

func (*Column) Desc

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

func (*Column) Drop

func (c *Column) Drop() *Expression

func (Column) Enum

func (c Column) Enum(enumType string, enums map[int][]string) *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) Modify

func (c *Column) Modify() *Expression

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

type Columns

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

func Cols

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

func (Columns) Wrap

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

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, conds ...*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) Create

func (d *Database) Create(ifNotExists bool) *Stmt

func (*Database) Drop

func (d *Database) Drop() *Stmt

func (*Database) Register

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

func (*Database) String

func (d *Database) String() string

func (*Database) Table

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

type Expression

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

func Expr

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

func ExprErr

func ExprErr(err error) *Expression

func ExprFrom

func ExprFrom(v interface{}) *Expression

func (Expression) ConcatBy

func (e Expression) ConcatBy(joiner string, canExpr CanExpr) *Expression

func (*Expression) Expr

func (e *Expression) Expr() *Expression

type FieldValues

type FieldValues map[string]interface{}

type Function

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

func Avg

func Avg(canExpr CanExpr) *Function

func Count

func Count(canExpr CanExpr) *Function

func Distinct

func Distinct(canExpr CanExpr) *Function

func First

func First(canExpr CanExpr) *Function

func Func

func Func(name string, canExpr CanExpr) *Function

func Last

func Last(canExpr CanExpr) *Function

func Max

func Max(canExpr CanExpr) *Function

func Min

func Min(canExpr CanExpr) *Function

func Sum

func Sum(canExpr CanExpr) *Function

func (*Function) Expr

func (f *Function) Expr() *Expression

type Key

type Key struct {
	Name string
	Columns
	Type keyType
}

func Index

func Index(name string) *Key

func PrimaryKey

func PrimaryKey() *Key

func UniqueIndex

func UniqueIndex(name string) *Key

func (*Key) Add

func (key *Key) Add() *Expression

func (*Key) Def

func (key *Key) Def() *Expression

func (*Key) Drop

func (key *Key) Drop() *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 OrderType

type OrderType string
const (
	ORDER_NO   OrderType = ""
	ORDER_ASC  OrderType = "ASC"
	ORDER_DESC OrderType = "DESC"
)

type Statement

type Statement interface {
	CanExpr
	Type() StmtType
}

type Stmt

type Stmt Expression

func (*Stmt) Expr

func (s *Stmt) Expr() *Expression

func (*Stmt) Type

func (s *Stmt) Type() StmtType

type StmtDelete

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

func Delete

func Delete(table *Table) *StmtDelete

func (StmtDelete) AscendBy

func (s StmtDelete) AscendBy(col *Column) *StmtDelete

func (StmtDelete) Comment

func (s StmtDelete) Comment(comment string) *StmtDelete

func (StmtDelete) DescendBy

func (s StmtDelete) DescendBy(col *Column) *StmtDelete

func (*StmtDelete) Expr

func (s *StmtDelete) Expr() *Expression

func (StmtDelete) Limit

func (s StmtDelete) Limit(size int32) *StmtDelete

func (StmtDelete) Modifier

func (s StmtDelete) Modifier(modifiers ...string) *StmtDelete

func (StmtDelete) OrderBy

func (s StmtDelete) OrderBy(col *Column, orderType OrderType) *StmtDelete

func (*StmtDelete) Type

func (s *StmtDelete) Type() StmtType

func (StmtDelete) Where

func (s StmtDelete) Where(cond *Condition) *StmtDelete

type StmtInsert

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

func Insert

func Insert(table *Table) *StmtInsert

func (StmtInsert) Columns

func (s StmtInsert) Columns(cols Columns) *StmtInsert

func (StmtInsert) Comment

func (s StmtInsert) Comment(comment string) *StmtInsert

func (*StmtInsert) Expr

func (s *StmtInsert) Expr() *Expression

func (StmtInsert) Modifier

func (s StmtInsert) Modifier(modifiers ...string) *StmtInsert

func (StmtInsert) OnDuplicateKeyUpdate

func (s StmtInsert) OnDuplicateKeyUpdate(assigns ...*Assignment) *StmtInsert

func (*StmtInsert) Type

func (s *StmtInsert) Type() StmtType

func (StmtInsert) Values

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

type StmtSelect

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

func SelectFrom

func SelectFrom(table *Table) *StmtSelect

func (StmtSelect) Comment

func (s StmtSelect) Comment(comment string) *StmtSelect

func (*StmtSelect) Expr

func (s *StmtSelect) Expr() *Expression

func (StmtSelect) For

func (s StmtSelect) For(expr CanExpr) *StmtSelect

func (StmtSelect) ForUpdate

func (s StmtSelect) ForUpdate() *StmtSelect

func (StmtSelect) GroupAscBy

func (s StmtSelect) GroupAscBy(canExpr CanExpr) *StmtSelect

func (StmtSelect) GroupBy

func (s StmtSelect) GroupBy(canExpr CanExpr) *StmtSelect

func (StmtSelect) GroupDescBy

func (s StmtSelect) GroupDescBy(canExpr CanExpr) *StmtSelect

func (StmtSelect) Having

func (s StmtSelect) Having(cond *Condition) *StmtSelect

func (StmtSelect) Limit

func (s StmtSelect) Limit(size int32) *StmtSelect

func (StmtSelect) Modifier

func (s StmtSelect) Modifier(modifiers ...string) *StmtSelect

func (StmtSelect) Offset

func (s StmtSelect) Offset(offset int32) *StmtSelect

func (StmtSelect) OrderAscBy

func (s StmtSelect) OrderAscBy(canExpr CanExpr) *StmtSelect

func (StmtSelect) OrderBy

func (s StmtSelect) OrderBy(canExpr CanExpr, orderType OrderType) *StmtSelect

func (StmtSelect) OrderDescBy

func (s StmtSelect) OrderDescBy(canExpr CanExpr) *StmtSelect

func (*StmtSelect) Type

func (s *StmtSelect) Type() StmtType

func (StmtSelect) Where

func (s StmtSelect) Where(cond *Condition) *StmtSelect

func (StmtSelect) WithRollup

func (s StmtSelect) WithRollup() *StmtSelect

type StmtType

type StmtType int16
const (
	STMT_UNKNOWN StmtType = iota
	STMT_INSERT
	STMT_DELETE
	STMT_UPDATE
	STMT_SELECT
	STMT_RAW
)

type StmtUpdate

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

func Update

func Update(table *Table) *StmtUpdate

func (StmtUpdate) Comment

func (s StmtUpdate) Comment(comment string) *StmtUpdate

func (*StmtUpdate) Expr

func (s *StmtUpdate) Expr() *Expression

func (StmtUpdate) Limit

func (s StmtUpdate) Limit(size int32) *StmtUpdate

func (StmtUpdate) Modifier

func (s StmtUpdate) Modifier(modifiers ...string) *StmtUpdate

func (StmtUpdate) OrderAscBy

func (s StmtUpdate) OrderAscBy(col *Column) *StmtUpdate

func (StmtUpdate) OrderBy

func (s StmtUpdate) OrderBy(col *Column, orderType OrderType) *StmtUpdate

func (StmtUpdate) OrderDescBy

func (s StmtUpdate) OrderDescBy(col *Column) *StmtUpdate

func (StmtUpdate) Set

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

func (*StmtUpdate) Type

func (s *StmtUpdate) Type() StmtType

func (StmtUpdate) Where

func (s StmtUpdate) Where(cond *Condition) *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) AssignsByFieldValues

func (t *Table) AssignsByFieldValues(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) Create

func (t *Table) Create(ifNotExists bool) *Stmt

func (Table) Define

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

func (*Table) Delete

func (t *Table) Delete() *StmtDelete

func (*Table) Diff

func (t *Table) Diff(table *Table) *Stmt

func (*Table) Drop

func (t *Table) Drop() *Stmt

func (*Table) Ex

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

func (*Table) FullName

func (t *Table) FullName() string

func (*Table) Insert

func (t *Table) Insert() *StmtInsert

func (*Table) Select

func (t *Table) Select() *StmtSelect

func (*Table) String

func (t *Table) String() string

func (*Table) Truncate

func (t *Table) Truncate() *Stmt

func (*Table) Update

func (t *Table) Update() *StmtUpdate

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)

Jump to

Keyboard shortcuts

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