condition

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MPL-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const UndefinedJoinNumber = -1

Variables

View Source
var (
	// query
	ErrFieldModelNotConcerned = errors.New("field's model is not concerned by the query (not joined)")
	ErrJoinMustBeSelected     = errors.New("field's model is joined more than once, select which one you want to use")

	// conditions
	ErrEmptyConditions     = errors.New("condition must have at least one inner condition")
	ErrOnlyPreloadsAllowed = errors.New("only conditions that do a preload are allowed")

	// crud
	ErrMoreThanOneObjectFound = errors.New("found more that one object that meet the requested conditions")
	ErrObjectNotFound         = errors.New("no object exists that meets the requested conditions")

	ErrUnsupportedByDatabase = errors.New("method not supported by database")
	ErrOrderByMustBeCalled   = errors.New("order by must be called before limit in an update statement")
)

Functions

func ApplyWhereCondition

func ApplyWhereCondition[T model.Model](condition WhereCondition[T], query *GormQuery, table Table) error

apply WhereCondition of any type on the query

func GetJoinNumber

func GetJoinNumber(joinNumberList []uint) int

from a list of uint, return the first or UndefinedJoinNumber in case the list is empty

Types

type BoolField

type BoolField[TModel model.Model] struct {
	Field[TModel, bool]
}

func (BoolField[TModel]) Is

func (boolField BoolField[TModel]) Is() BoolFieldIs[TModel]

type BoolFieldIs

type BoolFieldIs[TObject model.Model] struct {
	Field Field[TObject, bool]
}

func (BoolFieldIs[TObject]) False

func (is BoolFieldIs[TObject]) False() WhereCondition[TObject]

func (BoolFieldIs[TObject]) NotFalse

func (is BoolFieldIs[TObject]) NotFalse() WhereCondition[TObject]

func (BoolFieldIs[TObject]) NotTrue

func (is BoolFieldIs[TObject]) NotTrue() WhereCondition[TObject]

func (BoolFieldIs[TObject]) NotUnknown

func (is BoolFieldIs[TObject]) NotUnknown() WhereCondition[TObject]

func (BoolFieldIs[TObject]) True

func (is BoolFieldIs[TObject]) True() WhereCondition[TObject]

func (BoolFieldIs[TObject]) Unknown

func (is BoolFieldIs[TObject]) Unknown() WhereCondition[TObject]

type Condition

type Condition[T model.Model] interface {
	// Applies the condition to the "query"
	// using the table holding
	// the data for object of type T
	ApplyTo(query *GormQuery, table Table) error

	// This method is necessary to get the compiler to verify
	// that an object is of type Condition[T],
	// since if no method receives by parameter a type T,
	// any other Condition[T2] would also be considered a Condition[T].
	InterfaceVerificationMethod(t T)
}

func NewCollectionPreloadCondition

func NewCollectionPreloadCondition[T1, T2 model.Model](
	collectionField string,
	nestedPreloads []JoinCondition[T2],
) Condition[T1]

Condition used to the preload a collection of models of a model

func NewPreloadCondition

func NewPreloadCondition[T model.Model](fields ...IField) Condition[T]

Condition used to the preload the attributes of a model

type Delete

type Delete[T model.Model] struct {
	OrderLimitReturning[T]
}

func NewDelete

func NewDelete[T model.Model](tx *gorm.DB, conditions ...Condition[T]) *Delete[T]

Create a Delete to which the conditions are applied inside transaction tx

func (*Delete[T]) Ascending

func (deleteS *Delete[T]) Ascending(field IField, joinNumber ...uint) *Delete[T]

Ascending specify an ascending order when updating models

joinNumber can be used to select the join in case the field is joined more than once

available for: mysql

func (*Delete[T]) Descending

func (deleteS *Delete[T]) Descending(field IField, joinNumber ...uint) *Delete[T]

Descending specify a descending order when updating models

joinNumber can be used to select the join in case the field is joined more than once

available for: mysql

func (*Delete[T]) Exec

func (deleteS *Delete[T]) Exec() (int64, error)

