Documentation
¶
Index ¶
- type Builder
- type Clause
- type ClauseType
- type JoinClauseBuilder
- type LimitClauseBuilder
- type OffsetClauseBuilder
- type OrderClauseBuilder
- type Query
- func (q *Query) AfterCommit(callback func() error)
- func (q *Query) AfterRollback(callback func() error)
- func (q *Query) All(dest any) error
- func (q *Query) AllAsVar() ([]any, error)
- func (q *Query) Association(assocName string) contractsorm.Association
- func (q *Query) Avg(column string, dest any) error
- func (q *Query) AvgAsVar(column string) (float64, error)
- func (q *Query) BeforeCommit(callback func() error)
- func (q *Query) BeforeRollback(callback func() error)
- func (q *Query) Begin(opts ...*sql.TxOptions) (contractsorm.Query, error)
- func (q *Query) Chunk(size int, callback any) error
- func (q *Query) Clone() contractsorm.Query
- func (q *Query) Commit() error
- func (q *Query) Connection(name string) contractsorm.Query
- func (q *Query) Count(count *int64) error
- func (q *Query) CountAsVar() (int64, error)
- func (q *Query) Create(value any) error
- func (q *Query) CrossJoin(query string, args ...any) orm.Query
- func (q *Query) Cursor() (chan contractsorm.Cursor, error)
- func (q *Query) DB() (*sql.DB, error)
- func (q *Query) Decrement(column string, amount ...any) (*contractsorm.Result, error)
- func (q *Query) Delete(value ...any) (*contractsorm.Result, error)
- func (q *Query) Destroy(value ...any) (*contractsorm.Result, error)
- func (q *Query) DisableDebug()
- func (q *Query) DisableQueryLog()
- func (q *Query) Distinct(args ...any) orm.Query
- func (q *Query) Driver() database.Driver
- func (q *Query) EnableDebug()
- func (q *Query) EnableQueryLog()
- func (q *Query) Exclude(query any, args ...any) orm.Query
- func (q *Query) Exec(sql string, values ...any) (*contractsorm.Result, error)
- func (q *Query) Exists(exists *bool) error
- func (q *Query) ExistsAsVar() (bool, error)
- func (q *Query) Filter(query any, args ...any) orm.Query
- func (q *Query) Find(dest any, conds ...any) error
- func (q *Query) FindAll(dest any) error
- func (q *Query) FindAllAsVar() ([]any, error)
- func (q *Query) FindAsVar(conds ...any) ([]any, error)
- func (q *Query) FindOne(dest any) error
- func (q *Query) FindOneAsVar() (any, error)
- func (q *Query) FindOrFail(dest any, conds ...any) error
- func (q *Query) First(dest any) error
- func (q *Query) FirstAsVar() (any, error)
- func (q *Query) FirstOr(dest any, callback func() error) error
- func (q *Query) FirstOrCreate(dest any, conds ...any) error
- func (q *Query) FirstOrFail(dest any) error
- func (q *Query) FirstOrNew(dest any, attributes any, values ...any) error
- func (q *Query) FlushQueryLog()
- func (q *Query) ForceDelete(value ...any) (*contractsorm.Result, error)
- func (q *Query) Get(dest any) error
- func (q *Query) GetAsVar() ([]any, error)
- func (q *Query) GetQueryLog() []contractsorm.QueryLog
- func (q *Query) Group(name string) orm.Query
- func (q *Query) Having(query any, args ...any) orm.Query
- func (q *Query) InRandomOrder() contractsorm.Query
- func (q *Query) InTransaction() bool
- func (q *Query) Increment(column string, amount ...any) (*contractsorm.Result, error)
- func (q *Query) InsertGetId(values any) (uint, error)
- func (q *Query) IsDebug() bool
- func (q *Query) Join(query string, args ...any) orm.Query
- func (q *Query) LeftJoin(query string, args ...any) orm.Query
- func (q *Query) Limit(limit int) orm.Query
- func (q *Query) Load(dest any, relation string, args ...any) error
- func (q *Query) LoadMissing(dest any, relation string, args ...any) error
- func (q *Query) LockForUpdate() contractsorm.Query
- func (q *Query) Max(column string, dest any) error
- func (q *Query) MaxAsVar(column string) (float64, error)
- func (q *Query) Min(column string, dest any) error
- func (q *Query) MinAsVar(column string) (float64, error)
- func (q *Query) Model(value any) contractsorm.Query
- func (q *Query) Observe(model any, observer contractsorm.Observer)
- func (q *Query) Offset(offset int) orm.Query
- func (q *Query) Omit(columns ...string) contractsorm.Query
- func (q *Query) OnlySoftDeleted() contractsorm.Query
- func (q *Query) OnlyTrashed() contractsorm.Querydeprecated
- func (q *Query) OrWhere(query any, args ...any) orm.Query
- func (q *Query) OrWhereBetween(column string, x, y any) orm.Query
- func (q *Query) OrWhereColumn(first, operator, second string) orm.Query
- func (q *Query) OrWhereIn(column string, values []any) orm.Query
- func (q *Query) OrWhereJsonContains(column string, value any) orm.Query
- func (q *Query) OrWhereJsonContainsKey(column string) orm.Query
- func (q *Query) OrWhereJsonDoesntContain(column string, value any) orm.Query
- func (q *Query) OrWhereJsonDoesntContainKey(column string) orm.Query
- func (q *Query) OrWhereNot(query any, args ...any) orm.Query
- func (q *Query) OrWhereNotBetween(column string, x, y any) orm.Query
- func (q *Query) OrWhereNotIn(column string, values []any) orm.Query
- func (q *Query) OrWhereNull(column string) orm.Query
- func (q *Query) Order(value any) orm.Query
- func (q *Query) OrderBy(column string, direction ...string) orm.Query
- func (q *Query) OrderByDesc(column string) orm.Query
- func (q *Query) Paginate(page, limit int, dest any, total *int64) error
- func (q *Query) Pluck(column string, dest any) error
- func (q *Query) PluckAsVar(column string) ([]any, error)
- func (q *Query) Raw(sql string, values ...any) contractsorm.Query
- func (q *Query) ReadDB() (*sql.DB, error)
- func (q *Query) Restore(model ...any) (*contractsorm.Result, error)deprecated
- func (q *Query) RestoreSoftDeleted(model ...any) (*contractsorm.Result, error)
- func (q *Query) RightJoin(query string, args ...any) orm.Query
- func (q *Query) Rollback() error
- func (q *Query) RollbackTo(level string) error
- func (q *Query) Save(value any) error
- func (q *Query) SavePoint(name string) error
- func (q *Query) SaveQuietly(value any) error
- func (q *Query) Scan(dest any) error
- func (q *Query) Scopes(funcs ...func(contractsorm.Query) contractsorm.Query) contractsorm.Query
- func (q *Query) Select(query any, args ...any) orm.Query
- func (q *Query) SharedLock() contractsorm.Query
- func (q *Query) Sum(column string, dest any) error
- func (q *Query) SumAsVar(column string) (float64, error)
- func (q *Query) Table(name string, args ...any) contractsorm.Query
- func (q *Query) ToRawSql() contractsorm.ToSql
- func (q *Query) ToSql() contractsorm.ToSql
- func (q *Query) Transaction(txFunc func(tx contractsorm.Query) error, opts ...*sql.TxOptions) error
- func (q *Query) Update(column any, value ...any) (*contractsorm.Result, error)
- func (q *Query) UpdateOrCreate(dest any, attributes any, values any) error
- func (q *Query) UpdateOrInsert(attributes any, values any) error
- func (q *Query) Value(column string, dest any) error
- func (q *Query) ValueAsVar(column string) (any, error)
- func (q *Query) Where(query any, args ...any) orm.Query
- func (q *Query) WhereAll(columns []string, operator string, value any) orm.Query
- func (q *Query) WhereAny(columns []string, operator string, value any) orm.Query
- func (q *Query) WhereBetween(column string, x, y any) orm.Query
- func (q *Query) WhereColumn(first, operator, second string) orm.Query
- func (q *Query) WhereExists(callback func(orm.Query) orm.Query) orm.Query
- func (q *Query) WhereIn(column string, values []any) orm.Query
- func (q *Query) WhereJsonContains(column string, value any) orm.Query
- func (q *Query) WhereJsonContainsKey(column string) orm.Query
- func (q *Query) WhereJsonDoesntContain(column string, value any) orm.Query
- func (q *Query) WhereJsonDoesntContainKey(column string) orm.Query
- func (q *Query) WhereJsonLength(column string, operator string, value any) orm.Query
- func (q *Query) WhereNone(columns []string, operator string, value any) orm.Query
- func (q *Query) WhereNot(query any, args ...any) orm.Query
- func (q *Query) WhereNotBetween(column string, x, y any) orm.Query
- func (q *Query) WhereNotIn(column string, values []any) orm.Query
- func (q *Query) WhereNotNull(column string) orm.Query
- func (q *Query) WhereNull(column string) orm.Query
- func (q *Query) With(query string, args ...any) contractsorm.Query
- func (q *Query) WithContext(ctx context.Context) contractsorm.Query
- func (q *Query) WithCount(relation string, args ...any) contractsorm.Query
- func (q *Query) WithExists(relation string, args ...any) contractsorm.Query
- func (q *Query) WithSoftDeleted() contractsorm.Query
- func (q *Query) WithTrashed() contractsorm.Querydeprecated
- func (q *Query) Without(relations ...string) contractsorm.Query
- func (q *Query) WithoutEvents() contractsorm.Query
- func (q *Query) WithoutSoftDeleted() contractsorm.Query
- func (q *Query) WithoutTrashed() contractsorm.Querydeprecated
- type RawExpression
- type SelectClauseBuilder
- type ToSql
- func (t *ToSql) Avg(column string, dest any) string
- func (t *ToSql) Count() string
- func (t *ToSql) Create(value any) string
- func (t *ToSql) Decrement(column string, amount ...any) string
- func (t *ToSql) Delete(value ...any) string
- func (t *ToSql) Find(dest any, conds ...any) string
- func (t *ToSql) First(dest any) string
- func (t *ToSql) ForceDelete(value ...any) string
- func (t *ToSql) Get(dest any) string
- func (t *ToSql) Increment(column string, amount ...any) string
- func (t *ToSql) InsertGetId(values any) string
- func (t *ToSql) Max(column string, dest any) string
- func (t *ToSql) Min(column string, dest any) string
- func (t *ToSql) Pluck(column string, dest any) string
- func (t *ToSql) Save(value any) string
- func (t *ToSql) Sum(column string, dest any) string
- func (t *ToSql) Update(column any, value ...any) string
- func (t *ToSql) Value(column string, dest any) string
- type WhereClauseBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder handles SQL query building.
func (*Builder) BuildDelete ¶
BuildDelete builds a DELETE query from the query state.
func (*Builder) BuildInsert ¶
BuildInsert builds an INSERT query from the query state.
func (*Builder) BuildSelect ¶
BuildSelect builds a SELECT query from the query state.
type Clause ¶
type Clause interface {
Type() ClauseType
ToSQL() (string, []any)
}
Clause represents a query clause.
type ClauseType ¶
type ClauseType int
ClauseType represents the type of a query clause.
const ( WhereClause ClauseType = iota SelectClause JoinClause GroupClause HavingClause OrderClause LimitClause OffsetClause )
type JoinClauseBuilder ¶
type JoinClauseBuilder struct {
// contains filtered or unexported fields
}
JoinClauseBuilder builds JOIN clauses.
func (*JoinClauseBuilder) ToSQL ¶
func (j *JoinClauseBuilder) ToSQL() (string, []any)
func (*JoinClauseBuilder) Type ¶
func (j *JoinClauseBuilder) Type() ClauseType
type LimitClauseBuilder ¶
type LimitClauseBuilder struct {
// contains filtered or unexported fields
}
LimitClauseBuilder builds LIMIT clauses.
func (*LimitClauseBuilder) ToSQL ¶
func (l *LimitClauseBuilder) ToSQL() (string, []any)
func (*LimitClauseBuilder) Type ¶
func (l *LimitClauseBuilder) Type() ClauseType
type OffsetClauseBuilder ¶
type OffsetClauseBuilder struct {
// contains filtered or unexported fields
}
OffsetClauseBuilder builds OFFSET clauses.
func (*OffsetClauseBuilder) ToSQL ¶
func (o *OffsetClauseBuilder) ToSQL() (string, []any)
func (*OffsetClauseBuilder) Type ¶
func (o *OffsetClauseBuilder) Type() ClauseType
type OrderClauseBuilder ¶
type OrderClauseBuilder struct {
// contains filtered or unexported fields
}
OrderClauseBuilder builds ORDER BY clauses.
func (*OrderClauseBuilder) ToSQL ¶
func (o *OrderClauseBuilder) ToSQL() (string, []any)
func (*OrderClauseBuilder) Type ¶
func (o *OrderClauseBuilder) Type() ClauseType
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query implements the Query interface using native database/sql.
func NewQuery ¶
func NewQuery(ctx context.Context, db *sql.DB, drv driver.Driver, connection string, dbConfig *db.DBConfig, log log.Log) *Query
NewQuery creates a new Query instance.
func NewQueryWithReplicas ¶ added in v0.2.0
func NewQueryWithReplicas(ctx context.Context, writeConn, readConn *sql.DB, drv driver.Driver, connection string, dbConfig *db.DBConfig, lg log.Log) *Query
NewQueryWithReplicas creates a Query with separate read and write sql.DB connections.
func (*Query) AfterCommit ¶
AfterCommit registers a callback to run after the transaction is committed.
func (*Query) AfterRollback ¶
AfterRollback registers a callback to run after the transaction is rolled back.
func (*Query) All ¶ added in v0.12.0
All is an alias for Get, providing Django-style syntax. Retrieves all records matching the query.
func (*Query) AllAsVar ¶ added in v0.14.0
AllAsVar is an alias for GetAsVar, providing Django-style syntax. Retrieves all records matching the query as a variable.
func (*Query) Association ¶
func (q *Query) Association(assocName string) contractsorm.Association
Association returns an association for the given relationship name.
func (*Query) AvgAsVar ¶ added in v0.14.0
AvgAsVar returns the average of the specified column as a variable. This is a convenience method that wraps Avg for improved usability.
func (*Query) BeforeCommit ¶
BeforeCommit registers a callback to run before the transaction is committed.
func (*Query) BeforeRollback ¶
BeforeRollback registers a callback to run before the transaction is rolled back.
func (*Query) Chunk ¶
Chunk processes the query results in chunks and calls the callback for each chunk.
func (*Query) Clone ¶ added in v0.2.0
func (q *Query) Clone() contractsorm.Query
Clone returns a new Query with shared connection state but empty query-builder state.
func (*Query) Connection ¶
func (q *Query) Connection(name string) contractsorm.Query
Connection returns a new Query instance scoped to the named connection.
func (*Query) CountAsVar ¶ added in v0.14.0
CountAsVar returns the number of records matching the query as a variable. This is a convenience method that wraps Count for improved usability.
func (*Query) Create ¶
Create inserts a new record into the database. For Oracle databases, if you need the primary key populated after Create, wrap the call in a transaction to reduce the race window in ID retrieval.
func (*Query) Cursor ¶
func (q *Query) Cursor() (chan contractsorm.Cursor, error)
Cursor returns a cursor for streaming query results.
func (*Query) Delete ¶
func (q *Query) Delete(value ...any) (*contractsorm.Result, error)
Delete deletes records from the database.
func (*Query) Destroy ¶ added in v0.12.0
func (q *Query) Destroy(value ...any) (*contractsorm.Result, error)
Destroy is an alias for Delete, providing Sequelize-style syntax. Deletes records from the database.
func (*Query) DisableDebug ¶ added in v0.10.0
func (q *Query) DisableDebug()
DisableDebug disables debug mode at runtime, sanitizing SQL error messages. This is thread-safe and can be called while the application is running.
func (*Query) DisableQueryLog ¶
func (q *Query) DisableQueryLog()
DisableQueryLog disables query logging.
func (*Query) EnableDebug ¶ added in v0.10.0
func (q *Query) EnableDebug()
EnableDebug enables debug mode at runtime, allowing detailed SQL error messages. This is thread-safe and can be called while the application is running.
func (*Query) EnableQueryLog ¶
func (q *Query) EnableQueryLog()
EnableQueryLog enables query logging.
func (*Query) Exclude ¶ added in v0.12.0
Exclude is an alias for WhereNot, providing Django-style syntax. Supports Django-style syntax: Exclude("column", "value") automatically uses = operator.
func (*Query) ExistsAsVar ¶ added in v0.14.0
ExistsAsVar checks if any records match the query and returns the result as a variable. This is a convenience method that wraps Exists for improved usability.
func (*Query) Filter ¶ added in v0.12.0
Filter is an alias for Where, providing Django-style syntax. Supports Django-style syntax: Filter("column", "value") automatically uses = operator.
func (*Query) FindAll ¶ added in v0.12.0
FindAll is an alias for All, providing Sequelize-style syntax. Retrieves all records matching the query.
func (*Query) FindAllAsVar ¶ added in v0.14.0
FindAllAsVar is an alias for GetAsVar, providing Sequelize-style syntax. Retrieves all records matching the query as a variable.
func (*Query) FindAsVar ¶ added in v0.14.0
FindAsVar retrieves records matching the given conditions as a variable. This is a convenience method that wraps Find for improved usability.
func (*Query) FindOne ¶ added in v0.12.0
FindOne is an alias for First, providing Sequelize-style syntax. Retrieves the first record matching the query.
func (*Query) FindOneAsVar ¶ added in v0.14.0
FindOneAsVar is an alias for FirstAsVar, providing Sequelize-style syntax. Retrieves the first record matching the query as a variable.
func (*Query) FindOrFail ¶
FindOrFail retrieves records matching the given conditions or returns an error if not found.
func (*Query) FirstAsVar ¶ added in v0.14.0
FirstAsVar retrieves the first record matching the query as a variable. This is a convenience method that wraps First for improved usability.
func (*Query) FirstOrCreate ¶
FirstOrCreate retrieves the first record or creates it if not found.
func (*Query) FirstOrFail ¶
FirstOrFail retrieves the first record or returns an error if not found.
func (*Query) FirstOrNew ¶
FirstOrNew retrieves the first record or prepares a new instance if not found.
func (*Query) ForceDelete ¶
func (q *Query) ForceDelete(value ...any) (*contractsorm.Result, error)
ForceDelete permanently deletes a record (bypasses soft delete).
func (*Query) GetAsVar ¶ added in v0.14.0
GetAsVar retrieves all records matching the query as a variable. This is a convenience method that wraps Get for improved usability.
func (*Query) GetQueryLog ¶
func (q *Query) GetQueryLog() []contractsorm.QueryLog
GetQueryLog returns the query log.
func (*Query) InRandomOrder ¶
func (q *Query) InRandomOrder() contractsorm.Query
InRandomOrder orders the query results randomly.
func (*Query) InTransaction ¶
InTransaction returns true if the query is in a transaction.
func (*Query) InsertGetId ¶
InsertGetId inserts a record and returns the ID. For Oracle databases, wrap the call in a transaction to reduce the race window in ID retrieval.
func (*Query) IsDebug ¶ added in v0.10.0
IsDebug returns true if debug mode is enabled. This checks both the runtime debug state and the dbConfig.Debug setting.
func (*Query) LoadMissing ¶
LoadMissing loads a relation only if it's not already loaded.
func (*Query) LockForUpdate ¶
func (q *Query) LockForUpdate() contractsorm.Query
LockForUpdate locks the selected rows for update.
func (*Query) MaxAsVar ¶ added in v0.14.0
MaxAsVar returns the maximum value of the specified column as a variable. This is a convenience method that wraps Max for improved usability.
func (*Query) MinAsVar ¶ added in v0.14.0
MinAsVar returns the minimum value of the specified column as a variable. This is a convenience method that wraps Min for improved usability.
func (*Query) Model ¶
func (q *Query) Model(value any) contractsorm.Query
Model sets the model for the query.
func (*Query) Observe ¶
func (q *Query) Observe(model any, observer contractsorm.Observer)
Observe registers an observer for the given model.
func (*Query) Omit ¶
func (q *Query) Omit(columns ...string) contractsorm.Query
Omit specifies columns to omit from INSERT/UPDATE operations.
func (*Query) OnlySoftDeleted ¶ added in v0.12.0
func (q *Query) OnlySoftDeleted() contractsorm.Query
OnlySoftDeleted returns only soft-deleted records.
func (*Query) OnlyTrashed
deprecated
func (q *Query) OnlyTrashed() contractsorm.Query
OnlyTrashed returns only soft-deleted records.
Deprecated: Use OnlySoftDeleted() instead.
func (*Query) OrWhere ¶
OrWhere adds an or where clause to the query. Supports Laravel-style syntax: OrWhere("column", "value") automatically uses = operator.
func (*Query) OrWhereBetween ¶
OrWhereBetween adds an or where between clause to the query.
func (*Query) OrWhereColumn ¶
OrWhereColumn adds an or where column clause to the query.
func (*Query) OrWhereJsonContains ¶
OrWhereJsonContains adds an or where json contains clause to the query.
func (*Query) OrWhereJsonContainsKey ¶
OrWhereJsonContainsKey adds an or where json contains key clause to the query.
func (*Query) OrWhereJsonDoesntContain ¶
OrWhereJsonDoesntContain adds an or where json doesnt contain clause to the query.
func (*Query) OrWhereJsonDoesntContainKey ¶
OrWhereJsonDoesntContainKey adds an or where json doesnt contain key clause to the query.
func (*Query) OrWhereNot ¶
OrWhereNot adds an or where not clause to the query.
func (*Query) OrWhereNotBetween ¶
OrWhereNotBetween adds an or where not between clause to the query.
func (*Query) OrWhereNotIn ¶
OrWhereNotIn adds an or where not in clause to the query.
func (*Query) OrWhereNull ¶
OrWhereNull adds an or where null clause to the query.
func (*Query) OrderByDesc ¶
OrderByDesc adds an order by clause with desc direction.
func (*Query) PluckAsVar ¶ added in v0.14.0
PluckAsVar retrieves a single column's values from the query results as a variable. This is a convenience method that wraps Pluck for improved usability.
func (*Query) Raw ¶
func (q *Query) Raw(sql string, values ...any) contractsorm.Query
Raw sets a raw SQL query to be executed.
func (*Query) ReadDB ¶ added in v0.2.0
ReadDB returns the read-replica connection (falls back to primary if none configured).
func (*Query) RestoreSoftDeleted ¶ added in v0.12.0
func (q *Query) RestoreSoftDeleted(model ...any) (*contractsorm.Result, error)
RestoreSoftDeleted restores a soft-deleted record.
func (*Query) RollbackTo ¶
RollbackTo rolls back to a specific savepoint.
func (*Query) Save ¶
Save saves the model to the database (INSERT if no primary key, UPDATE otherwise).
func (*Query) SaveQuietly ¶
SaveQuietly saves the model without firing events.
func (*Query) Scopes ¶
func (q *Query) Scopes(funcs ...func(contractsorm.Query) contractsorm.Query) contractsorm.Query
Scopes registers scope functions to be applied to the query.
func (*Query) SharedLock ¶
func (q *Query) SharedLock() contractsorm.Query
SharedLock locks the selected rows with a shared lock.
func (*Query) SumAsVar ¶ added in v0.14.0
SumAsVar returns the sum of the specified column as a variable. This is a convenience method that wraps Sum for improved usability.
func (*Query) Table ¶
func (q *Query) Table(name string, args ...any) contractsorm.Query
Table sets the table for the query.
func (*Query) ToRawSql ¶
func (q *Query) ToRawSql() contractsorm.ToSql
ToRawSql returns the raw SQL with placeholders replaced by values.
func (*Query) ToSql ¶
func (q *Query) ToSql() contractsorm.ToSql
ToSql returns a ToSql instance for generating SQL without execution.
func (*Query) Transaction ¶
Transaction runs a callback wrapped in a database transaction. The callback function should return errors instead of panicking. If the callback returns an error, the transaction is rolled back. If the callback completes successfully, the transaction is committed.
func (*Query) UpdateOrCreate ¶
UpdateOrCreate updates a record if it exists, or creates it if it doesn't. The operation is performed atomically within a transaction to prevent race conditions.
func (*Query) UpdateOrInsert ¶
UpdateOrInsert updates a record if it exists, or creates it if it doesn't. The operation is performed atomically within a transaction to prevent race conditions.
func (*Query) ValueAsVar ¶ added in v0.14.0
ValueAsVar retrieves a single column's value from the first result as a variable. This is a convenience method that wraps Value for improved usability.
func (*Query) Where ¶
Where adds a where clause to the query. Supports Laravel-style syntax: Where("column", "value") automatically uses = operator.
func (*Query) WhereBetween ¶
WhereBetween adds a where between clause to the query.
func (*Query) WhereColumn ¶
WhereColumn adds a where column clause to the query.
func (*Query) WhereExists ¶
WhereExists adds a where exists clause to the query.
func (*Query) WhereJsonContains ¶
WhereJsonContains adds a where json contains clause to the query.
func (*Query) WhereJsonContainsKey ¶
WhereJsonContainsKey adds a where json contains key clause to the query.
func (*Query) WhereJsonDoesntContain ¶
WhereJsonDoesntContain adds a where json doesnt contain clause to the query.
func (*Query) WhereJsonDoesntContainKey ¶
WhereJsonDoesntContainKey adds a where json doesnt contain key clause to the query.
func (*Query) WhereJsonLength ¶
WhereJsonLength adds a where json length clause to the query.
func (*Query) WhereNotBetween ¶
WhereNotBetween adds a where not between clause to the query.
func (*Query) WhereNotIn ¶
WhereNotIn adds a where not in clause to the query.
func (*Query) WhereNotNull ¶
WhereNotNull adds a where not null clause to the query.
func (*Query) With ¶
func (q *Query) With(query string, args ...any) contractsorm.Query
With specifies relations to eager load.
func (*Query) WithContext ¶
func (q *Query) WithContext(ctx context.Context) contractsorm.Query
WithContext returns a new Query instance with the specified context.
func (*Query) WithCount ¶
func (q *Query) WithCount(relation string, args ...any) contractsorm.Query
WithCount adds a count subquery to the SELECT clause for the given relationship. The count is added as a column named "{relation}_count". A constraint callback can be provided to filter the count query.
func (*Query) WithExists ¶
func (q *Query) WithExists(relation string, args ...any) contractsorm.Query
WithExists adds an exists subquery to the SELECT clause for the given relationship. The exists result is added as a boolean column named "{relation}_exists". A constraint callback can be provided to filter the exists query.
func (*Query) WithSoftDeleted ¶ added in v0.12.0
func (q *Query) WithSoftDeleted() contractsorm.Query
WithSoftDeleted includes soft-deleted records in the query results.
func (*Query) WithTrashed
deprecated
func (q *Query) WithTrashed() contractsorm.Query
WithTrashed includes soft-deleted records in the query results.
Deprecated: Use WithSoftDeleted() instead.
func (*Query) Without ¶
func (q *Query) Without(relations ...string) contractsorm.Query
Without removes specified relations from eager loading.
func (*Query) WithoutEvents ¶
func (q *Query) WithoutEvents() contractsorm.Query
WithoutEvents disables event firing for the query.
func (*Query) WithoutSoftDeleted ¶ added in v0.12.0
func (q *Query) WithoutSoftDeleted() contractsorm.Query
WithoutSoftDeleted excludes soft-deleted records from the query results (default behavior).
func (*Query) WithoutTrashed
deprecated
func (q *Query) WithoutTrashed() contractsorm.Query
WithoutTrashed excludes soft-deleted records from the query results (default behavior).
Deprecated: Use WithoutSoftDeleted() instead.
type RawExpression ¶ added in v0.2.0
RawExpression represents a raw SQL expression that can be used as a value in maps
func RawExpr ¶ added in v0.6.0
func RawExpr(sql string, args ...any) RawExpression
RawExpr creates a new raw SQL expression for use in Create/Update values. WARNING: This function injects SQL directly without parameterization. NEVER pass user input to this function. The SQL will be injected directly into the query, creating a SQL injection vulnerability if used with untrusted data. Example: db.Table("users").Create(map[string]any{"created_at": RawExpr("NOW()")}) Safe usage: Only use with hardcoded SQL expressions like "NOW()", "CURRENT_TIMESTAMP", etc. Dangerous usage: RawExpr(userInput) - DO NOT DO THIS
type SelectClauseBuilder ¶
type SelectClauseBuilder struct {
// contains filtered or unexported fields
}
SelectClauseBuilder builds SELECT clauses.
func (*SelectClauseBuilder) ToSQL ¶
func (s *SelectClauseBuilder) ToSQL() (string, []any)
func (*SelectClauseBuilder) Type ¶
func (s *SelectClauseBuilder) Type() ClauseType
type ToSql ¶
type ToSql struct {
// contains filtered or unexported fields
}
ToSql implements the ToSql interface for generating SQL without execution.
func (*ToSql) ForceDelete ¶
ForceDelete generates the SQL for a DELETE query (same as Delete for now).
func (*ToSql) InsertGetId ¶
InsertGetId generates the SQL for an INSERT query with ID retrieval.
type WhereClauseBuilder ¶
type WhereClauseBuilder struct {
// contains filtered or unexported fields
}
WhereClauseBuilder builds WHERE clauses.
func (*WhereClauseBuilder) ToSQL ¶
func (w *WhereClauseBuilder) ToSQL() (string, []any)
func (*WhereClauseBuilder) Type ¶
func (w *WhereClauseBuilder) Type() ClauseType
Source Files
¶
- builder.go
- builder_delete.go
- builder_extract.go
- builder_insert.go
- builder_quote.go
- builder_select.go
- builder_update.go
- builder_where.go
- clause.go
- error_sanitizer.go
- query.go
- query_accessors.go
- query_advanced.go
- query_aggregate.go
- query_builder.go
- query_chunk.go
- query_clone.go
- query_constructors.go
- query_create.go
- query_cursor.go
- query_debug.go
- query_delete.go
- query_find.go
- query_first.go
- query_get.go
- query_helpers.go
- query_insert.go
- query_model.go
- query_paginate.go
- query_relations.go
- query_save.go
- query_scan.go
- query_scopes.go
- query_soft_delete.go
- query_transaction.go
- query_types.go
- query_update.go
- query_where.go
- to_sql.go
- utils.go