condition

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdaptField

func AdaptField(field string) string

AdaptField: return quote field Deprecated use Quote instead

func AdaptTable

func AdaptTable(table string) string

AdaptTable: return quote table Deprecated use Quote instead

func BuildDelete

func BuildDelete(builder *sqlbuilder.DeleteBuilder, conditions ...Condition) (string, []any)

func BuildDeleteWithFlavor

func BuildDeleteWithFlavor(flavor sqlbuilder.Flavor, builder *sqlbuilder.DeleteBuilder, conditions ...Condition) (string, []any)

func BuildSelect

func BuildSelect(builder *sqlbuilder.SelectBuilder, conditions ...Condition) (string, []any)

func BuildSelectWithFlavor

func BuildSelectWithFlavor(flavor sqlbuilder.Flavor, builder *sqlbuilder.SelectBuilder, conditions ...Condition) (string, []any)

func BuildUpdate

func BuildUpdate(builder *sqlbuilder.UpdateBuilder, data map[string]any, conditions ...Condition) (string, []any)

func BuildUpdateWithFlavor

func BuildUpdateWithFlavor(flavor sqlbuilder.Flavor, builder *sqlbuilder.UpdateBuilder, data map[string]any, conditions ...Condition) (string, []any)

func Delete

func Delete(builder sqlbuilder.DeleteBuilder, conditions ...Condition) sqlbuilder.DeleteBuilder

Delete return delete with condition builder Deprecated: Use BuildUDelete instead

func DeleteWithFlavor

func DeleteWithFlavor(flavor sqlbuilder.Flavor, builder sqlbuilder.DeleteBuilder, conditions ...Condition) sqlbuilder.DeleteBuilder

DeleteWithFlavor return delete with condition builder Deprecated: Use BuildUDeleteWithFlavor instead

func QuoteWithFlavor

func QuoteWithFlavor(flavor sqlbuilder.Flavor, str string) string

func RawFieldNames

func RawFieldNames(in any) []string

RawFieldNames converts golang struct field into slice string.

func RawFieldNamesWithFlavor

func RawFieldNamesWithFlavor(flavor sqlbuilder.Flavor, in any) []string

RawFieldNamesWithFlavor converts golang struct field into slice string.

func RemoveIgnoreColumns

func RemoveIgnoreColumns(columns []string, ignoreColumns ...string) []string

func RemoveIgnoreColumnsWithFlavor

func RemoveIgnoreColumnsWithFlavor(flavor sqlbuilder.Flavor, columns []string, ignoreColumns ...string) []string

func Select

func Select(builder sqlbuilder.SelectBuilder, conditions ...Condition) sqlbuilder.SelectBuilder

Select return select with condition builder Deprecated: Use BuildSelect instead

func SelectByWhereRawSql

func SelectByWhereRawSql(sb *sqlbuilder.SelectBuilder, originalField string, args ...any)

func SelectByWhereRawSqlWithFlavor

func SelectByWhereRawSqlWithFlavor(flavor sqlbuilder.Flavor, sb *sqlbuilder.SelectBuilder, originalField string, args ...any)

func SelectWithFlavor

func SelectWithFlavor(flavor sqlbuilder.Flavor, builder sqlbuilder.SelectBuilder, conditions ...Condition) sqlbuilder.SelectBuilder

SelectWithFlavor return flavor select with condition builder Deprecated: Use BuildSelectWithFlavor instead

func ToSlice

func ToSlice(i any) []any

func Unquote

func Unquote(s string) string

func Update

func Update(builder sqlbuilder.UpdateBuilder, conditions ...Condition) sqlbuilder.UpdateBuilder

Update return update with condition builder Deprecated: Use BuildUpdate instead

func UpdateWithFlavor

func UpdateWithFlavor(flavor sqlbuilder.Flavor, builder sqlbuilder.UpdateBuilder, conditions ...Condition) sqlbuilder.UpdateBuilder

UpdateWithFlavor return flavor update with condition builder Deprecated: Use BuildUpdateWithFlavor instead

func WithOrValuesFunc

func WithOrValuesFunc(valueFunc func() []any) opts.Opt[ChainOperatorOpts]

func WithSkip

func WithSkip(skip bool) opts.Opt[ChainOperatorOpts]

func WithSkipFunc

func WithSkipFunc(skipFunc func() bool) opts.Opt[ChainOperatorOpts]

func WithUpdateFieldSkip

func WithUpdateFieldSkip(skip bool) opts.Opt[UpdateFieldChainOpts]

func WithUpdateFieldSkipFunc

func WithUpdateFieldSkipFunc(skipFunc func() bool) opts.Opt[UpdateFieldChainOpts]

func WithUpdateFieldValueFunc

func WithUpdateFieldValueFunc(valueFunc func() any) opts.Opt[UpdateFieldChainOpts]

func WithValueFunc

func WithValueFunc(valueFunc func() any) opts.Opt[ChainOperatorOpts]

Types

type Chain

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

func NewChain

func NewChain(conditions ...Condition) Chain

func NewChainWithConditions deprecated

func NewChainWithConditions(conditions ...Condition) Chain

Deprecated: Use NewChain instead

func (Chain) AddCondition

func (c Chain) AddCondition(condition Condition) Chain

func (Chain) Between

func (c Chain) Between(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) Build

func (c Chain) Build() []Condition

func (Chain) Equal

func (c Chain) Equal(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) ForShare

func (c Chain) ForShare(op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) ForUpdate

func (c Chain) ForUpdate(op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) GreaterEqualThan

func (c Chain) GreaterEqualThan(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) GreaterThan