func (*Delete[T]) Limit

func (deleteS *Delete[T]) Limit(limit int) *Delete[T]

Limit specify the number of models to be updated

Limit conditions can be cancelled by using `Limit(-1)`

available for: mysql

func (*Delete[T]) Returning

func (deleteS *Delete[T]) Returning(dest *[]T) *Delete[T]

available for: postgres, sqlite, sqlserver

warning: in sqlite preloads are not allowed

type Dialector

type Dialector string
const (
	Postgres  Dialector = "postgres"
	MySQL     Dialector = "mysql"
	SQLite    Dialector = "sqlite"
	SQLServer Dialector = "sqlserver"
)

type DynamicCondition

type DynamicCondition[T model.Model] interface {
	WhereCondition[T]

	// Allows to choose which number of join use
	// for the operation in position "operationNumber"
	// when the value is a field and its model is joined more than once.
	// Does nothing if the operationNumber is bigger than the amount of operations.
	SelectJoin(operationNumber, joinNumber uint) DynamicCondition[T]
}

func NewFieldCondition

func NewFieldCondition[TObject model.Model, TAttribute any](
	fieldIdentifier Field[TObject, TAttribute],
	operator Operator[TAttribute],
) DynamicCondition[TObject]

type DynamicFieldIs

type DynamicFieldIs[TObject model.Model, TAttribute any] struct {
	// contains filtered or unexported fields
}

func (DynamicFieldIs[TObject, TAttribute]) Between

func (is DynamicFieldIs[TObject, TAttribute]) Between(field1, field2 FieldOfType[TAttribute]) DynamicCondition[TObject]

Equivalent to field1 < value < field2

func (DynamicFieldIs[TObject, TAttribute]) Distinct

func (is DynamicFieldIs[TObject, TAttribute]) Distinct(field FieldOfType[TAttribute]) DynamicCondition[TObject]

func (DynamicFieldIs[TObject, TAttribute]) Eq

func (is DynamicFieldIs[TObject, TAttribute]) Eq(field FieldOfType[TAttribute]) DynamicCondition[TObject]

EqualTo

func (DynamicFieldIs[TObject, TAttribute]) Gt

func (is DynamicFieldIs[TObject, TAttribute]) Gt(field FieldOfType[TAttribute]) DynamicCondition[TObject]

GreaterThan

func (DynamicFieldIs[TObject, TAttribute]) GtOrEq

func (is DynamicFieldIs[TObject, TAttribute]) GtOrEq(field FieldOfType[TAttribute]) DynamicCondition[TObject]

GreaterThanOrEqualTo

func (DynamicFieldIs[TObject, TAttribute]) Lt

func (is DynamicFieldIs[TObject, TAttribute]) Lt(field FieldOfType[TAttribute]) DynamicCondition[TObject]

LessThan

func (DynamicFieldIs[TObject, TAttribute]) LtOrEq

func (is DynamicFieldIs[TObject, TAttribute]) LtOrEq(field FieldOfType[TAttribute]) DynamicCondition[TObject]

LessThanOrEqualTo

func (DynamicFieldIs[TObject, TAttribute]) NotBetween

func (is DynamicFieldIs[TObject, TAttribute]) NotBetween(field1, field2 FieldOfType[TAttribute]) DynamicCondition[TObject]

Equivalent to NOT (field1 < value < field2)

func (DynamicFieldIs[TObject, TAttribute]) NotDistinct

func (is DynamicFieldIs[TObject, TAttribute]) NotDistinct(field FieldOfType[TAttribute]) DynamicCondition[TObject]

func (DynamicFieldIs[TObject, TAttribute]) NotEq

func (is DynamicFieldIs[TObject, TAttribute]) NotEq(field FieldOfType[TAttribute]) DynamicCondition[TObject]

NotEqualTo

type DynamicOperator

type DynamicOperator[T any] interface {
	Operator[T]

	// Allows to choose which number of join use
	// for the value in position "valueNumber"
	// when the value is a field and its model is joined more than once.
	// Does nothing if the valueNumber is bigger than the amount of values.
	SelectJoin(valueNumber, joinNumber uint) DynamicOperator[T]
}

