clause
v1.31.2
Documentation
pkg.go.dev ↗Package clause provides the clause interface and common clause implementations for GORM.
Constants
PrimaryKey (3 declarations)
const ( PrimaryKey string = "~~~py~~~" // primary key CurrentTable string = "~~~ct~~~" // current table Associations string = "~~~as~~~" // associations )
LockingStrengthUpdate (4 declarations)
const ( LockingStrengthUpdate = "UPDATE" LockingStrengthShare = "SHARE" LockingOptionsSkipLocked = "SKIP LOCKED" LockingOptionsNoWait = "NOWAIT" )
AndWithSpace (2 declarations)
const ( AndWithSpace = " AND " OrWithSpace = " OR " )
Variables
PrimaryColumn
var (
PrimaryColumn = Column{Table: CurrentTable, Name: PrimaryKey}
)
Types
AndConditions
type AndConditions struct {
Exprs []Expression
}
AndConditions.Build
func (and AndConditions) Build(builder Builder)
Assigner
type Assigner interface {
Assignments() []Assignment
}
Assigner assignments provider interface
Assignment
type Assignment struct {
Column Column
Value interface{}
}
Assignment.Assignments
func (a Assignment) Assignments() []Assignment
Assignments implements Assigner for a single Assignment.
Association
type Association struct {
Association string // Association name
Type AssociationOpType // Operation type
Conditions []Expression // Filter conditions
Set []Assignment // Assignment operations (for Update and Create)
Values []interface{} // Values for Create operation
}
Association represents an association operation
Association.Assignments
func (ao Association) Assignments() []Assignment
Assignments implements the Assigner interface so that AssociationOperation can be used as a Set method parameter
Association.AssociationAssignments
func (ao Association) AssociationAssignments() []Association
AssociationAssignments implements the AssociationAssigner interface
AssociationAssigner
type AssociationAssigner interface {
AssociationAssignments() []Association
}
AssociationAssigner is an interface for association operation providers
AssociationOpType
type AssociationOpType int
AssociationOpType represents association operation types
OpUnlink (4 declarations)
const ( OpUnlink AssociationOpType = iota // Unlink association OpDelete // Delete association records OpUpdate // Update association records OpCreate // Create association records with assignments )
Builder
type Builder interface {
Writer
WriteQuoted(field interface{})
AddVar(Writer, ...interface{})
AddError(error) error
}
Builder builder interface
Clause
type Clause struct {
Name string // WHERE
BeforeExpression Expression
AfterNameExpression Expression
AfterExpression Expression
Expression Expression
Builder ClauseBuilder
}
Clause
Clause.Build
func (c Clause) Build(builder Builder)
Build build clause
ClauseBuilder
type ClauseBuilder func(Clause, Builder)
ClauseBuilder clause builder, allows to customize how to build clause
Column
type Column struct {
Table string
Name string
Alias string
Raw bool
}
Column quote with name
CommaExpression
type CommaExpression struct {
Exprs []Expression
}
CommaExpression represents a group of expressions separated by commas.
CommaExpression.Build
func (comma CommaExpression) Build(builder Builder)
Delete
type Delete struct {
Modifier string
}
Delete.Build
func (d Delete) Build(builder Builder)
Delete.MergeClause
func (d Delete) MergeClause(clause *Clause)
Delete.Name
func (d Delete) Name() string
Eq
type Eq struct {
Column interface{}
Value interface{}
}
Eq equal to for where
Eq.Build
func (eq Eq) Build(builder Builder)
Eq.NegationBuild
func (eq Eq) NegationBuild(builder Builder)
Expr
type Expr struct {
SQL string
Vars []interface{}
WithoutParentheses bool
}
Expr raw expression
Expr.Build
func (expr Expr) Build(builder Builder)
Build build raw expression
Expression
type Expression interface {
Build(builder Builder)
}
Expression expression interface
And
func And(exprs ...Expression) Expression
Not
func Not(exprs ...Expression) Expression
Or
func Or(exprs ...Expression) Expression
From
type From struct {
Tables []Table
Joins []Join
}
From from clause
From.Build
func (from From) Build(builder Builder)
Build build from clause
From.MergeClause
func (from From) MergeClause(clause *Clause)
MergeClause merge from clause
From.Name
func (from From) Name() string
Name from clause name
GroupBy
type GroupBy struct {
Columns []Column
Having []Expression
}
GroupBy group by clause
GroupBy.Build
func (groupBy GroupBy) Build(builder Builder)
Build build group by clause
GroupBy.MergeClause
func (groupBy GroupBy) MergeClause(clause *Clause)
MergeClause merge group by clause
GroupBy.Name
func (groupBy GroupBy) Name() string
Name from clause name
Gt
type Gt Eq
Gt greater than for where
Gt.Build
func (gt Gt) Build(builder Builder)
Gt.NegationBuild
func (gt Gt) NegationBuild(builder Builder)
Gte
type Gte Eq
Gte greater than or equal to for where
Gte.Build
func (gte Gte) Build(builder Builder)
Gte.NegationBuild
func (gte Gte) NegationBuild(builder Builder)
IN
type IN struct {
Column interface{}
Values []interface{}
}
IN Whether a value is within a set of values
IN.Build
func (in IN) Build(builder Builder)
IN.NegationBuild
func (in IN) NegationBuild(builder Builder)
Insert
type Insert struct {
Table Table
Modifier string
}
Insert.Build
func (insert Insert) Build(builder Builder)
Build build insert clause
Insert.MergeClause
func (insert Insert) MergeClause(clause *Clause)
MergeClause merge insert clause
Insert.Name
func (insert Insert) Name() string
Name insert clause name
Interface
type Interface interface {
Name() string
Build(Builder)
MergeClause(*Clause)
}
Interface clause interface
Join
type Join struct {
Type JoinType
Table Table
ON Where
Using []string
Expression Expression
}
Join clause for from
Join.Build
func (join Join) Build(builder Builder)
JoinTarget
type JoinTarget struct {
Type JoinType
Association string
Subquery Expression
Table string
}
Has
func Has(name string) JoinTarget
JoinTarget.As
func (jt JoinTarget) As(name string) JoinTarget
JoinType
type JoinType string
CrossJoin (4 declarations)
const ( CrossJoin JoinType = "CROSS" InnerJoin JoinType = "INNER" LeftJoin JoinType = "LEFT" RightJoin JoinType = "RIGHT" )
JoinType.Association
func (jt JoinType) Association(name string) JoinTarget
JoinType.AssociationFrom
func (jt JoinType) AssociationFrom(name string, subquery Expression) JoinTarget
Like
type Like Eq
Like whether string matches regular expression
Like.Build
func (like Like) Build(builder Builder)
Like.NegationBuild
func (like Like) NegationBuild(builder Builder)
Limit
type Limit struct {
Limit *int
Offset int
}
Limit limit clause
Limit.Build
func (limit Limit) Build(builder Builder)
Build build where clause
Limit.MergeClause
func (limit Limit) MergeClause(clause *Clause)
MergeClause merge order by clauses
Limit.Name
func (limit Limit) Name() string
Name where clause name
Locking
type Locking struct {
Strength string
Table Table
Options string
}
Locking.Build
func (locking Locking) Build(builder Builder)
Build build where clause
Locking.MergeClause
func (locking Locking) MergeClause(clause *Clause)
MergeClause merge order by clauses
Locking.Name
func (locking Locking) Name() string
Name where clause name
Lt
type Lt Eq
Lt less than for where
Lt.Build
func (lt Lt) Build(builder Builder)
Lt.NegationBuild
func (lt Lt) NegationBuild(builder Builder)
Lte
type Lte Eq
Lte less than or equal to for where
Lte.Build
func (lte Lte) Build(builder Builder)
Lte.NegationBuild
func (lte Lte) NegationBuild(builder Builder)
NamedExpr
type NamedExpr struct {
SQL string
Vars []interface{}
}
NamedExpr raw expression for named expr
NamedExpr.Build
func (expr NamedExpr) Build(builder Builder)
Build build raw expression
NegationExpressionBuilder
type NegationExpressionBuilder interface {
NegationBuild(builder Builder)
}
NegationExpressionBuilder negation expression builder
Neq
type Neq Eq
Neq not equal to for where
Neq.Build
func (neq Neq) Build(builder Builder)
Neq.NegationBuild
func (neq Neq) NegationBuild(builder Builder)
NotConditions
type NotConditions struct {
Exprs []Expression
}
NotConditions.Build
func (not NotConditions) Build(builder Builder)
OnConflict
type OnConflict struct {
Columns []Column
Where Where
TargetWhere Where
OnConstraint string
DoNothing bool
DoUpdates Set
UpdateAll bool
}
OnConflict.Build
func (onConflict OnConflict) Build(builder Builder)
Build build onConflict clause
OnConflict.MergeClause
func (onConflict OnConflict) MergeClause(clause *Clause)
MergeClause merge onConflict clauses
OnConflict.Name
func (OnConflict) Name() string
OrConditions
type OrConditions struct {
Exprs []Expression
}
OrConditions.Build
func (or OrConditions) Build(builder Builder)
OrderBy
type OrderBy struct {
Columns []OrderByColumn
Expression Expression
}
OrderBy.Build
func (orderBy OrderBy) Build(builder Builder)
Build build where clause
OrderBy.MergeClause
func (orderBy OrderBy) MergeClause(clause *Clause)
MergeClause merge order by clauses
OrderBy.Name
func (orderBy OrderBy) Name() string
Name where clause name
OrderByColumn
type OrderByColumn struct {
Column Column
Desc bool
Reorder bool
}
Returning
type Returning struct {
Columns []Column
}
Returning.Build
func (returning Returning) Build(builder Builder)
Build build where clause
Returning.MergeClause
func (returning Returning) MergeClause(clause *Clause)
MergeClause merge order by clauses
Returning.Name
func (returning Returning) Name() string
Name where clause name
Select
type Select struct {
Distinct bool
Columns []Column
Expression Expression
}
Select select attrs when querying, updating, creating
Select.Build
func (s Select) Build(builder Builder)
Select.MergeClause
func (s Select) MergeClause(clause *Clause)
Select.Name
func (s Select) Name() string
Set
type Set []Assignment
AssignmentColumns
func AssignmentColumns(values []string) Set
Assignments
func Assignments(values map[string]interface{}) Set
Set.Assignments
func (set Set) Assignments() []Assignment
Assignments implements Assigner for Set.
Set.Build
func (set Set) Build(builder Builder)
Set.MergeClause
func (set Set) MergeClause(clause *Clause)
MergeClause merge assignments clauses
Set.Name
func (set Set) Name() string
Table
type Table struct {
Name string
Alias string
Raw bool
}
Table quote with name
JoinTable
func JoinTable(names ...string) Table
Update
type Update struct {
Modifier string
Table Table
}
Update.Build
func (update Update) Build(builder Builder)
Build build update clause
Update.MergeClause
func (update Update) MergeClause(clause *Clause)
MergeClause merge update clause
Update.Name
func (update Update) Name() string
Name update clause name
Values
type Values struct {
Columns []Column
Values [][]interface{}
}
Values.Build
func (values Values) Build(builder Builder)
Build build from clause
Values.MergeClause
func (values Values) MergeClause(clause *Clause)
MergeClause merge values clauses
Values.Name
func (Values) Name() string
Name from clause name
Where
type Where struct {
Exprs []Expression
}
Where where clause
Where.Build
func (where Where) Build(builder Builder)
Build build where clause
Where.MergeClause
func (where Where) MergeClause(clause *Clause)
MergeClause merge where clauses
Where.Name
func (where Where) Name() string
Name where clause name
With
type With struct{}
Writer
type Writer interface {
WriteByte(byte) error
WriteString(string) (int, error)
}