statements

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: BSD-3-Clause Imports: 17 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")
)
View Source
var ErrNoColumnName = errors.New("no column name")
View Source
var ErrNoColumnsTobeUpdated = errors.New("no columns found to be updated")
View Source
var ErrNotImplemented = errors.New("Not implemented")

ErrNotImplemented not implemented

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 ErrInvalidIndexHintOperator

type ErrInvalidIndexHintOperator struct {
	Op string
}

func (ErrInvalidIndexHintOperator) Error

type ErrUnsupportedExprType

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

ErrUnsupportedExprType represents an error with unsupported express type

func (ErrUnsupportedExprType) Error

func (err ErrUnsupportedExprType) Error() string

type Expr

type Expr struct {
	ColName string
	Arg     interface{}
}

Expr represents an SQL express

func (*Expr) WriteArgs

func (expr *Expr) WriteArgs(w *builder.BytesWriter) error

WriteArgs writes args to the writer

type QuoteReplacer

type QuoteReplacer struct {
	*builder.BytesWriter
	// contains filtered or unexported fields
}

func (*QuoteReplacer) Write

func (q *QuoteReplacer) Write(p []byte) (n int, err error)

type Statement

type Statement struct {
	RefTable *schemas.Table

	Start  int
	LimitN *int

	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)

BuildConds builds condition

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

ColumnStr returns column 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

Conds returns condtions

func (*Statement) ConvertIDSQL

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

ConvertIDSQL converts SQL with id

func (*Statement) ConvertSQLOrArgs

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

ConvertSQLOrArgs converts sql or args

func (*Statement) ConvertUpdateSQL

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

ConvertUpdateSQL converts update SQL

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

func (statement *Statement) GenConditionsFromMap(m interface{}) ([]builder.Cond, error)

func (*Statement) GenCountSQL

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

GenCountSQL generates the SQL for counting

func (*Statement) GenDelIndexSQL

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

GenDelIndexSQL generate delete index SQL

func (*Statement) GenExistSQL

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

GenExistSQL generates Exist SQL

func (*Statement) GenFindSQL

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

GenFindSQL generates Find SQL

func (*Statement) GenGetSQL

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

GenGetSQL generates Get SQL

func (*Statement) GenIndexSQL

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

GenIndexSQL generated create index SQL

func (*Statement) GenInsertMapSQL

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

GenInsertMapSQL generates insert map SQL

func (*Statement) GenInsertMultipleMapSQL

func (statement *Statement) GenInsertMultipleMapSQL(columns []string, argss [][]interface{}) (string, []interface{}, error)

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)

GenQuerySQL generate query SQL

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)

GenSumSQL generates sum SQL

func (*Statement) GenUniqueSQL

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

GenUniqueSQL generates unique SQL

func (*Statement) GetUnscoped

func (statement *Statement) GetUnscoped() bool

GetUnscoped return true if it's unscoped

func (*Statement) GroupBy

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

GroupBy generate "Group By keys" statement

func (*Statement) HasOrderBy

func (statement *Statement) HasOrderBy() bool

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

func (statement *Statement) IndexHint(op, forType, indexName string) error

func (*Statement) Join

func (statement *Statement) Join(joinOP string, joinTable interface{}, condition interface{}, 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) MergeConds

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

MergeConds merge conditions from bean and id

func (*Statement) MustCols

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

MustCols update use only: must update columns

func (*Statement) NeedTableName

func (statement *Statement) NeedTableName() bool

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 interface{}, args ...interface{}) *Statement

OrderBy generate "Order By order" statement

func (*Statement) ProcessIDParam

func (statement *Statement) ProcessIDParam() error

ProcessIDParam handles the process of id condition

func (*Statement) QuoteReplacer

func (statement *Statement) QuoteReplacer(w *builder.BytesWriter) *QuoteReplacer

func (*Statement) ReplaceQuote

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

ReplaceQuote replace sql key words with quote

func (*Statement) Reset

func (statement *Statement) Reset()

Reset reset all the statement's fields

func (*Statement) ResetOrderBy

func (statement *Statement) ResetOrderBy()

ResetOrderBy reset ordery conditions

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)

SetContextCache sets context cache

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

SetNoAutoCondition 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

SetRefBean set ref bean

func (*Statement) SetRefValue

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

SetRefValue set ref value

func (*Statement) SetTable

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

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

func (*Statement) SetTableName

func (statement *Statement) SetTableName(tableName string)

SetTableName set table name

func (*Statement) SetUnscoped

func (statement *Statement) SetUnscoped() *Statement

SetUnscoped 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 putting 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

WriteArg writes an arg

func (*Statement) WriteArgs

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

WriteArgs writes args

func (*Statement) WriteDelete

func (statement *Statement) WriteDelete(realSQLWriter, deleteSQLWriter *builder.BytesWriter, nowTime func(*schemas.Column) (interface{}, time.Time, error)) error

func (*Statement) WriteInsertMultiple

func (statement *Statement) WriteInsertMultiple(w *builder.BytesWriter, tableName string, colNames []string, colMultiPlaces []string) error

func (*Statement) WriteUpdate

func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []interface{}) error

Jump to

Keyboard shortcuts

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