type Field

type Field[TModel model.Model, TAttribute any] struct {
	Column       string
	Name         string
	ColumnPrefix string
}

func (Field[TModel, TAttribute]) ColumnName

func (field Field[TModel, TAttribute]) ColumnName(query *GormQuery, table Table) string

Returns the name of the column in which the field is saved in the table

func (Field[TModel, TAttribute]) ColumnSQL

func (field Field[TModel, TAttribute]) ColumnSQL(query *GormQuery, table Table) string

Returns the SQL to get the value of the field in the table

func (Field[TModel, TAttribute]) FieldName

func (field Field[TModel, TAttribute]) FieldName() string

Returns the name of the field identified

func (Field[TModel, TAttribute]) GetModelType

func (field Field[TModel, TAttribute]) GetModelType() reflect.Type

func (Field[TModel, TAttribute]) GetType

func (field Field[TModel, TAttribute]) GetType() TAttribute

func (Field[TModel, TAttribute]) Is

func (field Field[TModel, TAttribute]) Is() FieldIs[TModel, TAttribute]

func (Field[TModel, TAttribute]) Set

func (field Field[TModel, TAttribute]) Set() FieldSet[TModel, TAttribute]

type FieldIs

type FieldIs[TObject model.Model, TAttribute any] struct {
	Field Field[TObject, TAttribute]
}

func (FieldIs[TObject, TAttribute]) Between

func (is FieldIs[TObject, TAttribute]) Between(v1, v2 TAttribute) WhereCondition[TObject]

Equivalent to v1 < value < v2

func (FieldIs[TObject, TAttribute]) Custom

func (is FieldIs[TObject, TAttribute]) Custom(op Operator[TAttribute]) WhereCondition[TObject]

Custom can be used to use other Operators, like database specific operators

func (FieldIs[TObject, TAttribute]) Distinct

func (is FieldIs[TObject, TAttribute]) Distinct(value TAttribute) WhereCondition[TObject]

func (FieldIs[TObject, TAttribute]) Dynamic

func (is FieldIs[TObject, TAttribute]) Dynamic() DynamicFieldIs[TObject, TAttribute]

Dynamic transforms the FieldIs in a DynamicFieldIs to use dynamic operators

func (FieldIs[TObject, TAttribute]) Eq

func (is FieldIs[TObject, TAttribute]) Eq(value TAttribute) WhereCondition[TObject]

EqualTo NotDistinct must be used in cases where value can be NULL

func (FieldIs[TObject, TAttribute]) Gt

func (is FieldIs[TObject, TAttribute]) Gt(value TAttribute) WhereCondition[TObject]

GreaterThan

func (FieldIs[TObject, TAttribute]) GtOrEq

func (is FieldIs[TObject, TAttribute]) GtOrEq(value TAttribute) WhereCondition[TObject]

GreaterThanOrEqualTo

func (FieldIs[TObject, TAttribute]) In

func (is FieldIs[TObject, TAttribute]) In(values ...TAttribute) WhereCondition[TObject]

func (FieldIs[TObject, TAttribute]) Lt

func (is FieldIs[TObject, TAttribute]) Lt(value TAttribute) WhereCondition[TObject]

LessThan

func (FieldIs[TObject, TAttribute]) LtOrEq

func (is FieldIs[TObject, TAttribute]) LtOrEq(value TAttribute) WhereCondition[TObject]

LessThanOrEqualTo

func (FieldIs[TObject, TAttribute]) NotBetween

func (is FieldIs[TObject, TAttribute]) NotBetween(v1, v2 TAttribute) WhereCondition[TObject]

Equivalent to NOT (v1 < value < v2)

func (FieldIs[TObject, TAttribute]) NotDistinct

func (is FieldIs[TObject, TAttribute]) NotDistinct(value TAttribute) WhereCondition[TObject]

func (FieldIs[TObject, TAttribute]) NotEq