func (c Chain) GreaterThan(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) GroupBy

func (c Chain) GroupBy(field Field, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) In

func (c Chain) In(field Field, values any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) IsNotNull

func (c Chain) IsNotNull(field Field, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) IsNull

func (c Chain) IsNull(field Field, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) Join

func (c Chain) Join(option sqlbuilder.JoinOption, table string, onExpr ...string) Chain

func (Chain) LessEqualThan

func (c Chain) LessEqualThan(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) LessThan

func (c Chain) LessThan(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) Like

func (c Chain) Like(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) Limit

func (c Chain) Limit(value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) NotEqual

func (c Chain) NotEqual(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) NotIn

func (c Chain) NotIn(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) NotLike

func (c Chain) NotLike(field Field, value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) Offset

func (c Chain) Offset(value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) Or

func (c Chain) Or(fields []Field, operators []Operator, values []any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) OrderBy

func (c Chain) OrderBy(value any, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) OrderByAsc

func (c Chain) OrderByAsc(field Field, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) OrderByDesc

func (c Chain) OrderByDesc(field Field, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) Page

func (c Chain) Page(page, pageSize int, op ...opts.Opt[ChainOperatorOpts]) Chain

func (Chain) WhereClause

func (c Chain) WhereClause(whereClause *sqlbuilder.WhereClause) Chain

type ChainOperatorOpts

type ChainOperatorOpts struct {
	Skip     bool
	SkipFunc func() bool

	ValueFunc func() any

	OrValuesFunc func() []any
}

func (ChainOperatorOpts) DefaultOptions

func (opts ChainOperatorOpts) DefaultOptions() ChainOperatorOpts

type Condition

type Condition struct {
	// Skip indicates whether the condition is effective.
	Skip bool

	// SkipFunc The priority is higher than Skip.
	SkipFunc func() bool

	// Or indicates an or condition
	Or bool

	OrOperators  []Operator
	OrFields     []Field
	OrValues     []any
	OrValuesFunc func() []any

	// Field for default and condition
	Field Field

	Operator Operator
	Value    any

	// ValueFunc The priority is higher than Value.
	ValueFunc func() any

	// JoinCondition
	JoinCondition

	WhereClause *sqlbuilder.WhereClause
}

func New

func New(conditions ...Condition) []Condition

type Field

type Field string

func ToFieldSlice

func ToFieldSlice(fields []string) []Field

func (Field) String

func (f Field) String() string

type JoinCondition

type JoinCondition struct {
	Option sqlbuilder.JoinOption
	Table  string
	OnExpr []string
}

type Operator

type Operator string
const (
	Equal            Operator = "="
	NotEqual         Operator = "!="
	IsNull           Operator = "IS NULL"
	IsNotNull        Operator = "IS NOT NULL"
	GreaterThan      Operator = ">"
	LessThan         Operator = "<"
	GreaterEqualThan Operator = ">="
	LessEqualThan    Operator = "<="
	In               Operator = "IN"
	NotIn            Operator = "NOT IN"
	Like             Operator = "LIKE"
	NotLike          Operator = "NOT LIKE"
	Limit            Operator = "LIMIT"
	Offset           Operator = "OFFSET"
	Between          Operator = "BETWEEN"
	NotBetween       Operator = "NOT BETWEEN"
	ForUpdate        Operator = "FOR UPDATE" // only take effective for select builder
	ForShare         Operator = "FOR SHARE"  // only take effective for select builder

	// OrderBy Deprecated Use OrderByDesc or OrderByAsc instead.
	OrderBy     Operator = "ORDER BY"
	OrderByDesc Operator = "ORDER BY DESC"
	OrderByAsc  Operator = "ORDER BY ASC"
	GroupBy     Operator = "GROUP BY"
	Join        Operator = "JOIN"
)

func (Operator) String

func (o Operator) String() string

type UpdateField

type UpdateField struct {
	// Skip indicates whether the UpdateField is effective.
	Skip bool

	// SkipFunc The priority is higher than Skip.
	SkipFunc func() bool

	Operator UpdateFieldOperator

	Value any

	// ValueFunc The priority is higher than Value.
	ValueFunc func() any
	// contains filtered or unexported fields
}

type UpdateFieldChain

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

func NewUpdateFieldChain

func NewUpdateFieldChain() UpdateFieldChain

func (UpdateFieldChain) Add

func (UpdateFieldChain) Assign

func (u UpdateFieldChain) Assign(field Field, value any, op ...opts.Opt[UpdateFieldChainOpts]) UpdateFieldChain

func (UpdateFieldChain) Build

func (u UpdateFieldChain) Build() map[string]any

func (UpdateFieldChain) Decr

func (UpdateFieldChain) Div

func (UpdateFieldChain) Incr

func (UpdateFieldChain) Mul

func (UpdateFieldChain) Sub

type UpdateFieldChainOpts

type UpdateFieldChainOpts struct {
	Skip      bool
	SkipFunc  func() bool
	ValueFunc func() any
}

func (UpdateFieldChainOpts) DefaultOptions

func (opts UpdateFieldChainOpts) DefaultOptions() UpdateFieldChainOpts

type UpdateFieldOperator

type UpdateFieldOperator string
const (
	Incr   UpdateFieldOperator = "INCR"
	Decr   UpdateFieldOperator = "DECR"
	Assign UpdateFieldOperator = "ASSIGN"
	Add    UpdateFieldOperator = "ADD"
	Sub    UpdateFieldOperator = "SUB"
	Mul    UpdateFieldOperator = "MUL"
	Div    UpdateFieldOperator = "DIV"
)

Jump to

Keyboard shortcuts

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