statements

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConditionType condition type unsupported
	ErrConditionType = errors.New("Unsupported condition type")
	// ErrUnSupportedSQLType parameter of SQL is not supported
	ErrUnSupportedSQLType = errors.New("Unsupported sql type")
	// ErrUnSupportedType unsupported error
	ErrUnSupportedType = errors.New("Unsupported type error")
	// ErrTableNotFound table not found error
	ErrTableNotFound = errors.New("Table not found")
)

Functions

func IsIDConditionWithNoTableErr

func IsIDConditionWithNoTableErr(err error) bool

IsIDConditionWithNoTableErr return true if the err is ErrIDConditionWithNoTable

Types

type ErrIDConditionWithNoTable

type ErrIDConditionWithNoTable struct {
	ID schemas.PK
}

ErrIDConditionWithNoTable represents an error there is no reference table with an ID condition

func (ErrIDConditionWithNoTable) Error

func (err ErrIDConditionWithNoTable) Error() string

type ErrUnsupportedExprType

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

func (ErrUnsupportedExprType) Error

func (err ErrUnsupportedExprType) Error() string

type Statement

type Statement struct {
	RefTable *schemas.Table

	Start  int
	LimitN *int

	OrderStr string
	JoinStr  string

	GroupByStr string
	HavingStr  string
	SelectStr  string

	AltTableName string

	RawSQL          string
	RawParams       []interface{}
	UseCascade      bool
	UseAutoJoin     bool
	StoreEngine     string
	Charset         string
	UseCache        bool
	UseAutoTime     bool
	NoAutoCondition bool
	IsDistinct      bool
	IsForUpdate     bool
	TableAlias      string

	CheckVersion bool

	ColumnMap     columnMap
	OmitColumnMap columnMap
	MustColumnMap map[string]bool
	NullableMap   map[string]bool
	IncrColumns   exprParams
	DecrColumns   exprParams
	ExprColumns   exprParams

	BufferSize int
	Context    contexts.ContextCache
	LastError  error
	// contains filtered or unexported fields
}

Statement save all the sql info for executing SQL

func NewStatement

func NewStatement(dialect dialects.Dialect, tagParser *tags.Parser, defaultTimeZone *time.Location) *Statement

NewStatement creates a new statement

func (*Statement) Alias

func (statement *Statement) Alias(alias string) *Statement

Alias set the table alias

func (*Statement) AllCols

func (statement *Statement) AllCols() *Statement

AllCols update use only: update all columns

func (*Statement) And

func (statement *Statement) And(query interface{}, args ...interface{}) *Statement

And add Where & and statement

func (*Statement) Asc

func (statement *Statement) Asc(colNames ...string) *Statement

Asc provide asc order by query condition, the input parameters are columns.

func (*Statement) BuildConds

func (statement *Statement) BuildConds(table *schemas.Table, bean interface{}, includeVersion bool, includeUpdated bool, includeNil bool, includeAutoIncr bool, addedTableName bool) (builder.Cond, error)

func (*Statement) BuildUpdates

func (statement *Statement) BuildUpdates(tableValue reflect.Value,
	includeVersion, includeUpdated, includeNil,
	includeAutoIncr, update bool) ([]string, []interface{}, error)

BuildUpdates auto generating update columnes and values according a struct

func (*Statement) Cols

func (statement *Statement) Cols(columns ...string) *Statement

Cols generate "col1, col2" statement

func (*Statement) ColumnStr

func (statement *Statement) ColumnStr() string

func (*Statement) CondDeleted

func (statement *Statement) CondDeleted(col *schemas.Column) builder.Cond

CondDeleted returns the conditions whether a record is soft deleted.

func (*Statement) Conds

func (statement *Statement) Conds() builder.Cond

func (*Statement) ConvertIDSQL

func (statement *Statement) ConvertIDSQL(sqlStr string) string

func (*Statement) ConvertSQLOrArgs

func (statement *Statement) ConvertSQLOrArgs(sqlOrArgs ...interface{}) (string, []interface{}, error)

func (*Statement) ConvertUpdateSQL

func (statement *Statement) ConvertUpdateSQL(sqlStr string) (string, string)

func (*Statement) Decr

func (statement *Statement) Decr(column string, arg ...interface{}) *Statement

Decr Generate "Update ... Set column = column - arg" statement

func (*Statement) Desc

func (statement *Statement) Desc(colNames ...string) *Statement

Desc generate `ORDER BY xx DESC`

func (*Statement) Distinct

func (statement *Statement) Distinct(columns ...string) *Statement

Distinct generates "DISTINCT col1, col2 " statement

func (*Statement) ForUpdate

func (statement *Statement) ForUpdate() *Statement

ForUpdate generates "SELECT ... FOR UPDATE" statement

func (*Statement) GenCondSQL

func (statement *Statement) GenCondSQL(condOrBuilder interface{}) (string, []interface{}, error)

func (*Statement) GenConds

func (statement *Statement) GenConds(bean interface{}) (string, []interface{}, error)

func (*Statement) GenCountSQL

func (statement *Statement) GenCountSQL(beans ...interface{}) (string, []interface{}, error)

GenCountSQL generates the SQL for counting

func (*Statement) GenCreateTableSQL

func (statement *Statement) GenCreateTableSQL() []string

func (*Statement) GenDelIndexSQL

func (statement *Statement) GenDelIndexSQL() []string

func (*Statement) GenExistSQL

func (statement *Statement) GenExistSQL(bean ...interface{}) (string, []interface{}, error)