func (is FieldIs[TObject, TAttribute]) NotEq(value TAttribute) WhereCondition[TObject]

NotEqualTo Distinct must be used in cases where value can be NULL

func (FieldIs[TObject, TAttribute]) NotIn

func (is FieldIs[TObject, TAttribute]) NotIn(values ...TAttribute) WhereCondition[TObject]

func (FieldIs[TObject, TAttribute]) NotNull

func (is FieldIs[TObject, TAttribute]) NotNull() WhereCondition[TObject]

func (FieldIs[TObject, TAttribute]) Null

func (is FieldIs[TObject, TAttribute]) Null() WhereCondition[TObject]

func (FieldIs[TObject, TAttribute]) Unsafe

func (is FieldIs[TObject, TAttribute]) Unsafe() UnsafeFieldIs[TObject, TAttribute]

Unsafe transforms the FieldIs in an UnsafeFieldIs to use unsafe operators

type FieldOfType

type FieldOfType[T any] interface {
	IField
	GetType() T
}

type FieldSet

type FieldSet[TModel model.Model, TAttribute any] struct {
	Field Field[TModel, TAttribute]
}

TODO ver donde pongo esto TODO nombre muy parecido

func (FieldSet[TModel, TAttribute]) Dynamic

func (set FieldSet[TModel, TAttribute]) Dynamic(field FieldOfType[TAttribute], joinNumber ...uint) *Set[TModel]

joinNumber can be used to select the join in case the field is joined more than once

func (FieldSet[TModel, TAttribute]) Eq

func (set FieldSet[TModel, TAttribute]) Eq(value TAttribute) *Set[TModel]

func (FieldSet[TModel, TAttribute]) Unsafe

func (set FieldSet[TModel, TAttribute]) Unsafe(value any) *Set[TModel]

type GormQuery

type GormQuery struct {
	GormDB          *gorm.DB
	ConcernedModels map[reflect.Type][]Table
	// contains filtered or unexported fields
}

func ApplyConditions

func ApplyConditions[T model.Model](db *gorm.DB, conditions []Condition[T]) (*GormQuery, error)

Create a GormQuery to which the conditions are applied

func NewGormQuery

func NewGormQuery(db *gorm.DB, initialModel model.Model, initialTable Table) *GormQuery

func (*GormQuery) AddConcernedModel

func (query *GormQuery) AddConcernedModel(model model.Model, table Table)

func (*GormQuery) AddSelect

func (query *GormQuery) AddSelect(table Table, fieldID IField)

func (GormQuery) ColumnName

func (query GormQuery) ColumnName(table Table, fieldName string) string

func (*GormQuery) Delete

func (query *GormQuery) Delete() (int64, error)

func (GormQuery) Dialector

func (query GormQuery) Dialector() Dialector

func (*GormQuery) Find

func (query *GormQuery) Find(dest any) error

Find finds all models matching given conditions

func (*GormQuery) First

func (query *GormQuery) First(dest any) error

First finds the first record ordered by primary key, matching given conditions

func (*GormQuery) GetModelTable

func (query *GormQuery) GetModelTable(field IField, joinNumber int) (Table, error)

func (*GormQuery) GetTables

func (query *GormQuery) GetTables(modelType reflect.Type) []Table

func (*GormQuery) Joins

func (query *GormQuery) Joins(joinQuery string, isLeftJoin bool, args ...interface{})

func (*GormQuery) Last

func (query *GormQuery) Last(dest any) error

Last finds the last record ordered by primary key, matching given conditions

func (*GormQuery) Limit

func (query *GormQuery) Limit(limit int)

Limit specify the number of records to be retrieved

Limit conditions can be cancelled by using `Limit(-1)`

func (*GormQuery) Offset

func (query *GormQuery) Offset(offset int)

Offset specify the number of records to skip before starting to return the records

Offset conditions can be cancelled by using `Offset(-1)`.

func (*GormQuery) Order

func (query *GormQuery) Order(field IField, descending bool, joinNumber int) error

Order specify order when retrieving models from database.

