Documentation
¶
Index ¶
- Variables
- func DisableQueryLog(ctx context.Context) context.Context
- func EnableQueryLog(ctx context.Context) context.Context
- func Explain(statement string, args ...any) string
- func NewLogger(config config.Config, log log.Log) logger.Logger
- func Raw(expr string, args ...any) any
- type Builder
- type DB
- func (r *DB) AcquireWriteConnection() (db.WriteConnection, error)
- func (r *DB) AllowQueryDurationHandlersToRunAgain()
- func (r *DB) BeforeExecuting(callback func(context.Context, string, []any) error)
- func (r *DB) BeginTransaction() (contractsdb.Tx, error)
- func (r *DB) Connection(name string) contractsdb.DB
- func (r *DB) DisableQueryLog()
- func (r *DB) Disconnect(connection ...string) error
- func (r *DB) DriverName() string
- func (r *DB) EnableQueryLog()
- func (r *DB) Escape(value any, binary ...bool) (string, error)
- func (r *DB) FlushQueryLog()
- func (r *DB) ForgetRecordModificationState()
- func (r *DB) GetQueryLog() []db.QueryExecuted
- func (r *DB) HasModifiedRecords() bool
- func (r *DB) Listen(callback func(db.QueryExecuted))
- func (r *DB) Name() string
- func (r *DB) Pretend(callback func(db.DB) error) ([]db.QueryExecuted, error)
- func (r *DB) Purge(connection ...string) error
- func (r *DB) Reconnect(connection ...string) (db.DB, error)
- func (r *DB) RecordsHaveBeenModified(modified ...bool)
- func (r *DB) ResetTotalQueryDuration()
- func (r *DB) ServerVersion() (string, error)
- func (r *DB) Sticky(enabled bool) db.DB
- func (r *DB) TotalQueryDuration() time.Duration
- func (r *DB) Transaction(callback func(contractsdb.Tx) error, attempts ...int) error
- func (r *DB) UseWriteConnectionWhenReading(enabled bool) db.DB
- func (r *DB) WhenQueryingForLongerThan(duration time.Duration, callback func(db.QueryExecuted))
- func (r *DB) WithContext(ctx context.Context) contractsdb.DB
- func (r *DB) WithWriteConnection(callback func(db.Tx) error) (err error)
- type Expr
- type Logger
- func (r *Logger) Errorf(ctx context.Context, msg string, data ...any)
- func (r *Logger) Infof(ctx context.Context, msg string, data ...any)
- func (r *Logger) Level(level logger.Level) logger.Logger
- func (r *Logger) Log() log.Log
- func (r *Logger) Panicf(ctx context.Context, msg string, data ...any)
- func (r *Logger) Trace(ctx context.Context, begin *carbon.Carbon, sql string, rowsAffected int64, ...)
- func (r *Logger) Warningf(ctx context.Context, msg string, data ...any)
- type Query
- func (r *Query) AddBinding(value any, component string) db.Query
- func (r *Query) AddSelect(columns ...any) db.Query
- func (r *Query) AfterQuery(callback func(any) any) db.Query
- func (r *Query) Avg(column string, dest any) error
- func (r *Query) BeforeQuery(callback func(db.Query) db.Query) db.Query
- func (r *Query) Chunk(size uint64, callback func(rows []db.Row) error) error
- func (r *Query) ChunkById(size uint64, callback func(rows []db.Row) error, column ...string) error
- func (r *Query) ChunkByIdDesc(size uint64, callback func(rows []db.Row) error, column ...string) error
- func (r *Query) ChunkMap(size uint64, callback func(db.Row) (any, error)) ([]any, error)
- func (r *Query) Clone() db.Query
- func (r *Query) CloneWithout(components ...string) db.Query
- func (r *Query) CloneWithoutBindings(bindings ...string) db.Query
- func (r *Query) Count() (int64, error)
- func (r *Query) CrossJoin(query string, args ...any) db.Query
- func (r *Query) CrossJoinSub(query any, as string) db.Query
- func (r *Query) Cursor() chan db.Row
- func (r *Query) CursorPaginate(perPage int, cursor string, dest any) (db.CursorPaginator, error)
- func (r *Query) Decrement(column string, value ...uint64) error
- func (r *Query) DecrementEach(columns any, extra ...map[string]any) (*db.Result, error)
- func (r *Query) Delete() (*db.Result, error)
- func (r *Query) Distinct(columns ...string) db.Query
- func (r *Query) DoesntExist() (bool, error)
- func (r *Query) DoesntExistOr(callback func() any) (any, error)
- func (r *Query) DynamicWhere(method string, parameters ...any) db.Query
- func (r *Query) Each(callback func(row db.Row) error) error
- func (r *Query) EachById(size uint64, callback func(db.Row) error, column ...string) error
- func (r *Query) Exists() (bool, error)
- func (r *Query) ExistsOr(callback func() any) (any, error)
- func (r *Query) Explain(dest any) error
- func (r *Query) Find(dest any, conds ...any) error
- func (r *Query) FindOr(dest any, id any, callback func() error) error
- func (r *Query) FindOrFail(dest any, conds ...any) error
- func (r *Query) First(dest any) error
- func (r *Query) FirstOr(dest any, callback func() error) error
- func (r *Query) FirstOrFail(dest any) error
- func (r *Query) ForPage(page int, perPage ...int) db.Query
- func (r *Query) ForPageAfterId(perPage int, lastID any, column ...string) db.Query
- func (r *Query) ForPageBeforeId(perPage int, lastID any, column ...string) db.Query
- func (r *Query) ForceIndex(index string) db.Query
- func (r *Query) From(table any, alias ...string) db.Query
- func (r *Query) FromRaw(sql string, bindings ...any) db.Query
- func (r *Query) FromSub(query any, as string) db.Query
- func (r *Query) Get(dest any) error
- func (r *Query) GetBindings() []any
- func (r *Query) GetColumns() []string
- func (r *Query) GetCountForPagination(columns ...string) (int64, error)
- func (r *Query) GetLimit() *int
- func (r *Query) GetOffset() *int
- func (r *Query) GetRawBindings() map[string][]any
- func (r *Query) GroupBy(column ...string) db.Query
- func (r *Query) GroupByRaw(sql string, bindings ...any) db.Query
- func (r *Query) GroupLimit(limit int, column string) db.Query
- func (r *Query) Having(query any, args ...any) db.Query
- func (r *Query) HavingBetween(column string, lower, upper any) db.Query
- func (r *Query) HavingNested(callback func(db.Query) db.Query) db.Query
- func (r *Query) HavingNotBetween(column string, lower, upper any) db.Query
- func (r *Query) HavingNotNull(columns ...string) db.Query
- func (r *Query) HavingNull(columns ...string) db.Query
- func (r *Query) HavingRaw(sql string, bindings ...any) db.Query
- func (r *Query) IgnoreIndex(index string) db.Query
- func (r *Query) Implode(column string, glue string, dest any) error
- func (r *Query) InRandomOrder(seed ...any) db.Query
- func (r *Query) Increment(column string, value ...uint64) error
- func (r *Query) IncrementEach(columns any, extra ...map[string]any) (*db.Result, error)
- func (r *Query) Insert(data any) (*db.Result, error)
- func (r *Query) InsertGetID(data any, sequence ...string) (int64, error)
- func (r *Query) InsertOrIgnore(data any) (*db.Result, error)
- func (r *Query) InsertOrIgnoreUsing(columns []string, query any) (*db.Result, error)
- func (r *Query) InsertUsing(columns []string, query any) (*db.Result, error)
- func (r *Query) Join(query string, args ...any) db.Query
- func (r *Query) JoinLateral(query any, as string) db.Query
- func (r *Query) JoinSub(query any, as string, first any, args ...any) db.Query
- func (r *Query) JoinWhere(table, column, operator string, value any) db.Query
- func (r *Query) Latest(column ...string) db.Query
- func (r *Query) Lazy(chunkSize ...uint64) db.RowIterator
- func (r *Query) LazyById(size uint64, column ...string) db.RowIterator
- func (r *Query) LazyByIdDesc(size uint64, column ...string) db.RowIterator
- func (r *Query) LeftJoin(query string, args ...any) db.Query
- func (r *Query) LeftJoinLateral(query any, as string) db.Query
- func (r *Query) LeftJoinSub(query any, as string, first any, args ...any) db.Query
- func (r *Query) LeftJoinWhere(table, column, operator string, value any) db.Query
- func (r *Query) Limit(limit uint64) db.Query
- func (r *Query) Lock(value any) db.Query
- func (r *Query) LockForUpdate() db.Query
- func (r *Query) Max(column string, dest any) error
- func (r *Query) Min(column string, dest any) error
- func (r *Query) NewQuery() db.Query
- func (r *Query) Offset(offset uint64) db.Query
- func (r *Query) Oldest(column ...string) db.Query
- func (r *Query) OrHaving(column any, args ...any) db.Query
- func (r *Query) OrHavingNotNull(columns ...string) db.Query
- func (r *Query) OrHavingNull(columns ...string) db.Query
- func (r *Query) OrHavingRaw(sql string, bindings ...any) db.Query
- func (r *Query) OrWhere(query any, args ...any) db.Query
- func (r *Query) OrWhereAfterToday(columns ...string) db.Query
- func (r *Query) OrWhereAll(columns []string, args ...any) db.Query
- func (r *Query) OrWhereAny(columns []string, args ...any) db.Query
- func (r *Query) OrWhereBeforeToday(columns ...string) db.Query
- func (r *Query) OrWhereBetween(column string, x, y any) db.Query
- func (r *Query) OrWhereBetweenColumns(column, lower, upper string) db.Query
- func (r *Query) OrWhereColumn(column1 string, column2 ...string) db.Query
- func (r *Query) OrWhereDate(column string, args ...any) db.Query
- func (r *Query) OrWhereDay(column string, args ...any) db.Query
- func (r *Query) OrWhereExists(query any) db.Query
- func (r *Query) OrWhereFullText(columns []string, value string, options ...string) db.Query
- func (r *Query) OrWhereFuture(columns ...string) db.Query
- func (r *Query) OrWhereIn(column string, values any) db.Query
- func (r *Query) OrWhereIntegerInRaw(column string, values []any) db.Query
- func (r *Query) OrWhereIntegerNotInRaw(column string, values []any) db.Query
- func (r *Query) OrWhereJsonContains(column string, value any) db.Query
- func (r *Query) OrWhereJsonContainsKey(column string) db.Query
- func (r *Query) OrWhereJsonDoesntContain(column string, value any) db.Query
- func (r *Query) OrWhereJsonDoesntContainKey(column string) db.Query
- func (r *Query) OrWhereJsonDoesntOverlap(column string, value any) db.Query
- func (r *Query) OrWhereJsonLength(column string, args ...any) db.Query
- func (r *Query) OrWhereJsonOverlaps(column string, value any) db.Query
- func (r *Query) OrWhereLike(column string, value string, caseSensitive ...bool) db.Query
- func (r *Query) OrWhereMonth(column string, args ...any) db.Query
- func (r *Query) OrWhereNone(columns []string, args ...any) db.Query
- func (r *Query) OrWhereNot(query any, args ...any) db.Query
- func (r *Query) OrWhereNotBetween(column string, x, y any) db.Query
- func (r *Query) OrWhereNotBetweenColumns(column, lower, upper string) db.Query
- func (r *Query) OrWhereNotExists(query any) db.Query
- func (r *Query) OrWhereNotIn(column string, values any) db.Query
- func (r *Query) OrWhereNotLike(column string, value string, caseSensitive ...bool) db.Query
- func (r *Query) OrWhereNotNull(column string) db.Query
- func (r *Query) OrWhereNowOrFuture(columns ...string) db.Query
- func (r *Query) OrWhereNowOrPast(columns ...string) db.Query
- func (r *Query) OrWhereNull(column string) db.Query
- func (r *Query) OrWherePast(columns ...string) db.Query
- func (r *Query) OrWhereRaw(raw string, args []any) db.Query
- func (r *Query) OrWhereRowValues(columns []string, operator string, values []any) db.Query
- func (r *Query) OrWhereTime(column string, args ...any) db.Query
- func (r *Query) OrWhereToday(columns ...string) db.Query
- func (r *Query) OrWhereTodayOrAfter(columns ...string) db.Query
- func (r *Query) OrWhereTodayOrBefore(columns ...string) db.Query
- func (r *Query) OrWhereValueBetween(value any, lower, upper string) db.Query
- func (r *Query) OrWhereValueNotBetween(value any, lower, upper string) db.Query
- func (r *Query) OrWhereYear(column string, args ...any) db.Query
- func (r *Query) OrderBy(column any, directions ...string) db.Query
- func (r *Query) OrderByDesc(column any) db.Query
- func (r *Query) OrderByRaw(raw string, bindings ...any) db.Query
- func (r *Query) Paginate(page, limit int, dest any, total *int64) error
- func (r *Query) Pipe(callback func(db.Query) any) any
- func (r *Query) Pluck(column string, dest any) error
- func (r *Query) RawValue(expression string, dest any) error
- func (r *Query) Reorder(column ...string) db.Query
- func (r *Query) ReorderDesc(column string) db.Query
- func (r *Query) RightJoin(query string, args ...any) db.Query
- func (r *Query) RightJoinSub(query any, as string, first any, args ...any) db.Query
- func (r *Query) RightJoinWhere(table, column, operator string, value any) db.Query
- func (r *Query) Select(columns ...string) db.Query
- func (r *Query) SelectRaw(sql string, bindings ...any) db.Query
- func (r *Query) SelectSub(query any, as string) db.Query
- func (r *Query) SetBindings(values []any, component string) db.Query
- func (r *Query) SharedLock() db.Query
- func (r *Query) SimplePaginate(page, limit int, dest any) (bool, error)
- func (r *Query) Skip(offset int) db.Query
- func (r *Query) Sole(dest any) error
- func (r *Query) SoleValue(column string, dest any) error
- func (r *Query) Sum(column string, dest any) error
- func (r *Query) Take(limit int) db.Query
- func (r *Query) Tap(callback func(db.Query)) db.Query
- func (r *Query) ToRawSql() db.ToSql
- func (r *Query) ToSql() db.ToSql
- func (r *Query) Truncate() error
- func (r *Query) Union(query any) db.Query
- func (r *Query) UnionAll(query any) db.Query
- func (r *Query) Unless(condition bool, callback func(db.Query) db.Query, ...) db.Query
- func (r *Query) Update(column any, value ...any) (*db.Result, error)
- func (r *Query) UpdateFrom(values any) (*db.Result, error)
- func (r *Query) UpdateOrInsert(attributes any, values any) (*db.Result, error)
- func (r *Query) Upsert(data any, uniqueBy []string, update ...any) (*db.Result, error)
- func (r *Query) UseIndex(index string) db.Query
- func (r *Query) UseWritePdo() db.Query
- func (r *Query) Value(column string, dest any) error
- func (r *Query) When(condition bool, callback func(query db.Query) db.Query, ...) db.Query
- func (r *Query) Where(query any, args ...any) db.Query
- func (r *Query) WhereAfterToday(columns ...string) db.Query
- func (r *Query) WhereAll(columns []string, args ...any) db.Query
- func (r *Query) WhereAny(columns []string, args ...any) db.Query
- func (r *Query) WhereBeforeToday(columns ...string) db.Query
- func (r *Query) WhereBetween(column string, x, y any) db.Query
- func (r *Query) WhereBetweenColumns(column, lower, upper string) db.Query
- func (r *Query) WhereColumn(column1 string, column2 ...string) db.Query
- func (r *Query) WhereDate(column string, args ...any) db.Query
- func (r *Query) WhereDay(column string, args ...any) db.Query
- func (r *Query) WhereExists(query any) db.Query
- func (r *Query) WhereFullText(columns []string, value string, options ...string) db.Query
- func (r *Query) WhereFuture(columns ...string) db.Query
- func (r *Query) WhereIn(column string, values any) db.Query
- func (r *Query) WhereIntegerInRaw(column string, values []any) db.Query
- func (r *Query) WhereIntegerNotInRaw(column string, values []any) db.Query
- func (r *Query) WhereJsonContains(column string, value any) db.Query
- func (r *Query) WhereJsonContainsKey(column string) db.Query
- func (r *Query) WhereJsonDoesntContain(column string, value any) db.Query
- func (r *Query) WhereJsonDoesntContainKey(column string) db.Query
- func (r *Query) WhereJsonDoesntOverlap(column string, value any) db.Query
- func (r *Query) WhereJsonLength(column string, args ...any) db.Query
- func (r *Query) WhereJsonOverlaps(column string, value any) db.Query
- func (r *Query) WhereLike(column string, value string, caseSensitive ...bool) db.Query
- func (r *Query) WhereMonth(column string, args ...any) db.Query
- func (r *Query) WhereNested(callback func(db.Query) db.Query) db.Query
- func (r *Query) WhereNone(columns []string, args ...any) db.Query
- func (r *Query) WhereNot(query any, args ...any) db.Query
- func (r *Query) WhereNotBetween(column string, x, y any) db.Query
- func (r *Query) WhereNotBetweenColumns(column, lower, upper string) db.Query
- func (r *Query) WhereNotExists(query any) db.Query
- func (r *Query) WhereNotIn(column string, values any) db.Query
- func (r *Query) WhereNotLike(column string, value string, caseSensitive ...bool) db.Query
- func (r *Query) WhereNotNull(column string) db.Query
- func (r *Query) WhereNowOrFuture(columns ...string) db.Query
- func (r *Query) WhereNowOrPast(columns ...string) db.Query
- func (r *Query) WhereNull(column string) db.Query
- func (r *Query) WherePast(columns ...string) db.Query
- func (r *Query) WhereRaw(raw string, args []any) db.Query
- func (r *Query) WhereRowValues(columns []string, operator string, values []any) db.Query
- func (r *Query) WhereTime(column string, args ...any) db.Query
- func (r *Query) WhereToday(columns ...string) db.Query
- func (r *Query) WhereTodayOrAfter(columns ...string) db.Query
- func (r *Query) WhereTodayOrBefore(columns ...string) db.Query
- func (r *Query) WhereValueBetween(value any, lower, upper string) db.Query
- func (r *Query) WhereValueNotBetween(value any, lower, upper string) db.Query
- func (r *Query) WhereYear(column string, args ...any) db.Query
- type QueryLog
- type Row
- type ToSql
- func (r *ToSql) Count() string
- func (r *ToSql) DecrementEach(columns any, extra ...map[string]any) string
- func (r *ToSql) Delete() string
- func (r *ToSql) First() string
- func (r *ToSql) Get() string
- func (r *ToSql) IncrementEach(columns any, extra ...map[string]any) string
- func (r *ToSql) Insert(data any) string
- func (r *ToSql) InsertGetID(data any, sequence ...string) string
- func (r *ToSql) InsertOrIgnore(data any) string
- func (r *ToSql) InsertOrIgnoreUsing(columns []string, query any) string
- func (r *ToSql) InsertUsing(columns []string, query any) string
- func (r *ToSql) Pluck(column string, dest any) string
- func (r *ToSql) Truncate() []string
- func (r *ToSql) Update(column any, value ...any) string
- func (r *ToSql) UpdateFrom(values any) string
- func (r *ToSql) Upsert(data any, uniqueBy []string, update ...any) string
- type Tx
- func (r *Tx) AffectingStatement(statement string, args ...any) (*db.Result, error)
- func (r *Tx) AfterCommit(callback func() error) error
- func (r *Tx) AfterRollBack(callback func() error) error
- func (r *Tx) AfterRollback(callback func() error) error
- func (r *Tx) BeforeStartingTransaction(callback func(db.Tx) error)
- func (r *Tx) BeginTransaction() (db.Tx, error)
- func (r *Tx) CanDiscard() bool
- func (r *Tx) Commit() error
- func (r *Tx) Delete(sql string, args ...any) (*contractsdb.Result, error)
- func (r *Tx) Discard() error
- func (r *Tx) Insert(sql string, args ...any) (*contractsdb.Result, error)
- func (r *Tx) Query() db.Query
- func (r *Tx) Rollback() error
- func (r *Tx) RollbackTo(level int) error
- func (r *Tx) Scalar(statement string, args ...any) (any, error)
- func (r *Tx) Select(dest any, sql string, args ...any) error
- func (r *Tx) SelectFromWriteConnection(dest any, statement string, args ...any) error
- func (r *Tx) SelectOne(dest any, statement string, args ...any) error
- func (r *Tx) SelectResultSets(statement string, args ...any) (result [][]map[string]any, err error)
- func (r *Tx) Statement(sql string, args ...any) error
- func (r *Tx) StatementContext(ctx context.Context, statement string, args ...any) error
- func (r *Tx) Table(name string) contractsdb.Query
- func (r *Tx) Transaction(callback func(db.Tx) error, attempts ...int) error
- func (r *Tx) TransactionLevel() int
- func (r *Tx) Unprepared(statement string) error
- func (r *Tx) Update(sql string, args ...any) (*contractsdb.Result, error)
- type TxBuilder
- type TxLog
Constants ¶
This section is empty.
Variables ¶
var NameMapper = func(s string) string { return str.Of(s).Snake().String() }
NameMapper maps a Go field name to its database column for sqlx, which scans rows into structs. Explicit db tags override this mapper, including fields of embedded structs.
Functions ¶
func Explain ¶
Explain writes the arguments into a statement's placeholders. It is the same rendering the builders use for the raw form of a query, exposed so a caller holding only compiled SQL can report it that way too.
func Raw ¶
Raw creates a raw SQL fragment.
Laravel's DB::raw() takes only a string, with bindings supplied separately by whereRaw and friends. Goravel's Raw also accepts arguments, so they are rendered into the fragment here; a caller that needs parameterisation should use WhereRaw with its bindings instead.
Types ¶
type Builder ¶
Builder executes statements against a database pool. sqlx supplies the struct scanning and the transaction plumbing; the SQL itself is produced by database/query.
func NewBuilder ¶
NewBuilder wraps a pool for statement execution. driver is the connection's driver name; a recognised driver is reduced to the dialect string sqlx keys its bind-type lookup on.
func (*Builder) Explain ¶
Explain renders a statement with its arguments interpolated, which is what ToRawSql reports.
func (*Builder) GetContext ¶
type DB ¶
type DB struct {
contractsdb.Tx
// contains filtered or unexported fields
}
func NewDB ¶
func NewDB(ctx context.Context, config config.Config, driver contractsdriver.Driver, logger contractslogger.Logger, connection *databasedriver.Connection, telemetryResolver contractstelemetry.Resolver) (*DB, error)
func (*DB) AcquireWriteConnection ¶
func (r *DB) AcquireWriteConnection() (db.WriteConnection, error)
func (*DB) AllowQueryDurationHandlersToRunAgain ¶
func (r *DB) AllowQueryDurationHandlersToRunAgain()
func (*DB) BeforeExecuting ¶
func (*DB) BeginTransaction ¶
func (r *DB) BeginTransaction() (contractsdb.Tx, error)
func (*DB) Connection ¶
func (r *DB) Connection(name string) contractsdb.DB
func (*DB) DisableQueryLog ¶
func (r *DB) DisableQueryLog()
func (*DB) Disconnect ¶
func (*DB) DriverName ¶
func (*DB) EnableQueryLog ¶
func (r *DB) EnableQueryLog()
func (*DB) FlushQueryLog ¶
func (r *DB) FlushQueryLog()
func (*DB) ForgetRecordModificationState ¶
func (r *DB) ForgetRecordModificationState()
func (*DB) GetQueryLog ¶
func (r *DB) GetQueryLog() []db.QueryExecuted
func (*DB) HasModifiedRecords ¶
func (*DB) Listen ¶
func (r *DB) Listen(callback func(db.QueryExecuted))
func (*DB) Pretend ¶
Pretend receives an isolated session sharing the connection configuration and hooks. Queries issued through the callback's handle are recorded without reaching the driver.
func (*DB) RecordsHaveBeenModified ¶
func (*DB) ResetTotalQueryDuration ¶
func (r *DB) ResetTotalQueryDuration()
func (*DB) ServerVersion ¶
func (*DB) TotalQueryDuration ¶
func (*DB) Transaction ¶
func (*DB) UseWriteConnectionWhenReading ¶
func (*DB) WhenQueryingForLongerThan ¶
func (r *DB) WhenQueryingForLongerThan(duration time.Duration, callback func(db.QueryExecuted))
func (*DB) WithContext ¶
func (r *DB) WithContext(ctx context.Context) contractsdb.DB
type Expr ¶
type Expr = querybuilder.Expression
Expr is a raw SQL fragment. It is an alias for the query builder's Expression, so the two names denote the same type: callers of this package need not import the builder directly, and a value built under either name is accepted everywhere an Expression is - by the builder's IsExpression and ExpressionValue type switches and by renderLiteral's interpolation switch alike.
It used to be a distinct struct embedding querybuilder.Expression, but Go embedding is not type identity: a db.Expr then failed every type switch that names querybuilder.Expression, so a raw fragment passed to Raw fell through to the fmt.Sprint fallback and rendered as the struct's "{value}" text, producing a malformed statement.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is the DB facade query builder. All SQL is produced by database/query, a port of Illuminate\Database's builder and its grammars; this type adapts that builder to the framework's db.Query contract and executes through CommonBuilder, keeping the tracing and transaction behaviour unchanged.
func NewQuery ¶
func NewQuery(ctx context.Context, readBuilder db.CommonBuilder, writeBuilder db.CommonBuilder, grammar querybuilder.Grammar, driver string, logger logger.Logger, table string, txLogs *[]TxLog, supplied ...databasedriver.QueryComponents) *Query
NewQuery creates a query bound to a table. grammar selects the dialect and driver is its name, used to convert placeholders at execution time.
func (*Query) Chunk ¶
Chunk follows BuildsQueries::chunk, including the caller's starting offset and limit.
func (*Query) ChunkById ¶
ChunkById chunks the query by comparing ids, mirroring Laravel's BuildsQueries::chunkById. Each page is fetched with ForPageAfterId (ascending) using the last id of the previous page as the keyset, so a large result set is walked without the growing offset Chunk pays. The optional column is the key column (default "id"); an optional second value names the result-key alias the id is read from (default the column itself). A callback returning errors.DatabaseChunkStopped halts the loop cleanly, mirroring Laravel's `return false`.
func (*Query) ChunkByIdDesc ¶
func (r *Query) ChunkByIdDesc(size uint64, callback func(rows []db.Row) error, column ...string) error
ChunkByIdDesc is ChunkById in descending id order, mirroring Laravel's BuildsQueries::chunkByIdDesc: each page is fetched with ForPageBeforeId.
func (*Query) CloneWithoutBindings ¶
func (*Query) CrossJoin ¶
CrossJoin adds a cross join from raw SQL. A query that carries its own leading join keyword overrides the default cross type.
func (*Query) CursorPaginate ¶
CursorPaginate fetches one keyset ("seek") page and scans it into dest, which must be a pointer to a slice: a *[]map[string]any for an untyped page, or a pointer to a slice of structs for a typed one. cursor is the encoded anchor — an empty string is the first page, and a non-empty malformed string is refused with errors.QueryCursorInvalid rather than silently restarting at the first page.
It mirrors Paginate but never counts: the page carries no total. The builder entry does the SQL work — the keyset predicate, the per-column order flip for a backwards cursor and the perPage+1 probe limit; this method executes that statement once and projects the scanned rows onto the paginator. The name is deliberately distinct from Cursor, which streams rows.
func (*Query) DecrementEach ¶
func (*Query) Distinct ¶
Distinct preserves the select list and sets the distinct columns, mirroring Laravel's distinct().
func (*Query) DoesntExist ¶
func (*Query) DynamicWhere ¶
func (*Query) Exists ¶
Exists executes the grammar's existence query, preserving limit and offset semantics.
func (*Query) Explain ¶
Explain executes the query plan command; it is distinct from literal interpolation.
func (*Query) FindOr ¶
FindOr retrieves the first row matching the given id, or runs the callback when there is none, mirroring Laravel's Builder::findOr.
func (*Query) FindOrFail ¶
FindOrFail retrieves rows matching the given conditions or fails.
func (*Query) FirstOrFail ¶
func (*Query) ForPageAfterId ¶
func (*Query) ForPageBeforeId ¶
func (*Query) GetBindings ¶
func (*Query) GetColumns ¶
func (*Query) GetCountForPagination ¶
func (*Query) GetRawBindings ¶
func (*Query) Having ¶
Having adds a having clause.
As with applyWhere, a string that carries a binding placeholder is a raw fragment rather than a column name, so it is routed to HavingRaw; anything else keeps the builder's Laravel-faithful Having, which takes a column, an operator and a value (or a raw expression).
func (*Query) HavingBetween ¶
func (*Query) HavingNested ¶
func (*Query) HavingNotBetween ¶
func (*Query) Implode ¶
Implode concatenates the values of a single column into a string separated by glue. It mirrors Laravel's Builder::implode, which plucks the column and joins the plucked values.
func (*Query) InRandomOrder ¶
InRandomOrder orders randomly.
func (*Query) IncrementEach ¶
func (*Query) InsertGetID ¶
InsertGetID inserts one row and returns its generated id.
func (*Query) InsertOrIgnoreUsing ¶
func (*Query) InsertUsing ¶
func (*Query) Join ¶
Join adds an inner join from raw SQL. query is a "<table> on <condition>" fragment, or a whole join clause whose leading keyword ("left join ...") then overrides the default inner type.
func (*Query) LazyByIdDesc ¶
func (r *Query) LazyByIdDesc(size uint64, column ...string) db.RowIterator
func (*Query) LeftJoin ¶
LeftJoin adds a left join from raw SQL. A query that carries its own leading join keyword overrides the default left type.
func (*Query) LeftJoinSub ¶
func (*Query) LeftJoinWhere ¶
func (*Query) LockForUpdate ¶
LockForUpdate locks the selected rows for update.
func (*Query) OrWhereBetween ¶
OrWhereBetween adds an or between clause.
func (*Query) OrWhereBetweenColumns ¶
func (*Query) OrWhereColumn ¶
OrWhereColumn compares two columns with or.
func (*Query) OrWhereFullText ¶
func (*Query) OrWhereIntegerInRaw ¶
func (*Query) OrWhereIntegerNotInRaw ¶
func (*Query) OrWhereJsonContains ¶
OrWhereJsonContains adds an or JSON contains clause.
func (*Query) OrWhereJsonContainsKey ¶
OrWhereJsonContainsKey adds an or JSON key existence clause.
func (*Query) OrWhereJsonDoesntContain ¶
OrWhereJsonDoesntContain adds a negated or JSON contains clause.
func (*Query) OrWhereJsonDoesntContainKey ¶
OrWhereJsonDoesntContainKey adds a negated or JSON key existence clause.
func (*Query) OrWhereJsonDoesntOverlap ¶
func (*Query) OrWhereJsonLength ¶
OrWhereJsonLength compares a JSON array length with or. Mirrors Laravel's Builder::orWhereJsonLength: args is either a single length (equality) or an operator and a length.
func (*Query) OrWhereJsonOverlaps ¶
func (*Query) OrWhereLike ¶
OrWhereLike adds an or like clause.
func (*Query) OrWhereNot ¶
OrWhereNot adds a negated or where clause.
func (*Query) OrWhereNotBetween ¶
OrWhereNotBetween adds an or not between clause.
func (*Query) OrWhereNotBetweenColumns ¶
func (*Query) OrWhereNotIn ¶
OrWhereNotIn adds an or not in clause.
func (*Query) OrWhereNotLike ¶
OrWhereNotLike adds an or not like clause.
func (*Query) OrWhereNotNull ¶
OrWhereNotNull adds an or is not null clause.
func (*Query) OrWhereNull ¶
OrWhereNull adds an or is null clause.
func (*Query) OrWhereRaw ¶
OrWhereRaw adds a raw or where clause.
func (*Query) OrWhereRowValues ¶
func (*Query) OrWhereTodayOrBefore ¶
func (*Query) OrWhereValueBetween ¶
func (*Query) OrWhereValueNotBetween ¶
func (*Query) OrderByDesc ¶
OrderByDesc adds a descending order clause.
func (*Query) OrderByRaw ¶
OrderByRaw adds a raw order clause.
func (*Query) Paginate ¶
Paginate retrieves one page of rows, writing the total into total when it is not nil. It mirrors Laravel's Builder::paginate: a non-positive page and limit fall back to the defaults of page 1 and 15 rows, a total already carried by the caller is an override that skips the count, and a zero total skips the page fetch (Laravel returns an empty collection when the count is zero).
func (*Query) RawValue ¶
RawValue retrieves a single raw expression value from the first row. It mirrors Laravel's Builder::rawValue: selectRaw($expression)->first(). Unlike Value, the expression is not wrapped as an identifier, so it can carry an arbitrary SQL fragment such as UPPER("foo").
func (*Query) RightJoin ¶
RightJoin adds a right join from raw SQL. A query that carries its own leading join keyword overrides the default right type.
func (*Query) RightJoinSub ¶
func (*Query) RightJoinWhere ¶
func (*Query) Select ¶
Select replaces the selected columns and their bindings, mirroring Laravel's select().
func (*Query) SharedLock ¶
SharedLock takes a shared lock on the selected rows.
func (*Query) SimplePaginate ¶
SimplePaginate probes one extra row. Data stays in dest; pagination has no HTTP metadata.
func (*Query) Update ¶
Update updates rows with the given column and value, or with a map of columns.
func (*Query) UpdateOrInsert ¶
UpdateOrInsert updates the first matching row, or inserts a new one.
func (*Query) Upsert ¶
Upsert follows Laravel's distinction between an omitted update argument and an empty array.
func (*Query) UseWritePdo ¶
UseWritePdo forces the query's reads to run on the write connection instead of the reader replica, so a read that has to observe a write issued on the same connection is not answered by a lagging replica. Mirrors Laravel's Builder::useWritePdo, whose flag reaches the connection as the inverse of its $useReadPdo argument. Here the read routing is the builder a read executes through, so the write builder replaces the read one for this query and its clones.
func (*Query) When ¶
func (r *Query) When(condition bool, callback func(query db.Query) db.Query, falseCallback ...func(query db.Query) db.Query) db.Query
When applies a callback when the condition holds.
func (*Query) WhereAny ¶
WhereAny repeats one condition across columns joined by or, and joins that group to the clauses before it with and - the group connector Laravel's whereAny defaults to; the or lives inside the group.
func (*Query) WhereBetween ¶
WhereBetween adds a between clause.
func (*Query) WhereBetweenColumns ¶
func (*Query) WhereColumn ¶
WhereColumn compares two columns. One trailing column means equality, two mean operator then column.
func (*Query) WhereExists ¶
WhereExists adds an exists clause.
func (*Query) WhereFullText ¶
func (*Query) WhereIntegerInRaw ¶
func (*Query) WhereIntegerNotInRaw ¶
func (*Query) WhereJsonContains ¶
WhereJsonContains adds a JSON contains clause.
func (*Query) WhereJsonContainsKey ¶
WhereJsonContainsKey adds a JSON key existence clause.
func (*Query) WhereJsonDoesntContain ¶
WhereJsonDoesntContain adds a negated JSON contains clause.
func (*Query) WhereJsonDoesntContainKey ¶
WhereJsonDoesntContainKey adds a negated JSON key existence clause.
func (*Query) WhereJsonDoesntOverlap ¶
func (*Query) WhereJsonLength ¶
WhereJsonLength compares a JSON array length. Mirrors Laravel's Builder::whereJsonLength: args is either a single length (equality) or an operator and a length.
func (*Query) WhereJsonOverlaps ¶
func (*Query) WhereNotBetween ¶
WhereNotBetween adds a not between clause.
func (*Query) WhereNotBetweenColumns ¶
func (*Query) WhereNotIn ¶
WhereNotIn adds a not in clause.
func (*Query) WhereNotLike ¶
WhereNotLike adds a not like clause.
func (*Query) WhereNotNull ¶
WhereNotNull adds an is not null clause.
func (*Query) WhereRowValues ¶
func (*Query) WhereValueBetween ¶
func (*Query) WhereValueNotBetween ¶
type QueryLog ¶
func GetQueryLog ¶
type ToSql ¶
type ToSql struct {
// contains filtered or unexported fields
}
func (*ToSql) DecrementEach ¶
func (*ToSql) IncrementEach ¶
func (*ToSql) InsertOrIgnore ¶
func (*ToSql) InsertOrIgnoreUsing ¶
func (*ToSql) UpdateFrom ¶
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
func NewTx ¶
func NewTx( ctx context.Context, config config.Config, driver contractsdriver.Driver, logger contractslogger.Logger, connection *databasedriver.Connection, txBuilder contractsdb.TxBuilder, txLogs *[]TxLog, instrument *instrumentationdatabase.Instrument, ) *Tx
func (*Tx) AffectingStatement ¶
func (*Tx) AfterCommit ¶
func (*Tx) AfterRollBack ¶
func (*Tx) AfterRollback ¶
func (*Tx) BeforeStartingTransaction ¶
func (*Tx) CanDiscard ¶
CanDiscard reports whether this handle owns a removable physical connection.
func (*Tx) Discard ¶
Discard rolls back work and removes a leased physical connection from its pool. It is optional for db.Tx implementations and used when session cleanup fails.
func (*Tx) RollbackTo ¶
func (*Tx) SelectFromWriteConnection ¶
func (*Tx) SelectResultSets ¶
func (*Tx) StatementContext ¶
func (*Tx) Transaction ¶
func (*Tx) TransactionLevel ¶
func (*Tx) Unprepared ¶
type TxBuilder ¶
TxBuilder executes statements inside a transaction.
func NewTxBuilder ¶
NewTxBuilder opens a transaction on the given pool.
func NewTxBuilderWithContext ¶
func (*TxBuilder) Explain ¶
Explain renders a statement with its arguments interpolated, which is what ToRawSql reports.