func (*Statement) GenFindSQL

func (statement *Statement) GenFindSQL(autoCond builder.Cond) (string, []interface{}, error)

func (*Statement) GenGetSQL

func (statement *Statement) GenGetSQL(bean interface{}) (string, []interface{}, error)

func (*Statement) GenIndexSQL

func (statement *Statement) GenIndexSQL() []string

func (*Statement) GenInsertMapSQL

func (statement *Statement) GenInsertMapSQL(columns []string, args []interface{}) (string, []interface{}, error)

GenInsertMapSQL generates insert map SQL

func (*Statement) GenInsertSQL

func (statement *Statement) GenInsertSQL(colNames []string, args []interface{}) (string, []interface{}, error)

GenInsertSQL generates insert beans SQL

func (*Statement) GenQuerySQL

func (statement *Statement) GenQuerySQL(sqlOrArgs ...interface{}) (string, []interface{}, error)

func (*Statement) GenRawSQL

func (statement *Statement) GenRawSQL() string

GenRawSQL generates correct raw sql

func (*Statement) GenSumSQL

func (statement *Statement) GenSumSQL(bean interface{}, columns ...string) (string, []interface{}, error)

func (*Statement) GenUniqueSQL

func (statement *Statement) GenUniqueSQL() []string

func (*Statement) GetUnscoped

func (statement *Statement) GetUnscoped() bool

func (*Statement) GroupBy

func (statement *Statement) GroupBy(keys string) *Statement

GroupBy generate "Group By keys" statement

func (*Statement) Having

func (statement *Statement) Having(conditions string) *Statement

Having generate "Having conditions" statement

func (*Statement) ID

func (statement *Statement) ID(id interface{}) *Statement

ID generate "where id = ? " statement or for composite key "where key1 = ? and key2 = ?"

func (*Statement) In

func (statement *Statement) In(column string, args ...interface{}) *Statement

In generate "Where column IN (?) " statement

func (*Statement) Incr

func (statement *Statement) Incr(column string, arg ...interface{}) *Statement

Incr Generate "Update ... Set column = column + arg" statement

func (*Statement) Join

func (statement *Statement) Join(joinOP string, tablename interface{}, condition string, args ...interface{}) *Statement

Join The joinOP should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN

func (*Statement) Limit

func (statement *Statement) Limit(limit int, start ...int) *Statement

Limit generate LIMIT start, limit statement

func (*Statement) MustCols

func (statement *Statement) MustCols(columns ...string) *Statement

MustCols update use only: must update columns

func (*Statement) NotIn

func (statement *Statement) NotIn(column string, args ...interface{}) *Statement

NotIn generate "Where column NOT IN (?) " statement

func (*Statement) Nullable

func (statement *Statement) Nullable(columns ...string)

Nullable Update use only: update columns to null when value is nullable and zero-value

func (*Statement) Omit

func (statement *Statement) Omit(columns ...string)

Omit do not use the columns

func (*Statement) Or

func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement

Or add Where & Or statement

func (*Statement) OrderBy

func (statement *Statement) OrderBy(order string) *Statement

OrderBy generate "Order By order" statement

func (*Statement) ProcessIDParam

func (statement *Statement) ProcessIDParam() error

ProcessIDParam handles the process of id condition

func (*Statement) ReplaceQuote

func (statement *Statement) ReplaceQuote(sql string) string

func (*Statement) Reset

func (statement *Statement) Reset()

Init reset all the statement's fields

func (*Statement) SQL

func (statement *Statement) SQL(query interface{}, args ...interface{}) *Statement

SQL adds raw sql statement

func (*Statement) Select

func (statement *Statement) Select(str string) *Statement

Select replace select

func (*Statement) SetContextCache

func (statement *Statement) SetContextCache(ctxCache contexts.ContextCache)

func (*Statement) SetExpr

func (statement *Statement) SetExpr(column string, expression interface{}) *Statement

SetExpr Generate "Update ... Set column = {expression}" statement

func (*Statement) SetNoAutoCondition

func (statement *Statement) SetNoAutoCondition(no ...bool) *Statement

NoAutoCondition if you do not want convert bean's field as query condition, then use this function

func (*Statement) SetRefBean

func (statement *Statement) SetRefBean(bean interface{}) error

func (*Statement) SetRefValue

func (statement *Statement) SetRefValue(v reflect.Value) error

func (*Statement) SetTable

func (statement *Statement) SetTable(tableNameOrBean interface{}) error

Table tempororily set table name, the parameter could be a string or a pointer of struct

func (*Statement) SetTableName

func (statement *Statement) SetTableName(tableName string)

func (*Statement) SetUnscoped

func (statement *Statement) SetUnscoped() *Statement

Unscoped always disable struct tag "deleted"

func (*Statement) TableName

func (statement *Statement) TableName() string

TableName return current tableName

func (*Statement) Top

func (statement *Statement) Top(limit int) *Statement

Top generate LIMIT limit statement

func (*Statement) UseBool

func (statement *Statement) UseBool(columns ...string) *Statement

UseBool indicates that use bool fields as update contents and query contiditions

func (*Statement) Value2Interface

func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue reflect.Value) (interface{}, error)

Value2Interface convert a field value of a struct to interface for puting into database

func (*Statement) Where

func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement

Where add Where statement

func (*Statement) WriteArg

func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) error

func (*Statement) WriteArgs

func (statement *Statement) WriteArgs(w *builder.BytesWriter, args []interface{}) error

Jump to

Keyboard shortcuts

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