if descending is true, the ordering is in descending direction.

joinNumber can be used to select the join in case the field is joined more than once.

func (*GormQuery) Preload

func (query *GormQuery) Preload(preloadQuery string, args ...interface{})

func (*GormQuery) Returning

func (query *GormQuery) Returning(dest any) error

available for: postgres, sqlite, sqlserver

warning: in sqlite, sqlserver preloads are not allowed

func (*GormQuery) Take

func (query *GormQuery) Take(dest any) error

Take finds the first record returned by the database in no specified order, matching given conditions

func (*GormQuery) Unscoped

func (query *GormQuery) Unscoped()

func (*GormQuery) Update

func (query *GormQuery) Update(sets []ISet) (int64, error)

Find finds all models matching given conditions

func (*GormQuery) Where

func (query *GormQuery) Where(whereQuery interface{}, args ...interface{})

type IField

type IField interface {
	// TODO ver si de todos estos podria sacar alguno
	ColumnName(query *GormQuery, table Table) string
	FieldName() string
	ColumnSQL(query *GormQuery, table Table) string
	GetModelType() reflect.Type
}

type ISet

type ISet interface {
	Field() IField
	Value() any
	JoinNumber() int
}

TODO mover todo esto

type JoinCondition

type JoinCondition[T model.Model] interface {
	Condition[T]
	// contains filtered or unexported methods
}

Condition that joins T with any other model

func NewJoinCondition

func NewJoinCondition[T1, T2 model.Model](
	conditions []Condition[T2],
	relationField string,
	t1Field string,
	t1PreloadCondition Condition[T1],
	t2Field string,
) JoinCondition[T1]

Condition that joins T with any other model

type LikeOperator

type LikeOperator struct {
	ValueOperator[string]
}

func Like

func Like(pattern string) LikeOperator

Pattern in all databases:

  • An underscore (_) in pattern stands for (matches) any single character.
  • A percent sign (%) matches any sequence of zero or more characters.

Additionally in SQLServer:

  • Square brackets ([ ]) matches any single character within the specified range ([a-f]) or set ([abcdef]).
  • [^] matches any single character not within the specified range ([^a-f]) or set ([^abcdef]).

WARNINGS:

  • SQLite: LIKE is case-insensitive unless case_sensitive_like pragma (https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) is true.
  • SQLServer, MySQL: the case-sensitivity depends on the collation used in compared column.
  • PostgreSQL: LIKE is always case-sensitive, if you want case-insensitive use the ILIKE operator (implemented in psql.ILike)

refs:

func NewLikeOperator

func NewLikeOperator(sqlOperator sql.Operator, pattern string) LikeOperator

func (LikeOperator) Escape

func (operator LikeOperator) Escape(escape rune) ValueOperator[string]

type Operator

type Operator[T any] interface {
	// Transform the Operator to a SQL string and a list of values to use in the query
	// columnName is used by the operator to determine which is the objective column.
	ToSQL(query *GormQuery, columnName string) (string, []any, error)

	// This method is necessary to get the compiler to verify
	// that an object is of type Operator[T],
	// since if no method receives by parameter a type T,
	// any other Operator[T2] would also be considered a Operator[T].
	InterfaceVerificationMethod(t T)
}

func Between

func Between[T any](v1, v2 any) Operator[T]

Equivalent to v1 < value < v2

func Eq

func Eq[T any](value any) Operator[T]

EqualTo IsNotDistinct must be used in cases where value can be NULL

func Gt

func Gt[T any](value any) Operator[T]

GreaterThan

func GtOrEq

func GtOrEq[T any](value any) Operator[T]

GreaterThanOrEqualTo

func In

func In[T any](values []T) Operator[T]

func IsDistinct

func IsDistinct[T any](value any) Operator[T]

func IsNotDistinct

func IsNotDistinct[T any](value any) Operator[T]

func IsNotNull

func IsNotNull[T any]() Operator[T]

func IsNull

func IsNull[T any]() Operator[T]

func Lt

func Lt[T any](value any) Operator[T]

