field

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 3 Imported by: 0

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

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

func (b Bool) Column() clause.Column

Column returns the underlying column for this field

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

func (b Bool) WithColumn(name string) Bool

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

func (b Bool) WithTable(name string) Bool

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

func (b Bytes) Column() clause.Column

Column returns the underlying column for this field

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

func (b Bytes) WithColumn(name string) Bytes

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

func (b Bytes) WithTable(name string) Bytes

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

type ColumnInterface interface {
	Column() clause.Column
}

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]) Column

func (f Field[T]) Column() clause.Column

Column returns the underlying clause.Column for selection and grouping.

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

func (f Field[T]) WithColumn(name string) Field[T]

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

func (f Field[T]) WithTable(name string) Field[T]

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]) Column

func (n Number[T]) Column() clause.Column

Column returns the underlying column for this field

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

func (n Number[T]) WithColumn(name string) Number[T]

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

func (n Number[T]) WithTable(name string) Number[T]

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

type OrderableInterface interface {
	Build(clause.Builder)
}

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[T]) Name

func (s Slice[T]) Name() string

Name returns the association name (field name on the parent model)

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

func (Slice[T]) WithName

func (s Slice[T]) WithName(name string) Slice[T]

WithName creates a new Slice with the specified field name

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

func (s String) Column() clause.Column

Column returns the underlying column for this field

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

func (s String) WithColumn(name string) String

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

func (String) WithTable

func (s String) WithTable(name string) String

WithTable creates a new String 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:

name := field.String{column: clause.Column{Name: "name"}}
userName := name.WithTable("users")

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[T]) Name

func (s Struct[T]) Name() string

Name returns the association name (field name on the parent model)

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

func (Struct[T]) WithName

func (s Struct[T]) WithName(name string) Struct[T]

WithName creates a new Struct with the specified field name

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

func (t Time) Column() clause.Column

Column returns the underlying column for this field

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

func (t Time) Day() clause.Expression

Day extracts the day from the date field.

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

func (t Time) WithColumn(name string) Time

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

func (t Time) WithTable(name string) Time

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.

Jump to

Keyboard shortcuts

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