Documentation
¶
Overview ¶
Package field provides type-safe field operations for GORM query builder.
Package field provides type-safe field operations for GORM query builder.
Package field provides type-safe field operations for GORM query builder.
Package field provides type-safe field operations for GORM query builder.
Package field provides type-safe field operations for GORM query builder.
Index ¶
- func BuildSelectExpr(ss ...Selectable) clause.Expression
- type AssignerExpression
- type AssociationInterface
- type Bool
- func (b Bool) AndExpr(expr clause.Expression) AssignerExpression
- func (b Bool) As(alias string) Selectable
- func (b Bool) Asc() clause.OrderByColumn
- func (b Bool) Column() clause.Column
- func (b Bool) Desc() clause.OrderByColumn
- func (b Bool) Eq(value bool) clause.Expression
- func (b Bool) EqExpr(expr clause.Expression) clause.Expression
- func (b Bool) Expr(expr string, values ...any) clause.Expression
- func (b Bool) IsNotNull() clause.Expression
- func (b Bool) IsNull() clause.Expression
- func (b Bool) NeqExpr(expr clause.Expression) clause.Expression
- func (b Bool) Not() AssignerExpression
- func (b Bool) OrExpr(expr clause.Expression) AssignerExpression
- func (b Bool) OrderExpr(expr string, values ...any) clause.Expression
- func (b Bool) SelectExpr(sql string, values ...any) Selectable
- func (b Bool) Set(val bool) clause.Assignment
- func (b Bool) SetExpr(expr clause.Expression) clause.Assignment
- func (b Bool) WithColumn(name string) Bool
- func (b Bool) WithTable(name string) Bool
- func (b Bool) Xor(value bool) AssignerExpression
- func (b Bool) XorExpr(expr clause.Expression) AssignerExpression
- type Bytes
- func (b Bytes) As(alias string) Selectable
- func (b Bytes) Asc() clause.OrderByColumn
- func (b Bytes) Column() clause.Column
- func (b Bytes) Concat(value []byte) AssignerExpression
- func (b Bytes) Desc() clause.OrderByColumn
- func (b Bytes) Eq(value []byte) clause.Expression
- func (b Bytes) EqExpr(expr clause.Expression) clause.Expression
- func (b Bytes) Expr(expr string, values ...any) clause.Expression
- func (b Bytes) In(values ...[]byte) clause.Expression
- func (b Bytes) IsNotNull() clause.Expression
- func (b Bytes) IsNull() clause.Expression
- func (b Bytes) Length() clause.Expression
- func (b Bytes) Neq(value []byte) clause.Expression
- func (b Bytes) NeqExpr(expr clause.Expression) clause.Expression
- func (b Bytes) NotIn(values ...[]byte) clause.Expression
- func (b Bytes) OrderExpr(expr string, values ...any) clause.Expression
- func (b Bytes) SelectExpr(sql string, values ...any) Selectable
- func (b Bytes) Set(val []byte) clause.Assignment
- func (b Bytes) SetExpr(expr clause.Expression) clause.Assignment
- func (b Bytes) WithColumn(name string) Bytes
- func (b Bytes) WithTable(name string) Bytes
- type ColumnInterface
- type DistinctInterface
- type Field
- func (f Field[T]) As(alias string) Selectable
- func (f Field[T]) Asc() clause.OrderByColumn
- func (f Field[T]) Column() clause.Column
- func (f Field[T]) Desc() clause.OrderByColumn
- func (f Field[T]) Eq(value T) clause.Expression
- func (f Field[T]) EqExpr(expr clause.Expression) clause.Expression
- func (f Field[T]) Expr(expr string, values ...any) clause.Expression
- func (f Field[T]) IsNotNull() clause.Expression
- func (f Field[T]) IsNull() clause.Expression
- func (f Field[T]) Neq(value T) clause.Expression
- func (f Field[T]) NeqExpr(expr clause.Expression) clause.Expression
- func (f Field[T]) OrderExpr(expr string, values ...any) clause.Expression
- func (f Field[T]) SelectExpr(sql string, values ...any) Selectable
- func (f Field[T]) Set(value T) clause.Assignment
- func (f Field[T]) SetExpr(expr clause.Expression) clause.Assignment
- func (f Field[T]) WithColumn(name string) Field[T]
- func (f Field[T]) WithTable(name string) Field[T]
- type Number
- func (n Number[T]) As(alias string) Selectable
- func (n Number[T]) Asc() clause.OrderByColumn
- func (n Number[T]) Between(v1, v2 T) clause.Expression
- func (n Number[T]) Column() clause.Column
- func (n Number[T]) Decr(value T) AssignerExpression
- func (n Number[T]) Desc() clause.OrderByColumn
- func (n Number[T]) Div(value T) AssignerExpression
- func (n Number[T]) Eq(value T) clause.Expression
- func (n Number[T]) EqExpr(expr clause.Expression) clause.Expression
- func (n Number[T]) Expr(expr string, values ...any) clause.Expression
- func (n Number[T]) Gt(value T) clause.Expression
- func (n Number[T]) GtExpr(expr clause.Expression) clause.Expression
- func (n Number[T]) Gte(value T) clause.Expression
- func (n Number[T]) GteExpr(expr clause.Expression) clause.Expression
- func (n Number[T]) In(values ...T) clause.Expression
- func (n Number[T]) Incr(value T) AssignerExpression
- func (n Number[T]) IsNotNull() clause.Expression
- func (n Number[T]) IsNull() clause.Expression
- func (n Number[T]) Lt(value T) clause.Expression
- func (n Number[T]) LtExpr(expr clause.Expression) clause.Expression
- func (n Number[T]) Lte(value T) clause.Expression
- func (n Number[T]) LteExpr(expr clause.Expression) clause.Expression
- func (n Number[T]) Mul(value T) AssignerExpression
- func (n Number[T]) Neq(value T) clause.Expression
- func (n Number[T]) NeqExpr(expr clause.Expression) clause.Expression
- func (n Number[T]) NotIn(values ...T) clause.Expression
- func (n Number[T]) OrderExpr(expr string, values ...any) clause.Expression
- func (n Number[T]) SelectExpr(sql string, values ...any) Selectable
- func (n Number[T]) Set(val T) clause.Assignment
- func (n Number[T]) SetExpr(expr clause.Expression) clause.Assignment
- func (n Number[T]) WithColumn(name string) Number[T]
- func (n Number[T]) WithTable(name string) Number[T]
- type OrderableInterface
- type QueryInterface
- type Selectable
- type Slice
- func (s Slice[T]) Create(assignments ...clause.Assignment) clause.Association
- func (s Slice[T]) CreateInBatch(records []T) clause.Association
- func (w Slice) Delete() clause.Association
- func (s Slice[T]) Name() string
- func (w Slice) Unlink() clause.Association
- func (w Slice) Update(assignments ...clause.Assignment) clause.Association
- func (s Slice[T]) Where(conditions ...clause.Expression) associationWithConditions[T]
- func (s Slice[T]) WithName(name string) Slice[T]
- type String
- func (s String) As(alias string) Selectable
- func (s String) Asc() clause.OrderByColumn
- func (s String) Column() clause.Column
- func (s String) Concat(value string) AssignerExpression
- func (s String) Desc() clause.OrderByColumn
- func (s String) Eq(value string) clause.Expression
- func (s String) EqExpr(expr clause.Expression) clause.Expression
- func (s String) Expr(expr string, values ...any) clause.Expression
- func (s String) Gt(value string) clause.Expression
- func (s String) GtExpr(expr clause.Expression) clause.Expression
- func (s String) Gte(value string) clause.Expression
- func (s String) GteExpr(expr clause.Expression) clause.Expression
- func (s String) ILike(pattern string) clause.Expression
- func (s String) In(values ...string) clause.Expression
- func (s String) IsNotNull() clause.Expression
- func (s String) IsNull() clause.Expression
- func (s String) Left(length int) AssignerExpression
- func (s String) Length() clause.Expression
- func (s String) Like(pattern string) clause.Expression
- func (s String) Lower() AssignerExpression
- func (s String) Lt(value string) clause.Expression
- func (s String) LtExpr(expr clause.Expression) clause.Expression
- func (s String) Lte(value string) clause.Expression
- func (s String) LteExpr(expr clause.Expression) clause.Expression
- func (s String) Neq(value string) clause.Expression
- func (s String) NeqExpr(expr clause.Expression) clause.Expression
- func (s String) NotILike(pattern string) clause.Expression
- func (s String) NotIn(values ...string) clause.Expression
- func (s String) NotLike(pattern string) clause.Expression
- func (s String) NotRegexp(pattern string) clause.Expression
- func (s String) OrderExpr(expr string, values ...any) clause.Expression
- func (s String) Regexp(pattern string) clause.Expression
- func (s String) Right(length int) AssignerExpression
- func (s String) SelectExpr(sql string, values ...any) Selectable
- func (s String) Set(val string) clause.Assignment
- func (s String) SetExpr(expr clause.Expression) clause.Assignment
- func (s String) Substring(start, length int) AssignerExpression
- func (s String) Trim() AssignerExpression
- func (s String) Upper() AssignerExpression
- func (s String) WithColumn(name string) String
- func (s String) WithTable(name string) String
- type Struct
- func (s Struct[T]) Create(assignments ...clause.Assignment) clause.Association
- func (w Struct) Delete() clause.Association
- func (s Struct[T]) Name() string
- func (w Struct) Unlink() clause.Association
- func (w Struct) Update(assignments ...clause.Assignment) clause.Association
- func (s Struct[T]) Where(conditions ...clause.Expression) associationWithConditions[T]
- func (s Struct[T]) WithName(name string) Struct[T]
- type Time
- func (t Time) Add(duration time.Duration) AssignerExpression
- func (t Time) As(alias string) Selectable
- func (t Time) Asc() clause.OrderByColumn
- func (t Time) Between(v1, v2 time.Time) clause.Expression
- func (t Time) Column() clause.Column
- func (t Time) Date() clause.Expression
- func (t Time) DateDiff(date time.Time) clause.Expression
- func (t Time) DateFormat(format string) clause.Expression
- func (t Time) Day() clause.Expression
- func (t Time) Desc() clause.OrderByColumn
- func (t Time) Eq(value time.Time) clause.Expression
- func (t Time) EqExpr(expr clause.Expression) clause.Expression
- func (t Time) Expr(expr string, values ...any) clause.Expression
- func (t Time) Gt(value time.Time) clause.Expression
- func (t Time) GtExpr(expr clause.Expression) clause.Expression
- func (t Time) Gte(value time.Time) clause.Expression
- func (t Time) GteExpr(expr clause.Expression) clause.Expression
- func (t Time) Hour() clause.Expression
- func (t Time) In(values ...time.Time) clause.Expression
- func (t Time) IsNotNull() clause.Expression
- func (t Time) IsNull() clause.Expression
- func (t Time) Lt(value time.Time) clause.Expression
- func (t Time) LtExpr(expr clause.Expression) clause.Expression
- func (t Time) Lte(value time.Time) clause.Expression
- func (t Time) LteExpr(expr clause.Expression) clause.Expression
- func (t Time) Minute() clause.Expression
- func (t Time) Month() clause.Expression
- func (t Time) Neq(value time.Time) clause.Expression
- func (t Time) NeqExpr(expr clause.Expression) clause.Expression
- func (t Time) NotIn(values ...time.Time) clause.Expression
- func (t Time) Now() AssignerExpression
- func (t Time) OrderExpr(expr string, values ...any) clause.Expression
- func (t Time) Second() clause.Expression
- func (t Time) SelectExpr(sql string, values ...any) Selectable
- func (t Time) Set(val time.Time) clause.Assignment
- func (t Time) SetExpr(expr clause.Expression) clause.Assignment
- func (t Time) Sub(duration time.Duration) AssignerExpression
- func (t Time) Time() clause.Expression
- func (t Time) Unix() clause.Expression
- func (t Time) WithColumn(name string) Time
- func (t Time) WithTable(name string) Time
- func (t Time) Year() clause.Expression
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildSelectExpr ¶
func BuildSelectExpr(ss ...Selectable) clause.Expression
Types ¶
type AssignerExpression ¶
type AssignerExpression interface {
clause.Expression
clause.Assigner
}
AssignerExpression combines a clause.Expression with an Assignments provider.
type AssociationInterface ¶
type AssociationInterface interface {
Name() string
}
AssociationInterface defines association
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool represents a boolean field that provides type-safe operations for building SQL queries.
func (Bool) AndExpr ¶
func (b Bool) AndExpr(expr clause.Expression) AssignerExpression
AndExpr creates a logical AND expression (field AND expression). Use this to combine the boolean field with another expression using logical AND.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
isEnabled := field.Bool{column: clause.Column{Name: "is_enabled"}}
// Generate: WHERE is_active AND is_enabled
condition := isActive.AndExpr(isEnabled)
func (Bool) As ¶
func (b Bool) As(alias string) Selectable
As creates an alias for this column usable in Select(...)
func (Bool) Asc ¶
func (b Bool) Asc() clause.OrderByColumn
Asc creates an ascending order expression for ORDER BY clauses. Use this to sort the boolean field in ascending order (false before true).
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: ORDER BY is_active ASC
order := isActive.Asc()
func (Bool) Desc ¶
func (b Bool) Desc() clause.OrderByColumn
Desc creates a descending order expression for ORDER BY clauses. Use this to sort the boolean field in descending order (true before false).
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: ORDER BY is_active DESC
order := isActive.Desc()
func (Bool) Eq ¶
func (b Bool) Eq(value bool) clause.Expression
Eq creates an equality comparison expression (field = value). Use this to compare the boolean field with a specific boolean value.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: WHERE is_active = true
condition := isActive.Eq(true)
func (Bool) EqExpr ¶
func (b Bool) EqExpr(expr clause.Expression) clause.Expression
EqExpr creates an equality comparison expression (field = expression). Use this to compare the boolean field with another expression or subquery.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
isEnabled := field.Bool{column: clause.Column{Name: "is_enabled"}}
// Generate: WHERE is_active = is_enabled
condition := isActive.EqExpr(isEnabled)
func (Bool) Expr ¶
func (b Bool) Expr(expr string, values ...any) clause.Expression
Expr creates a custom SQL expression with parameters. Use this to create complex SQL expressions with placeholders and values.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: WHERE is_active AND status IN ('active', 'pending')
condition := isActive.Expr("? AND status IN (?, ?)", isActive, "active", "pending")
func (Bool) IsNotNull ¶
func (b Bool) IsNotNull() clause.Expression
IsNotNull creates a NOT NULL check expression (field IS NOT NULL). Use this to check if the boolean field value is not NULL.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: WHERE is_active IS NOT NULL
condition := isActive.IsNotNull()
func (Bool) IsNull ¶
func (b Bool) IsNull() clause.Expression
IsNull creates a NULL check expression (field IS NULL). Use this to check if the boolean field value is NULL.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: WHERE is_active IS NULL
condition := isActive.IsNull()
func (Bool) NeqExpr ¶
func (b Bool) NeqExpr(expr clause.Expression) clause.Expression
NeqExpr creates a not equal comparison expression (field != expression). Use this to check if the boolean field is different from another expression.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
isEnabled := field.Bool{column: clause.Column{Name: "is_enabled"}}
// Generate: WHERE is_active != is_enabled
condition := isActive.NeqExpr(isEnabled)
func (Bool) Not ¶
func (b Bool) Not() AssignerExpression
Not creates a logical NOT expression (NOT field). Use this to negate the boolean field value.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: WHERE NOT is_active
condition := isActive.Not()
func (Bool) OrExpr ¶
func (b Bool) OrExpr(expr clause.Expression) AssignerExpression
OrExpr creates a logical OR expression (field OR expression). Use this to combine the boolean field with another expression using logical OR.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
isEnabled := field.Bool{column: clause.Column{Name: "is_enabled"}}
// Generate: WHERE is_active OR is_enabled
condition := isActive.OrExpr(isEnabled)
func (Bool) OrderExpr ¶
func (b Bool) OrderExpr(expr string, values ...any) clause.Expression
OrderExpr creates a custom ORDER BY expression with parameters. Use this to create complex ordering expressions for boolean fields.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: ORDER BY CASE WHEN is_active THEN 0 ELSE 1 END
order := isActive.OrderExpr("CASE WHEN ? THEN 0 ELSE 1 END", isActive)
func (Bool) SelectExpr ¶
func (b Bool) SelectExpr(sql string, values ...any) Selectable
SelectExpr wraps a custom expression built from this field for Select(...)
func (Bool) Set ¶
func (b Bool) Set(val bool) clause.Assignment
Set creates an assignment expression for UPDATE operations (field = value). Use this to set the boolean field to a specific boolean value.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: SET is_active = true
assignment := isActive.Set(true)
func (Bool) SetExpr ¶
func (b Bool) SetExpr(expr clause.Expression) clause.Assignment
SetExpr creates an assignment expression for UPDATE operations (field = expression). Use this to set the boolean field to the result of another expression or field.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
isEnabled := field.Bool{column: clause.Column{Name: "is_enabled"}}
// Generate: SET is_active = is_enabled
assignment := isActive.SetExpr(isEnabled)
func (Bool) WithColumn ¶
WithColumn creates a new Bool field with the specified column name. This method allows you to change the column name while keeping other properties.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
isEnabled := isActive.WithColumn("is_enabled")
func (Bool) WithTable ¶
WithTable creates a new Bool field with the specified table name. This method is useful when working with joins and you need to qualify the column with a table name.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
userIsActive := isActive.WithTable("users")
func (Bool) Xor ¶
func (b Bool) Xor(value bool) AssignerExpression
Xor creates a logical XOR expression (field XOR value). Use this to create an exclusive OR condition between the field and a boolean value.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
// Generate: WHERE is_active XOR true
condition := isActive.Xor(true)
func (Bool) XorExpr ¶
func (b Bool) XorExpr(expr clause.Expression) AssignerExpression
XorExpr creates a logical XOR expression (field XOR expression). Use this to create an exclusive OR condition between the field and another expression.
Example:
isActive := field.Bool{column: clause.Column{Name: "is_active"}}
isEnabled := field.Bool{column: clause.Column{Name: "is_enabled"}}
// Generate: WHERE is_active XOR is_enabled
condition := isActive.XorExpr(isEnabled)
type Bytes ¶
type Bytes struct {
// contains filtered or unexported fields
}
Bytes represents a byte slice field that provides type-safe operations for building SQL queries.
func (Bytes) As ¶
func (b Bytes) As(alias string) Selectable
As creates an alias for this column usable in Select(...)
func (Bytes) Asc ¶
func (b Bytes) Asc() clause.OrderByColumn
Asc creates an ascending order expression for ORDER BY clauses.
func (Bytes) Concat ¶
func (b Bytes) Concat(value []byte) AssignerExpression
Concat creates a binary concatenation expression (CONCAT(field, value)).
func (Bytes) Desc ¶
func (b Bytes) Desc() clause.OrderByColumn
Desc creates a descending order expression for ORDER BY clauses.
func (Bytes) Eq ¶
func (b Bytes) Eq(value []byte) clause.Expression
Eq creates an equality comparison expression (field = value).
func (Bytes) EqExpr ¶
func (b Bytes) EqExpr(expr clause.Expression) clause.Expression
EqExpr creates an equality comparison expression (field = expression).
func (Bytes) Expr ¶
func (b Bytes) Expr(expr string, values ...any) clause.Expression
Expr creates a custom SQL expression with parameters.
func (Bytes) In ¶
func (b Bytes) In(values ...[]byte) clause.Expression
In creates an IN comparison expression (field IN (values...)).
func (Bytes) IsNotNull ¶
func (b Bytes) IsNotNull() clause.Expression
IsNotNull creates a NOT NULL check expression (field IS NOT NULL).
func (Bytes) IsNull ¶
func (b Bytes) IsNull() clause.Expression
IsNull creates a NULL check expression (field IS NULL).
func (Bytes) Length ¶
func (b Bytes) Length() clause.Expression
Length creates a byte length expression (LENGTH(field)).
func (Bytes) Neq ¶
func (b Bytes) Neq(value []byte) clause.Expression
Neq creates a not equal comparison expression (field != value).
func (Bytes) NeqExpr ¶
func (b Bytes) NeqExpr(expr clause.Expression) clause.Expression
NeqExpr creates a not equal comparison expression (field != expression).
func (Bytes) NotIn ¶
func (b Bytes) NotIn(values ...[]byte) clause.Expression
NotIn creates a NOT IN comparison expression (field NOT IN (values...)).
func (Bytes) OrderExpr ¶
func (b Bytes) OrderExpr(expr string, values ...any) clause.Expression
OrderExpr creates a custom ORDER BY expression with parameters.
func (Bytes) SelectExpr ¶
func (b Bytes) SelectExpr(sql string, values ...any) Selectable
SelectExpr wraps a custom expression built from this field for Select(...)
func (Bytes) Set ¶
func (b Bytes) Set(val []byte) clause.Assignment
Set creates an assignment expression for UPDATE operations (field = value).
func (Bytes) SetExpr ¶
func (b Bytes) SetExpr(expr clause.Expression) clause.Assignment
SetExpr creates an assignment expression for UPDATE operations (field = expression).
func (Bytes) WithColumn ¶
WithColumn creates a new Bytes field with the specified column name. This method allows you to change the column name while keeping other properties.
Example:
avatar := field.Bytes{column: clause.Column{Name: "user_avatar"}}
thumbnail := avatar.WithColumn("thumbnail")
func (Bytes) WithTable ¶
WithTable creates a new Bytes field with the specified table name. This method is useful when working with joins and you need to qualify the column with a table name.
Example:
avatar := field.Bytes{column: clause.Column{Name: "avatar"}}
userAvatar := avatar.WithTable("users")
type ColumnInterface ¶
ColumnInterface defines the interface for column operations
type DistinctInterface ¶
type DistinctInterface interface {
// contains filtered or unexported methods
}
DistinctInterface defines the interface for distinct operations
type Field ¶
type Field[T any] struct { // contains filtered or unexported fields }
Field<T> represents a generic field that provides type-safe operations for building SQL queries. This is the base type for all field operations in GORM query builder.
func (Field[T]) As ¶
func (f Field[T]) As(alias string) Selectable
As creates a column alias usable in Select(...), e.g. SELECT col AS alias
func (Field[T]) Asc ¶
func (f Field[T]) Asc() clause.OrderByColumn
Asc creates an ascending order expression for ORDER BY clauses. Use this to sort the field in ascending order.
Example:
field := field.Field[T]{column: clause.Column{Name: "created_at"}}
// Generate: ORDER BY created_at ASC
order := field.Asc()
func (Field[T]) Desc ¶
func (f Field[T]) Desc() clause.OrderByColumn
Desc creates a descending order expression for ORDER BY clauses. Use this to sort the field in descending order.
Example:
field := field.Field[T]{column: clause.Column{Name: "created_at"}}
// Generate: ORDER BY created_at DESC
order := field.Desc()
func (Field[T]) Eq ¶
func (f Field[T]) Eq(value T) clause.Expression
Eq creates an equality comparison expression (field = value). Use this to compare the field with a specific value.
Example:
field := field.Field[T]{column: clause.Column{Name: "status"}}
// Generate: WHERE status = 'active'
condition := field.Eq("active")
func (Field[T]) EqExpr ¶
func (f Field[T]) EqExpr(expr clause.Expression) clause.Expression
EqExpr creates an equality comparison expression (field = expression). Use this to compare the field with another expression or subquery.
Example:
field1 := field.Field[T]{column: clause.Column{Name: "field1"}}
field2 := field.Field[T]{column: clause.Column{Name: "field2"}}
// Generate: WHERE field1 = field2
condition := field1.EqExpr(field2)
func (Field[T]) Expr ¶
func (f Field[T]) Expr(expr string, values ...any) clause.Expression
Expr creates a custom SQL expression with parameters. Use this to create complex SQL expressions with placeholders and values.
Example:
field := field.Field[T]{column: clause.Column{Name: "status"}}
// Generate: WHERE status IN ('active', 'pending')
condition := field.Expr("? IN (?, ?)", field, "active", "pending")
func (Field[T]) IsNotNull ¶
func (f Field[T]) IsNotNull() clause.Expression
IsNotNull creates a NOT NULL check expression (field IS NOT NULL). Use this to check if the field value is not NULL.
Example:
field := field.Field[T]{column: clause.Column{Name: "deleted_at"}}
// Generate: WHERE deleted_at IS NOT NULL
condition := field.IsNotNull()
func (Field[T]) IsNull ¶
func (f Field[T]) IsNull() clause.Expression
IsNull creates a NULL check expression (field IS NULL). Use this to check if the field value is NULL.
Example:
field := field.Field[T]{column: clause.Column{Name: "deleted_at"}}
// Generate: WHERE deleted_at IS NULL
condition := field.IsNull()
func (Field[T]) Neq ¶
func (f Field[T]) Neq(value T) clause.Expression
Neq creates a not equal comparison expression (field != value). Use this to check if the field is different from a specific value.
Example:
field := field.Field[T]{column: clause.Column{Name: "status"}}
// Generate: WHERE status != 'inactive'
condition := field.Neq("inactive")
func (Field[T]) NeqExpr ¶
func (f Field[T]) NeqExpr(expr clause.Expression) clause.Expression
NeqExpr creates a not equal comparison expression (field != expression). Use this to check if the field is different from another expression.
Example:
field1 := field.Field[T]{column: clause.Column{Name: "field1"}}
field2 := field.Field[T]{column: clause.Column{Name: "field2"}}
// Generate: WHERE field1 != field2
condition := field1.NeqExpr(field2)
func (Field[T]) OrderExpr ¶
func (f Field[T]) OrderExpr(expr string, values ...any) clause.Expression
OrderExpr creates a custom ORDER BY expression with parameters. Use this to create complex ordering expressions.
Example:
field := field.Field[T]{column: clause.Column{Name: "name"}}
// Generate: ORDER BY CASE WHEN name IS NULL THEN 1 ELSE 0 END
order := field.OrderExpr("CASE WHEN ? IS NULL THEN 1 ELSE 0 END", field)
func (Field[T]) SelectExpr ¶
func (f Field[T]) SelectExpr(sql string, values ...any) Selectable
SelectExpr wraps a custom expression built from this field for Select(...)
func (Field[T]) Set ¶
func (f Field[T]) Set(value T) clause.Assignment
Set creates an assignment expression for UPDATE operations (field = value). Use this to set the field to a specific value.
Example:
field := field.Field[T]{column: clause.Column{Name: "status"}}
// Generate: SET status = 'active'
assignment := field.Set("active")
func (Field[T]) SetExpr ¶
func (f Field[T]) SetExpr(expr clause.Expression) clause.Assignment
SetExpr creates an assignment expression for UPDATE operations (field = expression). Use this to set the field to the result of another expression or field.
Example:
field1 := field.Field[T]{column: clause.Column{Name: "field1"}}
field2 := field.Field[T]{column: clause.Column{Name: "field2"}}
// Generate: SET field1 = field2
assignment := field1.SetExpr(field2)
func (Field[T]) WithColumn ¶
WithColumn creates a new Field[T]<T> with the specified column name. This method allows you to change the column name while keeping other properties.
Example:
field := field.Field[T]{column: clause.Column{Name: "original_name"}}
newField[T] := field.WithColumn("new_name")
func (Field[T]) WithTable ¶
WithTable creates a new Field[T]<T> with the specified table name. This method is useful when working with joins and you need to qualify the column with a table name.
Example:
field := field.Field[T]{column: clause.Column{Name: "name"}}
userField[T] := field.WithTable("users")
type Number ¶
type Number[T constraints.Integer | constraints.Float] struct { // contains filtered or unexported fields }
Number represents a numeric field that supports both integer and float types. It provides type-safe operations for building SQL queries.
func (Number[T]) As ¶
func (n Number[T]) As(alias string) Selectable
As creates an alias for this column usable in Select(...)
func (Number[T]) Asc ¶
func (n Number[T]) Asc() clause.OrderByColumn
Asc creates an ascending order expression for ORDER BY clauses.
func (Number[T]) Between ¶
func (n Number[T]) Between(v1, v2 T) clause.Expression
Between creates a range comparison expression (field BETWEEN v1 AND v2).
func (Number[T]) Decr ¶
func (n Number[T]) Decr(value T) AssignerExpression
Decr creates a decrement expression (field - value).
func (Number[T]) Desc ¶
func (n Number[T]) Desc() clause.OrderByColumn
Desc creates a descending order expression for ORDER BY clauses.
func (Number[T]) Div ¶
func (n Number[T]) Div(value T) AssignerExpression
Div creates a division expression (field / value).
func (Number[T]) Eq ¶
func (n Number[T]) Eq(value T) clause.Expression
Eq creates an equality comparison expression (field = value).
func (Number[T]) EqExpr ¶
func (n Number[T]) EqExpr(expr clause.Expression) clause.Expression
EqExpr creates an equality comparison expression (field = expression).
func (Number[T]) Expr ¶
func (n Number[T]) Expr(expr string, values ...any) clause.Expression
Expr creates a custom SQL expression with parameters.
func (Number[T]) Gt ¶
func (n Number[T]) Gt(value T) clause.Expression
Gt creates a greater than comparison expression (field > value).
func (Number[T]) GtExpr ¶
func (n Number[T]) GtExpr(expr clause.Expression) clause.Expression
GtExpr creates a greater than comparison expression (field > expression).
func (Number[T]) Gte ¶
func (n Number[T]) Gte(value T) clause.Expression
Gte creates a greater than or equal comparison expression (field >= value).
func (Number[T]) GteExpr ¶
func (n Number[T]) GteExpr(expr clause.Expression) clause.Expression
GteExpr creates a greater than or equal comparison expression (field >= expression).
func (Number[T]) In ¶
func (n Number[T]) In(values ...T) clause.Expression
In creates an IN comparison expression (field IN (values...)).
func (Number[T]) Incr ¶
func (n Number[T]) Incr(value T) AssignerExpression
Incr creates an increment expression (field + value).
func (Number[T]) IsNotNull ¶
func (n Number[T]) IsNotNull() clause.Expression
IsNotNull creates a NOT NULL check expression (field IS NOT NULL).
func (Number[T]) IsNull ¶
func (n Number[T]) IsNull() clause.Expression
IsNull creates a NULL check expression (field IS NULL).
func (Number[T]) Lt ¶
func (n Number[T]) Lt(value T) clause.Expression
Lt creates a less than comparison expression (field < value).
func (Number[T]) LtExpr ¶
func (n Number[T]) LtExpr(expr clause.Expression) clause.Expression
LtExpr creates a less than comparison expression (field < expression).
func (Number[T]) Lte ¶
func (n Number[T]) Lte(value T) clause.Expression
Lte creates a less than or equal comparison expression (field <= value).
func (Number[T]) LteExpr ¶
func (n Number[T]) LteExpr(expr clause.Expression) clause.Expression
LteExpr creates a less than or equal comparison expression (field <= expression).
func (Number[T]) Mul ¶
func (n Number[T]) Mul(value T) AssignerExpression
Mul creates a multiplication expression (field * value).
func (Number[T]) Neq ¶
func (n Number[T]) Neq(value T) clause.Expression
Neq creates a not equal comparison expression (field != value).
func (Number[T]) NeqExpr ¶
func (n Number[T]) NeqExpr(expr clause.Expression) clause.Expression
NeqExpr creates a not equal comparison expression (field != expression).
func (Number[T]) NotIn ¶
func (n Number[T]) NotIn(values ...T) clause.Expression
NotIn creates a NOT IN comparison expression (field NOT IN (values...)).
func (Number[T]) OrderExpr ¶
func (n Number[T]) OrderExpr(expr string, values ...any) clause.Expression
OrderExpr creates a custom ORDER BY expression with parameters.
func (Number[T]) SelectExpr ¶
func (n Number[T]) SelectExpr(sql string, values ...any) Selectable
SelectExpr wraps a custom expression built from this field for Select(...)
func (Number[T]) Set ¶
func (n Number[T]) Set(val T) clause.Assignment
Set creates an assignment expression for UPDATE operations (field = value).
func (Number[T]) SetExpr ¶
func (n Number[T]) SetExpr(expr clause.Expression) clause.Assignment
SetExpr creates an assignment expression for UPDATE operations (field = expression).
func (Number[T]) WithColumn ¶
WithColumn creates a new Number field with the specified column name. This method allows you to change the column name while keeping other properties.
Example:
age := NewNumber[int]("user_age")
userAge := age.WithColumn("age")
func (Number[T]) WithTable ¶
WithTable creates a new Number field with the specified table name. This method is useful when working with joins and you need to qualify the column with a table name.
Example:
age := field.Number[int]{column: clause.Column{Name: "age"}}
userAge := age.WithTable("users")
type OrderableInterface ¶
OrderableInterface defines the interface for orderable expressions
type QueryInterface ¶
type QueryInterface = clause.Expression
QueryInterface defines the interface for building conditions
type Selectable ¶
type Selectable interface {
// contains filtered or unexported methods
}
Selectable defines the interface for Select operations
type Slice ¶
type Slice[T any] struct { // contains filtered or unexported fields }
Slice represents a slice field for multiple association operations
func (Slice[T]) Create ¶
func (s Slice[T]) Create(assignments ...clause.Assignment) clause.Association
Create prepares an association create operation for a slice (has many/many2many) association. Creates one associated record per matched parent using provided assignments.
func (Slice[T]) CreateInBatch ¶
func (s Slice[T]) CreateInBatch(records []T) clause.Association
CreateInBatch prepares an association batch create for a slice association. Creates all provided records for each matched parent.
func (Slice) Delete ¶
func (w Slice) Delete() clause.Association
Delete removes records from the associated table Delete prepares an association delete operation. Use with Set(...).Update(ctx) to delete matched associated records for matched parents.
func (Slice) Unlink ¶
func (w Slice) Unlink() clause.Association
Unlink removes the association without deleting associated records. Unlink semantics: - belongs to: sets the parent's foreign key to NULL - has one / has many: sets the child's foreign key to NULL - many2many: removes join table rows only Use with Set(...).Update(ctx).
func (Slice) Update ¶
func (w Slice) Update(assignments ...clause.Assignment) clause.Association
Update updates records in the associated table Update prepares an association update operation with optional conditions. Use with Set(...).Update(ctx) to update matched associated records for matched parents.
func (Slice[T]) Where ¶
func (s Slice[T]) Where(conditions ...clause.Expression) associationWithConditions[T]
Where adds conditions to a Slice field
type String ¶
type String struct {
// contains filtered or unexported fields
}
String represents a string field that provides type-safe operations for building SQL queries.
func (String) As ¶
func (s String) As(alias string) Selectable
As creates an alias for this column usable in Select(...)
func (String) Asc ¶
func (s String) Asc() clause.OrderByColumn
Asc creates an ascending order expression for ORDER BY clauses.
func (String) Concat ¶
func (s String) Concat(value string) AssignerExpression
Concat creates a string concatenation expression.
func (String) Desc ¶
func (s String) Desc() clause.OrderByColumn
Desc creates a descending order expression for ORDER BY clauses.
func (String) Eq ¶
func (s String) Eq(value string) clause.Expression
Eq creates an equality comparison expression (field = value).
func (String) EqExpr ¶
func (s String) EqExpr(expr clause.Expression) clause.Expression
EqExpr creates an equality comparison expression (field = expression).
func (String) Expr ¶
func (s String) Expr(expr string, values ...any) clause.Expression
Expr creates a custom SQL expression with parameters.
func (String) Gt ¶
func (s String) Gt(value string) clause.Expression
Gt creates a greater than comparison expression (field > value).
func (String) GtExpr ¶
func (s String) GtExpr(expr clause.Expression) clause.Expression
GtExpr creates a greater than comparison expression (field > expression).
func (String) Gte ¶
func (s String) Gte(value string) clause.Expression
Gte creates a greater than or equal comparison expression (field >= value).
func (String) GteExpr ¶
func (s String) GteExpr(expr clause.Expression) clause.Expression
GteExpr creates a greater than or equal comparison expression (field >= expression).
func (String) ILike ¶
func (s String) ILike(pattern string) clause.Expression
ILike creates a case-insensitive LIKE pattern matching expression (field ILIKE pattern).
func (String) In ¶
func (s String) In(values ...string) clause.Expression
In creates an IN comparison expression (field IN (values...)).
func (String) IsNotNull ¶
func (s String) IsNotNull() clause.Expression
IsNotNull creates a NOT NULL check expression (field IS NOT NULL).
func (String) IsNull ¶
func (s String) IsNull() clause.Expression
IsNull creates a NULL check expression (field IS NULL).
func (String) Left ¶
func (s String) Left(length int) AssignerExpression
Left creates a left substring expression.
func (String) Length ¶
func (s String) Length() clause.Expression
Length creates a string length expression.
func (String) Like ¶
func (s String) Like(pattern string) clause.Expression
Like creates a LIKE pattern matching expression (field LIKE pattern).
func (String) Lower ¶
func (s String) Lower() AssignerExpression
Lower creates a lowercase conversion expression.
func (String) Lt ¶
func (s String) Lt(value string) clause.Expression
Lt creates a less than comparison expression (field < value).
func (String) LtExpr ¶
func (s String) LtExpr(expr clause.Expression) clause.Expression
LtExpr creates a less than comparison expression (field < expression).
func (String) Lte ¶
func (s String) Lte(value string) clause.Expression
Lte creates a less than or equal comparison expression (field <= value).
func (String) LteExpr ¶
func (s String) LteExpr(expr clause.Expression) clause.Expression
LteExpr creates a less than or equal comparison expression (field <= expression).
func (String) Neq ¶
func (s String) Neq(value string) clause.Expression
Neq creates a not equal comparison expression (field != value).
func (String) NeqExpr ¶
func (s String) NeqExpr(expr clause.Expression) clause.Expression
NeqExpr creates a not equal comparison expression (field != expression).
func (String) NotILike ¶
func (s String) NotILike(pattern string) clause.Expression
NotILike creates a case-insensitive NOT LIKE pattern matching expression (field NOT ILIKE pattern).
func (String) NotIn ¶
func (s String) NotIn(values ...string) clause.Expression
NotIn creates a NOT IN comparison expression (field NOT IN (values...)).
func (String) NotLike ¶
func (s String) NotLike(pattern string) clause.Expression
NotLike creates a NOT LIKE pattern matching expression (field NOT LIKE pattern).
func (String) NotRegexp ¶
func (s String) NotRegexp(pattern string) clause.Expression
NotRegexp creates a regular expression not matching expression (field NOT REGEXP pattern).
func (String) OrderExpr ¶
func (s String) OrderExpr(expr string, values ...any) clause.Expression
OrderExpr creates a custom ORDER BY expression with parameters.
func (String) Regexp ¶
func (s String) Regexp(pattern string) clause.Expression
Regexp creates a regular expression matching expression (field REGEXP pattern).
func (String) Right ¶
func (s String) Right(length int) AssignerExpression
Right creates a right substring expression.
func (String) SelectExpr ¶
func (s String) SelectExpr(sql string, values ...any) Selectable
SelectExpr wraps a custom expression built from this field for Select(...)
func (String) Set ¶
func (s String) Set(val string) clause.Assignment
Set creates an assignment expression for UPDATE operations (field = value).
func (String) SetExpr ¶
func (s String) SetExpr(expr clause.Expression) clause.Assignment
SetExpr creates an assignment expression for UPDATE operations (field = expression).
func (String) Substring ¶
func (s String) Substring(start, length int) AssignerExpression
Substring creates a substring expression.
func (String) Trim ¶
func (s String) Trim() AssignerExpression
Trim creates a whitespace trimming expression.
func (String) Upper ¶
func (s String) Upper() AssignerExpression
Upper creates an uppercase conversion expression.
func (String) WithColumn ¶
WithColumn creates a new String field with the specified column name. This method allows you to change the column name while keeping other properties.
Example:
name := field.String{column: clause.Column{Name: "user_name"}}
fullName := name.WithColumn("full_name")
type Struct ¶
type Struct[T any] struct { // contains filtered or unexported fields }
Struct represents a struct field for single association operations
func (Struct[T]) Create ¶
func (s Struct[T]) Create(assignments ...clause.Assignment) clause.Association
Create prepares an association create operation for a single (has one/belongs to) association. Use with Set(...).Update(ctx) to create and associate a record per matched parent.
func (Struct) Delete ¶
func (w Struct) Delete() clause.Association
Delete removes records from the associated table Delete prepares an association delete operation. Use with Set(...).Update(ctx) to delete matched associated records for matched parents.
func (Struct) Unlink ¶
func (w Struct) Unlink() clause.Association
Unlink removes the association without deleting associated records. Unlink semantics: - belongs to: sets the parent's foreign key to NULL - has one / has many: sets the child's foreign key to NULL - many2many: removes join table rows only Use with Set(...).Update(ctx).
func (Struct) Update ¶
func (w Struct) Update(assignments ...clause.Assignment) clause.Association
Update updates records in the associated table Update prepares an association update operation with optional conditions. Use with Set(...).Update(ctx) to update matched associated records for matched parents.
func (Struct[T]) Where ¶
func (s Struct[T]) Where(conditions ...clause.Expression) associationWithConditions[T]
Where adds conditions to a Struct field
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time represents a time field that provides type-safe operations for building SQL queries.
func (Time) Add ¶
func (t Time) Add(duration time.Duration) AssignerExpression
Add creates a date addition expression (DATE_ADD(field, INTERVAL seconds SECOND)).
func (Time) As ¶
func (t Time) As(alias string) Selectable
As creates an alias for this column usable in Select(...)
func (Time) Asc ¶
func (t Time) Asc() clause.OrderByColumn
Asc creates an ascending order expression for ORDER BY clauses.
func (Time) Between ¶
func (t Time) Between(v1, v2 time.Time) clause.Expression
Between creates a range comparison expression (field BETWEEN v1 AND v2).
func (Time) Date ¶
func (t Time) Date() clause.Expression
Date extracts the date part from a datetime field.
func (Time) DateDiff ¶
func (t Time) DateDiff(date time.Time) clause.Expression
DateDiff creates a date difference expression (DATEDIFF(field, date)).
func (Time) DateFormat ¶
func (t Time) DateFormat(format string) clause.Expression
DateFormat creates a date formatting expression (DATE_FORMAT(field, format)).
func (Time) Desc ¶
func (t Time) Desc() clause.OrderByColumn
Desc creates a descending order expression for ORDER BY clauses.
func (Time) Eq ¶
func (t Time) Eq(value time.Time) clause.Expression
Eq creates an equality comparison expression (field = value).
func (Time) EqExpr ¶
func (t Time) EqExpr(expr clause.Expression) clause.Expression
EqExpr creates an equality comparison expression (field = expression).
func (Time) Expr ¶
func (t Time) Expr(expr string, values ...any) clause.Expression
Expr creates a custom SQL expression with parameters.
func (Time) Gt ¶
func (t Time) Gt(value time.Time) clause.Expression
Gt creates a greater than comparison expression (field > value).
func (Time) GtExpr ¶
func (t Time) GtExpr(expr clause.Expression) clause.Expression
GtExpr creates a greater than comparison expression (field > expression).
func (Time) Gte ¶
func (t Time) Gte(value time.Time) clause.Expression
Gte creates a greater than or equal comparison expression (field >= value).
func (Time) GteExpr ¶
func (t Time) GteExpr(expr clause.Expression) clause.Expression
GteExpr creates a greater than or equal comparison expression (field >= expression).
func (Time) Hour ¶
func (t Time) Hour() clause.Expression
Hour extracts the hour from the datetime field.
func (Time) In ¶
func (t Time) In(values ...time.Time) clause.Expression
In creates an IN comparison expression (field IN (values...)).
func (Time) IsNotNull ¶
func (t Time) IsNotNull() clause.Expression
IsNotNull creates a NOT NULL check expression (field IS NOT NULL).
func (Time) IsNull ¶
func (t Time) IsNull() clause.Expression
IsNull creates a NULL check expression (field IS NULL).
func (Time) Lt ¶
func (t Time) Lt(value time.Time) clause.Expression
Lt creates a less than comparison expression (field < value).
func (Time) LtExpr ¶
func (t Time) LtExpr(expr clause.Expression) clause.Expression
LtExpr creates a less than comparison expression (field < expression).
func (Time) Lte ¶
func (t Time) Lte(value time.Time) clause.Expression
Lte creates a less than or equal comparison expression (field <= value).
func (Time) LteExpr ¶
func (t Time) LteExpr(expr clause.Expression) clause.Expression
LteExpr creates a less than or equal comparison expression (field <= expression).
func (Time) Minute ¶
func (t Time) Minute() clause.Expression
Minute extracts the minute from the datetime field.
func (Time) Month ¶
func (t Time) Month() clause.Expression
Month extracts the month from the date field.
func (Time) Neq ¶
func (t Time) Neq(value time.Time) clause.Expression
Neq creates a not equal comparison expression (field != value).
func (Time) NeqExpr ¶
func (t Time) NeqExpr(expr clause.Expression) clause.Expression
NeqExpr creates a not equal comparison expression (field != expression).
func (Time) NotIn ¶
func (t Time) NotIn(values ...time.Time) clause.Expression
NotIn creates a NOT IN comparison expression (field NOT IN (values...)).
func (Time) Now ¶
func (t Time) Now() AssignerExpression
Now creates a NOW() expression for current timestamp.
func (Time) OrderExpr ¶
func (t Time) OrderExpr(expr string, values ...any) clause.Expression
OrderExpr creates a custom ORDER BY expression with parameters.
func (Time) Second ¶
func (t Time) Second() clause.Expression
Second extracts the second from the datetime field.
func (Time) SelectExpr ¶
func (t Time) SelectExpr(sql string, values ...any) Selectable
SelectExpr wraps a custom expression built from this field for Select(...)
func (Time) Set ¶
func (t Time) Set(val time.Time) clause.Assignment
Set creates an assignment expression for UPDATE operations (field = value).
func (Time) SetExpr ¶
func (t Time) SetExpr(expr clause.Expression) clause.Assignment
SetExpr creates an assignment expression for UPDATE operations (field = expression).
func (Time) Sub ¶
func (t Time) Sub(duration time.Duration) AssignerExpression
Sub creates a date subtraction expression (DATE_SUB(field, INTERVAL seconds SECOND)).
func (Time) Time ¶
func (t Time) Time() clause.Expression
Time extracts the time part from a datetime field.
func (Time) Unix ¶
func (t Time) Unix() clause.Expression
Unix converts the datetime to Unix timestamp.
func (Time) WithColumn ¶
WithColumn creates a new Time field with the specified column name. This method allows you to change the column name while keeping other properties.
Example:
createdAt := field.Time{column: clause.Column{Name: "created_at"}}
updatedAt := createdAt.WithColumn("updated_at")
func (Time) WithTable ¶
WithTable creates a new Time field with the specified table name. This method is useful when working with joins and you need to qualify the column with a table name.
Example:
createdAt := field.Time{column: clause.Column{Name: "created_at"}}
userCreatedAt := createdAt.WithTable("users")
func (Time) Year ¶
func (t Time) Year() clause.Expression
Year extracts the year from the date field.