LessThan

func LtOrEq

func LtOrEq[T any](value any) Operator[T]

LessThanOrEqualTo

func NotBetween

func NotBetween[T any](v1, v2 any) Operator[T]

Equivalent to NOT (v1 < value < v2)

func NotEq

func NotEq[T any](value any) Operator[T]

NotEqualTo IsDistinct must be used in cases where value can be NULL

func NotIn

func NotIn[T any](values []T) Operator[T]

type OrderLimitReturning

type OrderLimitReturning[T model.Model] struct {
	// contains filtered or unexported fields
}

func (*OrderLimitReturning[T]) Ascending

func (olr *OrderLimitReturning[T]) Ascending(field IField, joinNumber ...uint)

Ascending specify an ascending order when updating models

joinNumber can be used to select the join in case the field is joined more than once

available for: mysql

func (*OrderLimitReturning[T]) Descending

func (olr *OrderLimitReturning[T]) Descending(field IField, joinNumber ...uint)

Descending specify a descending order when updating models

joinNumber can be used to select the join in case the field is joined more than once

available for: mysql

func (*OrderLimitReturning[T]) Limit

func (olr *OrderLimitReturning[T]) Limit(limit int)

Limit specify the number of models to be updated

Limit conditions can be cancelled by using `Limit(-1)`

available for: mysql

func (OrderLimitReturning[T]) Returning

func (olr OrderLimitReturning[T]) Returning(dest *[]T)

available for: postgres, sqlite, sqlserver

warning: in sqlite preloads are not allowed

type PredicateOperator

type PredicateOperator[T any] struct {
	SQLOperator string
}

Operator that verifies a predicate Example: value IS TRUE

func NewPredicateOperator

func NewPredicateOperator[T any](sqlOperator string) PredicateOperator[T]

func (PredicateOperator[T]) InterfaceVerificationMethod

func (operator PredicateOperator[T]) InterfaceVerificationMethod(_ T)

func (PredicateOperator[T]) ToSQL

func (operator PredicateOperator[T]) ToSQL(_ *GormQuery, columnName string) (string, []any, error)

type Query

type Query[T model.Model] struct {
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery[T model.Model](tx *gorm.DB, conditions ...Condition[T]) *Query[T]

Create a Query to which the conditions are applied inside transaction tx

func (*Query[T]) Ascending

func (query *Query[T]) Ascending(field IField, joinNumber ...uint) *Query[T]

Ascending specify an ascending order when retrieving models from database joinNumber can be used to select the join in case the field is joined more than once

func (*Query[T]) Descending

func (query *Query[T]) Descending(field IField, joinNumber ...uint) *Query[T]

Descending specify a descending order when retrieving models from database joinNumber can be used to select the join in case the field is joined more than once

func (*Query[T]) Find

func (query *Query[T]) Find() ([]*T, error)

Find finds all models matching given conditions

func (*Query[T]) FindOne

func (query *Query[T]) FindOne() (*T, error)

FindOne finds the only one model that matches given conditions or returns error if 0 or more than 1 are found.

func (*Query[T]) First

func (query *Query[T]) First() (*T, error)

First finds the first model ordered by primary key, matching given conditions or returns gorm.ErrRecordNotFound is if no model does it

func (*Query[T]) Last

func (query *Query[T]) Last() (*T, error)

Last finds the last model ordered by primary key, matching given conditions or returns gorm.ErrRecordNotFound is if no model does it

func (*Query[T]) Limit

func (query *Query[T]) Limit(limit int) *Query[T]

Limit specify the number of models to be retrieved

Limit conditions can be cancelled by using `Limit(-1)`

func (*Query[T]) Offset

func (query *Query[T]) Offset(offset int) *Query[T]

Offset specify the number of models to skip before starting to return the results

Offset conditions can be cancelled by using `Offset(-1)`

Warning: in MySQL Offset can only be used if Limit is also used

func (*Query[T]) Take

func (query *Query[T]) Take() (*T, error)

Take finds the first model returned by the database in no specified order, matching given conditions or returns gorm.ErrRecordNotFound is if no model does it

type Set

type Set[T model.Model] struct {
	// contains filtered or unexported fields
}

TODO ver donde pongo esto

func (Set[T]) Field

func (set Set[T]) Field() IField

func (Set[T]) JoinNumber

func (set Set[T]) JoinNumber() int

func (Set[T]) Value

func (set Set[T]) Value() any

type StringField

type StringField[TModel model.Model] struct {
	Field[TModel, string]
}

func (StringField[TModel]) Is

func (stringField StringField[TModel]) Is() StringFieldIs[TModel]

type StringFieldIs

type StringFieldIs[TObject model.Model] struct {
	FieldIs[TObject, string]
}

func (StringFieldIs[TObject]) Like

func (is StringFieldIs[TObject]) Like(pattern string) WhereCondition[TObject]

Pattern in all databases:

  • An underscore (_) in pattern stands for (matches) any single character.
  • A percent sign (%) matches any sequence of zero or more characters.

Additionally in SQLServer:

  • Square brackets ([ ]) matches any single character within the specified range ([a-f]) or set ([abcdef]).
  • [^] matches any single character not within the specified range ([^a-f]) or set ([^abcdef]).

WARNINGS:

  • SQLite: LIKE is case-insensitive unless case_sensitive_like pragma (https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) is true.
  • SQLServer, MySQL: the case-sensitivity depends on the collation used in compared column.
  • PostgreSQL: LIKE is always case-sensitive, if you want case-insensitive use the ILIKE operator (implemented in psql.ILike)

refs:

type Table

type Table struct {
	Name    string
	Alias   string
	Initial bool
}

func NewTable

func NewTable(db *gorm.DB, model model.Model) (Table, error)

func (Table) DeliverTable

func (t Table) DeliverTable(query *GormQuery, model model.Model, relationName string) (Table, error)

Returns the related Table corresponding to the model

func (Table) IsInitial

func (t Table) IsInitial() bool

Returns true if the Table is the initial table in a query

func (Table) SQLName

func (t Table) SQLName() string

SQLName returns the name that must be used in a sql query to use this table: the alias if not empty or the table name

type TableAndValue

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

type UnsafeFieldIs

type UnsafeFieldIs[TObject model.Model, TAttribute any] struct {
	// contains filtered or unexported fields
}

func (UnsafeFieldIs[TObject, TAttribute]) Between

func (is UnsafeFieldIs[TObject, TAttribute]) Between(v1, v2 any) DynamicCondition[TObject]

Equivalent to field1 < value < field2

func (UnsafeFieldIs[TObject, TAttribute]) Distinct

func (is UnsafeFieldIs[TObject, TAttribute]) Distinct(value any) DynamicCondition[TObject]

func (UnsafeFieldIs[TObject, TAttribute]) Eq

func (is UnsafeFieldIs[TObject, TAttribute]) Eq(value any) DynamicCondition[TObject]

EqualTo

func (UnsafeFieldIs[TObject, TAttribute]) Gt

func (is UnsafeFieldIs[TObject, TAttribute]) Gt(value any) DynamicCondition[TObject]

GreaterThan

func (UnsafeFieldIs[TObject, TAttribute]) GtOrEq

func (is UnsafeFieldIs[TObject, TAttribute]) GtOrEq(value any) DynamicCondition[TObject]

GreaterThanOrEqualTo

func (UnsafeFieldIs[TObject, TAttribute]) Lt

func (is UnsafeFieldIs[TObject, TAttribute]) Lt(value any) DynamicCondition[TObject]

LessThan

func (UnsafeFieldIs[TObject, TAttribute]) LtOrEq

func (is UnsafeFieldIs[TObject, TAttribute]) LtOrEq(value any) DynamicCondition[TObject]

LessThanOrEqualTo

func (UnsafeFieldIs[TObject, TAttribute]) NotBetween

func (is UnsafeFieldIs[TObject, TAttribute]) NotBetween(v1, v2 any) DynamicCondition[TObject]

Equivalent to NOT (field1 < value < field2)

func (UnsafeFieldIs[TObject, TAttribute]) NotDistinct

func (is UnsafeFieldIs[TObject, TAttribute]) NotDistinct(value any) DynamicCondition[TObject]

func (UnsafeFieldIs[TObject, TAttribute]) NotEq

func (is UnsafeFieldIs[TObject, TAttribute]) NotEq(value any) DynamicCondition[TObject]

NotEqualTo

type Update

type Update[T model.Model] struct {
	OrderLimitReturning[T]
}

func NewUpdate

func NewUpdate[T model.Model](tx *gorm.DB, conditions ...Condition[T]) *Update[T]

Create a Update to which the conditions are applied inside transaction tx

func (*Update[T]) Ascending

func (update *Update[T]) Ascending(field IField, joinNumber ...uint) *Update[T]

Ascending specify an ascending order when updating models

joinNumber can be used to select the join in case the field is joined more than once

available for: mysql

func (*Update[T]) Descending

func (update *Update[T]) Descending(field IField, joinNumber ...uint) *Update[T]

Descending specify a descending order when updating models

joinNumber can be used to select the join in case the field is joined more than once

available for: mysql

func (*Update[T]) Limit

func (update *Update[T]) Limit(limit int) *Update[T]

Limit specify the number of models to be updated

Limit conditions can be cancelled by using `Limit(-1)`

available for: mysql

func (*Update[T]) Returning

func (update *Update[T]) Returning(dest *[]T) *Update[T]

available for: postgres, sqlite, sqlserver

warning: in sqlite preloads are not allowed

func (*Update[T]) Set

func (update *Update[T]) Set(sets ...*Set[T]) (int64, error)

func (*Update[T]) SetMultiple

func (update *Update[T]) SetMultiple(sets ...ISet) (int64, error)

available for: mysql

type ValueOperator

type ValueOperator[T any] struct {
	Operations []operation
	Modifier   map[Dialector]string
}

Operator that compares the value of the column against a fixed value If Operations has multiple entries, operations will be nested Example (single): value = v1 Example (multi): value LIKE v1 ESCAPE v2

func NewValueOperator

func NewValueOperator[T any](sqlOperator sql.Operator, value any) *ValueOperator[T]

func (*ValueOperator[T]) AddOperation

func (operator *ValueOperator[T]) AddOperation(sqlOperator any, value any) *ValueOperator[T]

func (ValueOperator[T]) InterfaceVerificationMethod

func (operator ValueOperator[T]) InterfaceVerificationMethod(_ T)

func (*ValueOperator[T]) SelectJoin

func (operator *ValueOperator[T]) SelectJoin(operationNumber, joinNumber uint) DynamicOperator[T]

Allows to choose which number of join use for the operation in position "operationNumber" when the value is a field and its model is joined more than once. Does nothing if the operationNumber is bigger than the amount of operations.

func (ValueOperator[T]) ToSQL

func (operator ValueOperator[T]) ToSQL(query *GormQuery, columnName string) (string, []any, error)

type WhereCondition

type WhereCondition[T model.Model] interface {
	Condition[T]

	// Get the sql string and values to use in the query
	GetSQL(query *GormQuery, table Table) (string, []any, error)

	// Returns true if the DeletedAt column if affected by the condition
	// If no condition affects the DeletedAt, the verification that it's null will be added automatically
	AffectsDeletedAt() bool
}

Conditions that can be used in a where clause (or in a on of a join)

func And

func And[T model.Model](conditions ...WhereCondition[T]) WhereCondition[T]

func NewConnectionCondition

func NewConnectionCondition[T model.Model](connector sql.Operator, conditions ...WhereCondition[T]) WhereCondition[T]

Condition that connects multiple conditions. Example: condition1 AND condition2

func NewContainerCondition

func NewContainerCondition[T model.Model](prefix sql.Operator, conditions ...WhereCondition[T]) WhereCondition[T]

Condition that contains a internal condition. Example: NOT (internal condition)

Jump to

Keyboard shortcuts

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