Help us shape the future of Go! Take the 2026 Go Developer Survey

query

package
v1.20.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DialectMySQL     = core.DialectMySQL
	DialectPostgres  = core.DialectPostgres
	DialectSqlite    = core.DialectSqlite
	DialectSqlServer = core.DialectSqlServer
)
View Source
const CursorDirectionKey = "_pointsToNextItems"

CursorDirectionKey is the JSON key that carries the scan direction inside an encoded cursor. It is reserved: a query may not order by a column of this name.

View Source
const DefaultCursorName = "cursor"

DefaultCursorName is the query-parameter name a cursor travels under, mirroring Laravel's CursorPaginator::$cursorName default.

View Source
const MaxCursorPayloadSize = 16 * 1024

MaxCursorPayloadSize caps both the encoded string and the decoded JSON of a cursor. A cursor is client-supplied input, so it is refused before it is parsed rather than after.

Variables

View Source
var BindingTypes = core.BindingTypes
View Source
var SelectComponents = grammars.SelectComponents

Functions

func CanonicalDialect

func CanonicalDialect(driver string) string

func CastBinding

func CastBinding(value any) any

CastBinding mirrors Builder::castBinding(), which passes an enum case through enum_value(): a BackedEnum binds as its backing value and a UnitEnum as its name. Any other value is returned unchanged, so it keeps its dynamic type and database/sql converts it at execution.

A nil pointer is also returned unchanged, even when its type is an enum. Calling a value-receiver method through a nil pointer panics, and database/sql binds a nil pointer as NULL, which matches castBinding(null) returning null.

func CleanBindings

func CleanBindings(values []any) []any

CleanBindings drops expressions and casts the rest. Mirrors Builder::cleanBindings().

func ExpressionValue

func ExpressionValue(value any) string

func FlattenValue

func FlattenValue(value any) any

FlattenValue collapses a slice to its first scalar. Mirrors Builder::flattenValue().

func IsExpression

func IsExpression(value any) bool

func IsQueryable

func IsQueryable(value any) bool

IsQueryable reports whether value can act as a subquery. Go has no Closure, so the builder accepts a builder or a callback that configures one. Mirrors Builder::isQueryable().

func ReplacePlaceholders

func ReplacePlaceholders(sql, driver string) string

func UnrecognisedDriverWarning

func UnrecognisedDriverWarning(driver string) error

Types

type BackedEnum

type BackedEnum = core.BackedEnum

BackedEnum is implemented by an enum type whose cases carry a scalar backing value: the Go counterpart of PHP's BackedEnum. CastBinding binds a case as that value. A type implementing both interfaces binds its value, because PHP's BackedEnum extends UnitEnum and enum_value() tests it first.

type BaseGrammar

type BaseGrammar = grammars.BaseGrammar

func NewBaseGrammar

func NewBaseGrammar(prefix string) *BaseGrammar

type Builder

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

Builder is the dialect-neutral query builder. Its state mirrors Illuminate\Database\Query\Builder: flat clause descriptors plus positional bindings.

Presence follows Laravel's isset($query->$component): a nil slice or nil pointer means the component is unset, so the grammar skips it.

func NewBuilder

func NewBuilder(grammar Grammar, postProcessor ...Processor) *Builder

NewBuilder binds SQL compilation and result processing. A SQL-only builder may omit the processor; connections supply their dialect processor when the builder will execute inserts.

func (*Builder) AddBinding

func (b *Builder) AddBinding(value any, typ string) error

AddBinding appends a binding for one component. Mirrors Builder::addBinding().

func (*Builder) AddNestedHavingQuery

func (b *Builder) AddNestedHavingQuery(query *Builder, boolean string) *Builder

AddNestedHavingQuery adds a builder as a nested having. Mirrors Builder::addNestedHavingQuery().

func (*Builder) AddNestedWhereQuery

func (b *Builder) AddNestedWhereQuery(query *Builder, boolean string) *Builder

AddNestedWhereQuery adds a builder as a nested where. Mirrors Builder::addNestedWhereQuery().

func (*Builder) AddSelect

func (b *Builder) AddSelect(columns ...any) *Builder

AddSelect appends columns without clearing the list. Mirrors Builder::addSelect().

func (*Builder) AddWhereExistsQuery

func (b *Builder) AddWhereExistsQuery(query *Builder, boolean string, not bool) *Builder

AddWhereExistsQuery adds a builder as an exists clause. Mirrors Builder::addWhereExistsQuery().

func (*Builder) AfterQuery

func (b *Builder) AfterQuery(callback func(any) any) *Builder

AfterQuery registers a result transformation. Like Laravel, callbacks survive execution and a false-like callback result retains the preceding result.

func (*Builder) Aggregate

func (b *Builder) Aggregate() *core.Aggregate

Aggregate returns the current aggregate, or nil.

func (*Builder) ApplyAfterQueryCallbacks

func (b *Builder) ApplyAfterQueryCallbacks(result any) any

func (*Builder) ApplyBeforeQueryCallbacks

func (b *Builder) ApplyBeforeQueryCallbacks()

ApplyBeforeQueryCallbacks invokes the registered before-query closures once and clears the queue. Mirrors Builder::applyBeforeQueryCallbacks().

func (*Builder) BeforeQuery

func (b *Builder) BeforeQuery(callback func(*Builder) *Builder) *Builder

BeforeQuery registers a closure to be invoked before the query is compiled. The closure receives the builder so it can add clauses. Mirrors Builder::beforeQuery().

func (*Builder) Bindings

func (b *Builder) Bindings() map[string][]any

Bindings returns the raw binding map.

func (*Builder) ClearDistinct

func (b *Builder) ClearDistinct()

ClearDistinct clears both distinct flags.

func (*Builder) Clone

func (b *Builder) Clone() *Builder

Clone returns a deep-enough copy. Laravel's PHP clone copies arrays by value; in Go a struct copy shares slice backing arrays, so every slice is copied explicitly.

func (*Builder) CloneForGrammar

func (b *Builder) CloneForGrammar() GrammarQuery

CloneForGrammar lets compilers rewrite a copy without depending on the concrete builder.

func (*Builder) CloneWithout

func (b *Builder) CloneWithout(components ...string) *Builder

CloneWithout clones the builder with the named components cleared. Mirrors Builder::cloneWithout().

func (*Builder) CloneWithoutBindings

func (b *Builder) CloneWithoutBindings(except ...string) *Builder

CloneWithoutBindings clones the builder with the named binding components emptied. Mirrors Builder::cloneWithoutBindings().

func (*Builder) CrossJoin

func (b *Builder) CrossJoin(table any, first any, operator any, second any) *Builder

CrossJoin adds a cross join. Mirrors Builder::crossJoin().

func (*Builder) CrossJoinSub

func (b *Builder) CrossJoinSub(query any, as string) *Builder

CrossJoinSub adds a subquery cross join. Mirrors Builder::crossJoinSub(): the subquery is resolved through createSub, its bindings go to the join component, and the clause is stored as a cross join whose table is the wrapped subquery expression.

func (*Builder) CursorPaginate

func (b *Builder) CursorPaginate(perPage int, cursor *Cursor) (CursorPaginator, error)

CursorPaginate prepares b for one keyset ("seek") page fetch and returns the paginator skeleton the caller fills with rows. It mirrors the SQL-mutating half of Laravel's BuildsQueries::paginateUsingCursor: resolve the orders, reverse them for a backwards cursor, emit the cursor predicate (once per union branch), set the limit to perPage+1, and hand back a paginator whose Parameters name the ORDER BY columns.

A nil cursor is the first page: no predicate and no reversal, but the order requirement and the perPage+1 limit still apply, exactly as Laravel calls ensureOrderForCursorPagination unconditionally. It mutates the builder — a caller that reuses one should clone it first — and does not execute: the returned paginator has no Items yet, because the row fetch and the paginator's derived booleans and cursors are the facade's job (it scans the rows and calls NewCursorPaginator).

It returns errors.QueryOrderRequired when the builder carries no order at all, mirroring enforceOrderBy; no implicit order is invented.

func (*Builder) DecrementEach

func (b *Builder) DecrementEach(columns any, extra ...core.UpdateValue) *Builder

DecrementEach validates amounts in Laravel's order, then preserves ordered assignments and the overriding extra values just as incrementEach does.

func (*Builder) Distinct

func (b *Builder) Distinct(columns ...any) *Builder

Distinct sets distinct, or distinct-on columns. Mirrors Builder::distinct().

func (*Builder) DistinctColumns

func (b *Builder) DistinctColumns() []any

DistinctColumns returns the distinct-on columns.

func (*Builder) DistinctFlag

func (b *Builder) DistinctFlag() bool

DistinctFlag reports whether distinct is set.

func (*Builder) Driver

func (b *Builder) Driver() string

Driver returns the dialect name the builder was created for, if one was recorded.

func (*Builder) DynamicWhere

func (b *Builder) DynamicWhere(method string, parameters []any) *Builder

DynamicWhere handles dynamic "where" clauses for a magic whereXxx method, such as whereFooBarAndBazOrQux. Mirrors Builder::dynamicWhere() (Builder.php:2245). In PHP this is reached through Builder::__call() with the whole method name; Go has no magic dispatch, so callers pass the full method name (including the leading "where") and its parameters. Like Laravel it drops the first five characters, then walks the And/Or-delimited segments, adding one equality clause per column.

func (*Builder) Error

func (b *Builder) Error() error

Error returns the first error recorded while building, if any.

func (*Builder) ForNestedWhere

func (b *Builder) ForNestedWhere() *Builder

ForNestedWhere creates a nested builder seeded with the parent's from. Mirrors Builder::forNestedWhere().

func (*Builder) ForPage

func (b *Builder) ForPage(page int, perPage ...int) *Builder

ForPage sets offset and limit for a page. Mirrors Builder::forPage(), whose signature is forPage($page, $perPage = 15): the 15 is the default applied only when the caller omits perPage, never a substitute for a zero that was passed. A perPage of 0 therefore keeps a limit of 0 and, multiplied into the offset, still yields an offset of 0. Laravel's body is offset(($page - 1) * $perPage)->limit($perPage) with no zero substitution; the variadic perPage stands in for the PHP parameter default.

func (*Builder) ForPageAfterId

func (b *Builder) ForPageAfterId(perPage int, lastID any, column string) *Builder

ForPageAfterId constrains to the page after an id. Mirrors Builder::forPageAfterId(), whose signature is forPageAfterId($perPage = 15, $lastId = 0, $column = 'id'). The 15 defaults an omitted argument only, never a passed zero; see ForPageBeforeId for why callers supply the default.

func (*Builder) ForPageBeforeId

func (b *Builder) ForPageBeforeId(perPage int, lastID any, column string) *Builder

ForPageBeforeId constrains to the page before an id. Mirrors Builder::forPageBeforeId(), whose signature is forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id'). As with ForPage, the 15 is a default for an omitted argument, never a substitute for a zero that was passed: Laravel's body is limit($perPage) with no zero substitution, so an explicit 0 keeps a limit of 0. Go cannot default a leading parameter, so callers that want the framework default pass 15 themselves.

func (*Builder) ForSubQuery

func (b *Builder) ForSubQuery() *Builder

ForSubQuery mirrors Builder::forSubQuery().

func (*Builder) ForceIndex

func (b *Builder) ForceIndex(index string) *Builder

ForceIndex forces an index. Mirrors Builder::forceIndex().

func (*Builder) From

func (b *Builder) From(table any, as string) *Builder

From sets the table, or a subquery when table is queryable. Mirrors Builder::from().

func (*Builder) FromRaw

func (b *Builder) FromRaw(expression string, bindings []any) *Builder

FromRaw sets a raw table expression. Mirrors Builder::fromRaw().

func (*Builder) FromSub

func (b *Builder) FromSub(query any, as string) *Builder

FromSub sets a subquery as the table. Mirrors Builder::fromSub().

func (*Builder) GetBindings

func (b *Builder) GetBindings() []any

GetBindings flattens the bindings in Laravel's component order. Mirrors Builder::getBindings(), which is Arr::flatten($this->bindings): a binding that is itself a list (for example a whereIn value list built from nested single-element arrays) is flattened into individual bindings.

func (*Builder) GetColumns

func (b *Builder) GetColumns() []string

func (*Builder) GetCountForPagination

func (b *Builder) GetCountForPagination(columns ...any) (string, []any)

GetCountForPagination compiles the count statement a paginator runs to learn how many rows a page is drawn from. It mirrors the compiler half of Builder::getCountForPagination, i.e. Builder::runPaginationCountQuery: the count is built on a clone, so the receiver's own clauses and bindings survive untouched, and it returns the compiled SQL and its bindings rather than an int because this builder has no execution side.

With neither groups nor havings the count runs directly against the table, dropping the select list, the orders and the limit/offset (and the matching select and order bindings) so the statement is a plain "select count(...) as aggregate from ...". With unions the count wraps the union in a derived table named "temp_table", dropping only the union orders, limit and offset so the union itself survives. A grouped or having query is counted by wrapping the grouped select as a derived table named "aggregate_table" and counting its rows, which is what makes grouped pagination count groups rather than rows.

func (*Builder) GetGrammar

func (b *Builder) GetGrammar() Grammar

func (*Builder) GetLimit

func (b *Builder) GetLimit() *int

func (*Builder) GetOffset

func (b *Builder) GetOffset() *int

func (*Builder) GetProcessor

func (b *Builder) GetProcessor() Processor

func (*Builder) GetRawBindings

func (b *Builder) GetRawBindings() map[string][]any

func (*Builder) Grammar

func (b *Builder) Grammar() Grammar

Grammar returns the builder's grammar.

func (*Builder) GroupBy

func (b *Builder) GroupBy(groups ...any) *Builder

GroupBy appends grouping columns. Mirrors Builder::groupBy().

func (*Builder) GroupByRaw

func (b *Builder) GroupByRaw(sql string, bindings []any) *Builder

GroupByRaw appends a raw grouping expression. Mirrors Builder::groupByRaw().

func (*Builder) GroupLimit

func (b *Builder) GroupLimit(value int, column string) *Builder

GroupLimit adds a "group limit" clause to the query, used to cap the rows per group. Mirrors Builder::groupLimit(): a negative value is ignored and leaves any previously set group limit untouched, and the presence flag is what compileSelect tests (Laravel's isset($query->groupLimit)).

func (*Builder) HasAfterQueryCallbacks

func (b *Builder) HasAfterQueryCallbacks() bool

func (*Builder) Having

func (b *Builder) Having(column any, args ...any) *Builder

Having adds a having clause. Mirrors Builder::having().

func (*Builder) HavingBetween

func (b *Builder) HavingBetween(column any, values []any, boolean string, not bool) *Builder

HavingBetween adds a having between clause. Mirrors Builder::havingBetween().

func (*Builder) HavingNested

func (b *Builder) HavingNested(callback func(*Builder) *Builder, boolean string) *Builder

HavingNested nests having clauses. Mirrors Builder::havingNested().

func (*Builder) HavingNotNull

func (b *Builder) HavingNotNull(columns any, boolean string) *Builder

HavingNotNull adds a having not null clause. Mirrors Builder::havingNotNull().

func (*Builder) HavingNull

func (b *Builder) HavingNull(columns any, boolean string, not bool) *Builder

HavingNull adds a having null clause. Mirrors Builder::havingNull().

func (*Builder) HavingRaw

func (b *Builder) HavingRaw(sql string, bindings []any, boolean string) *Builder

HavingRaw adds a raw having clause. Mirrors Builder::havingRaw().

func (*Builder) IgnoreIndex

func (b *Builder) IgnoreIndex(index string) *Builder

IgnoreIndex ignores an index. Mirrors Builder::ignoreIndex().

func (*Builder) InRandomOrder

func (b *Builder) InRandomOrder(seed any) *Builder

InRandomOrder orders randomly. Mirrors Builder::inRandomOrder().

func (*Builder) IncrementEach

func (b *Builder) IncrementEach(columns any, extra ...core.UpdateValue) *Builder

IncrementEach mirrors Builder::incrementEach(): every column's amount must be numeric and every key a column name, and the column is then rewritten to the raw expression `<wrapped column> + <amount>` and merged with extra. The merged assignments become the ordered update descriptor the caller compiles with ToUpdateSQL. Laravel hands the array to update(), which executes against its connection; the builder here holds none, so the descriptor is left on the builder. A Go slice stands for PHP's non-associative array, which Laravel rejects because its keys are integer indices, not column names.

func (*Builder) InsertGetID

func (b *Builder) InsertGetID(connection processors.Connection, values any, sequence string) (any, error)

InsertGetID mirrors Builder::insertGetId: compile with the grammar, then execute through the processor. ToInsertGetIdSQL remains available for callers that only need to preview the SQL.

func (*Builder) InsertOrIgnoreUsing

func (b *Builder) InsertOrIgnoreUsing(columns []any, query any) *Builder

InsertOrIgnoreUsing mirrors Builder::insertOrIgnoreUsing(): it resolves the subquery into a statement — createSub's argument guard rejects anything that is not a builder, a callback or a string — and records the descriptor ToInsertOrIgnoreUsingSQL compiles. Laravel runs the compiled statement against its connection; the builder here holds none, so the statement is left on the builder for the caller to execute.

func (*Builder) InsertUsing

func (b *Builder) InsertUsing(columns []any, query any) *Builder

InsertUsing mirrors Builder::insertUsing(): it applies the queued before-query callbacks at its head — exactly as Laravel does — then resolves the subquery into a statement. createSub's argument guard rejects anything that is not a builder, a callback or a string, and the descriptor ToInsertUsingSQL compiles is recorded on the builder. Laravel runs the compiled statement against its connection; the builder here holds none, so the statement is left for the caller to execute.

func (*Builder) InvalidOperator

func (b *Builder) InvalidOperator(operator any) bool

InvalidOperator mirrors Builder::invalidOperator().

func (*Builder) InvalidOperatorAndValue

func (b *Builder) InvalidOperatorAndValue(operator, value any) bool

InvalidOperatorAndValue mirrors Builder::invalidOperatorAndValue().

The membership test is case-sensitive, as Laravel's in_array() is: "LIKE" with a null value is not an illegal combination, so it falls through to whereNull and renders "is not null", while lowercase "like" is refused. InvalidOperator lowercases separately, so both spellings still pass operator validation; only this null-value guard distinguishes them.

func (*Builder) IsBitwiseOperator

func (b *Builder) IsBitwiseOperator(operator string) bool

IsBitwiseOperator mirrors Builder::isBitwiseOperator(): an operator is bitwise when it is in the base list or in whatever set the dialect declares through GetBitwiseOperators(). The base declares none, so only the dialect grammars add to the shared list.

func (*Builder) IsJoinClause

func (b *Builder) IsJoinClause() bool

IsJoinClause reports whether this builder is a JoinClause.

func (*Builder) Join

func (b *Builder) Join(table any, first any, operator any, second any, typ string, where bool) *Builder

Join adds a join. Mirrors Builder::join().

func (*Builder) JoinLateral

func (b *Builder) JoinLateral(query any, as string, typ string) *Builder

JoinLateral adds a lateral join. Mirrors Builder::joinLateral(): the subquery is resolved through the same createSub path as JoinSub, its bindings go to the join component, and the clause is stored as a lateral JoinClause that compileJoins routes through CompileJoinLateral.

func (*Builder) JoinRaw

func (b *Builder) JoinRaw(expression string, bindings []any, typ string) *Builder

JoinRaw adds a join whose target and condition are a raw expression. This is the Go form of the single string Laravel accepts when a join is passed as one argument, and it is what the existing database/db Join(query string, args ...any) maps onto.

The expression may be either a bare "<table> on <condition>" fragment, which is rendered with the caller's type ("inner join posts on ..."), or a whole join clause that carries its own keyword ("left join addresses ua on ..."), the string form GORM's Joins accepted. In the second case the leading keyword becomes the clause's type, so the default is not prepended on top of it — the defect that rendered "inner join left join addresses ua on ...".

func (*Builder) JoinSub

func (b *Builder) JoinSub(query any, as string, first any, operator any, second any, typ string, where bool) *Builder

JoinSub adds a subquery join. Mirrors Builder::joinSub().

func (*Builder) JoinWhere

func (b *Builder) JoinWhere(table any, first any, operator any, second any, typ string) *Builder

JoinWhere adds a join with the condition in the where clause. Mirrors Builder::joinWhere().

func (*Builder) Latest

func (b *Builder) Latest(column string) *Builder

Latest orders by a column descending. Mirrors Builder::latest().

func (*Builder) LeftJoin

func (b *Builder) LeftJoin(table any, first any, operator any, second any) *Builder

LeftJoin adds a left join. Mirrors Builder::leftJoin().

func (*Builder) LeftJoinLateral

func (b *Builder) LeftJoinLateral(query any, as string) *Builder

LeftJoinLateral adds a lateral left join. Mirrors Builder::leftJoinLateral(), which is joinLateral($query, $as, 'left').

func (*Builder) LeftJoinSub

func (b *Builder) LeftJoinSub(query any, as string, first any, operator any, second any) *Builder

LeftJoinSub adds a left subquery join. Mirrors Builder::leftJoinSub().

func (*Builder) LeftJoinWhere

func (b *Builder) LeftJoinWhere(table, first, operator, second any) *Builder

LeftJoinWhere mirrors Laravel's leftJoinWhere.

func (*Builder) Limit

func (b *Builder) Limit(value int) *Builder

Limit sets the limit, or the union limit while unions exist. Mirrors Builder::limit().

func (*Builder) LimitValue

func (b *Builder) LimitValue() (int, bool)

LimitValue reports the limit set on the builder, mirroring Builder::getLimit(). The bool is false when no limit was set, so callers can tell "unlimited" from a limit of zero.

func (*Builder) Lock

func (b *Builder) Lock(value any) *Builder

Lock sets the lock value. Mirrors Builder::lock().

func (*Builder) LockForUpdate

func (b *Builder) LockForUpdate() *Builder

LockForUpdate locks for update. Mirrors Builder::lockForUpdate().

func (*Builder) MergeBindings

func (b *Builder) MergeBindings(other *Builder)

MergeBindings merges another builder's bindings. Mirrors Builder::mergeBindings().

func (*Builder) MergeWheres

func (b *Builder) MergeWheres(wheres []core.Where, bindings []any) *Builder

MergeWheres merges an array of where clauses and bindings. Mirrors Builder::mergeWheres(): the incoming clauses are appended to this builder's, and the incoming bindings are appended to the "where" component in order - array_values(array_merge(...)) in Laravel, which a slice append reproduces without the PHP array keys. Laravel stores the merged bindings as given, without castBinding (which runs only in addBinding and cleanBindings), and so does this.

func (*Builder) NewQuery

func (b *Builder) NewQuery() *Builder

NewQuery mirrors Builder::newQuery(): a fresh builder sharing the grammar, processor, and dialect.

func (*Builder) Offset

func (b *Builder) Offset(value int) *Builder

Offset sets the offset, or the union offset while unions exist. Mirrors Builder::offset().

func (*Builder) OffsetValue

func (b *Builder) OffsetValue() (int, bool)

OffsetValue reports the offset set on the builder, mirroring Builder::getOffset(). The bool is false when no offset was set.

func (*Builder) Oldest

func (b *Builder) Oldest(column string) *Builder

Oldest orders by a column ascending. Mirrors Builder::oldest().

func (*Builder) OrHaving

func (b *Builder) OrHaving(column any, args ...any) *Builder

OrHaving adds a having clause with "or". Mirrors Builder::orHaving().

func (*Builder) OrHavingNotNull

func (b *Builder) OrHavingNotNull(columns any) *Builder

OrHavingNotNull mirrors Laravel's orHavingNotNull.

func (*Builder) OrHavingNull

func (b *Builder) OrHavingNull(columns any) *Builder

OrHavingNull mirrors Laravel's orHavingNull.

func (*Builder) OrHavingRaw

func (b *Builder) OrHavingRaw(sql string, bindings []any) *Builder

OrHavingRaw adds a raw having clause joined with "or". Mirrors Builder::orHavingRaw(), which is havingRaw() with the or boolean.

func (*Builder) OrWhere

func (b *Builder) OrWhere(column any, args ...any) *Builder

OrWhere adds an "or" where clause. Mirrors Builder::orWhere().

func (*Builder) OrWhereAfterToday

func (b *Builder) OrWhereAfterToday(columns any) *Builder

OrWhereAfterToday mirrors Laravel's orWhereAfterToday.

func (*Builder) OrWhereAll

func (b *Builder) OrWhereAll(columns []any, args ...any) *Builder

OrWhereAll nests one condition repeated across columns joined by and, queued with "or". Mirrors Builder::orWhereAll(), which is whereAll(..., boolean: 'or'): the columns, operator and value are handed through unchanged, only the connector differs.

func (*Builder) OrWhereAny

func (b *Builder) OrWhereAny(columns []any, args ...any) *Builder

OrWhereAny nests one condition repeated across columns joined by or, queued with "or". Mirrors Builder::orWhereAny(), which is whereAny(..., boolean: 'or'): the columns, operator and value are handed through unchanged, only the connector differs.

func (*Builder) OrWhereBeforeToday

func (b *Builder) OrWhereBeforeToday(columns any) *Builder

OrWhereBeforeToday mirrors Laravel's orWhereBeforeToday.

func (*Builder) OrWhereBetween

func (b *Builder) OrWhereBetween(column any, values []any) *Builder

OrWhereBetween adds a "between" clause with "or". Mirrors Builder::orWhereBetween().

func (*Builder) OrWhereBetweenColumns

func (b *Builder) OrWhereBetweenColumns(column any, values []any) *Builder

OrWhereBetweenColumns mirrors Laravel's orWhereBetweenColumns.

func (*Builder) OrWhereColumn

func (b *Builder) OrWhereColumn(first any, operator any, second any) *Builder

OrWhereColumn compares two columns with "or". Mirrors Builder::orWhereColumn().

func (*Builder) OrWhereDate

func (b *Builder) OrWhereDate(column any, args ...any) *Builder

OrWhereDate mirrors Laravel's orWhereDate.

func (*Builder) OrWhereDay

func (b *Builder) OrWhereDay(column any, args ...any) *Builder

OrWhereDay adds an "or where day" statement. Mirrors Builder::orWhereDay().

func (*Builder) OrWhereExists

func (b *Builder) OrWhereExists(callback any) *Builder

OrWhereExists adds an exists clause with "or". Mirrors Builder::orWhereExists().

func (*Builder) OrWhereFullText

func (b *Builder) OrWhereFullText(columns any, value string, options []string) *Builder

OrWhereFullText mirrors Laravel's orWhereFullText.

func (*Builder) OrWhereFuture

func (b *Builder) OrWhereFuture(columns any) *Builder

OrWhereFuture adds an "or where" clause testing whether a date column is in the future. Mirrors Builder::orWhereFuture().

func (*Builder) OrWhereIn

func (b *Builder) OrWhereIn(column any, values any) *Builder

OrWhereIn adds an "in" clause with "or". Mirrors Builder::orWhereIn().

func (*Builder) OrWhereIntegerInRaw

func (b *Builder) OrWhereIntegerInRaw(column any, values []any) *Builder

OrWhereIntegerInRaw mirrors Laravel's orWhereIntegerInRaw.

func (*Builder) OrWhereIntegerNotInRaw

func (b *Builder) OrWhereIntegerNotInRaw(column any, values []any) *Builder

OrWhereIntegerNotInRaw mirrors Laravel's orWhereIntegerNotInRaw.

func (*Builder) OrWhereJsonContains

func (b *Builder) OrWhereJsonContains(column string, value any) *Builder

OrWhereJsonContains adds a JSON "contains" clause with "or". Mirrors Builder::orWhereJsonContains().

func (*Builder) OrWhereJsonContainsKey

func (b *Builder) OrWhereJsonContainsKey(column string) *Builder

OrWhereJsonContainsKey adds a JSON key existence clause with "or". Mirrors Builder::orWhereJsonContainsKey().

func (*Builder) OrWhereJsonDoesntContain

func (b *Builder) OrWhereJsonDoesntContain(column string, value any) *Builder

OrWhereJsonDoesntContain adds a JSON "doesn't contain" clause with "or". Mirrors Builder::orWhereJsonDoesntContain().

func (*Builder) OrWhereJsonDoesntContainKey

func (b *Builder) OrWhereJsonDoesntContainKey(column string) *Builder

OrWhereJsonDoesntContainKey adds an "or" clause that determines if a JSON path does not exist. Mirrors Builder::orWhereJsonDoesntContainKey().

func (*Builder) OrWhereJsonDoesntOverlap

func (b *Builder) OrWhereJsonDoesntOverlap(column string, value any) *Builder

OrWhereJsonDoesntOverlap mirrors Laravel's orWhereJsonDoesntOverlap.

func (*Builder) OrWhereJsonLength

func (b *Builder) OrWhereJsonLength(column string, args ...any) *Builder

OrWhereJsonLength compares a JSON array length with "or". Mirrors Builder::orWhereJsonLength().

func (*Builder) OrWhereJsonOverlaps

func (b *Builder) OrWhereJsonOverlaps(column string, value any) *Builder

OrWhereJsonOverlaps mirrors Laravel's orWhereJsonOverlaps.

func (*Builder) OrWhereLike

func (b *Builder) OrWhereLike(column any, value string, caseSensitive bool) *Builder

OrWhereLike mirrors Laravel's orWhereLike.

func (*Builder) OrWhereMonth

func (b *Builder) OrWhereMonth(column any, args ...any) *Builder

OrWhereMonth adds an "or where month" statement. Mirrors Builder::orWhereMonth().

func (*Builder) OrWhereNone

func (b *Builder) OrWhereNone(columns []any, args ...any) *Builder

OrWhereNone nests one condition repeated across columns, negated, queued with "or". Mirrors Builder::orWhereNone(), which is whereNone(..., boolean: 'or') and so whereAny(..., boolean: 'or not'): the columns, operator and value pass through unchanged, only the connector differs, and the queued group is negated while its inner clauses stay joined by "or".

func (*Builder) OrWhereNot

func (b *Builder) OrWhereNot(column any, args ...any) *Builder

OrWhereNot adds an "or not" where clause. Mirrors Builder::orWhereNot(), which is whereNot(..., boolean: 'or'): the array form nests under "or not" with the inner clauses joined by "or".

func (*Builder) OrWhereNotBetween

func (b *Builder) OrWhereNotBetween(column any, values []any) *Builder

OrWhereNotBetween mirrors Laravel's orWhereNotBetween.

func (*Builder) OrWhereNotBetweenColumns

func (b *Builder) OrWhereNotBetweenColumns(column any, values []any) *Builder

OrWhereNotBetweenColumns mirrors Laravel's orWhereNotBetweenColumns.

func (*Builder) OrWhereNotExists

func (b *Builder) OrWhereNotExists(query any) *Builder

OrWhereNotExists mirrors Laravel's orWhereNotExists.

func (*Builder) OrWhereNotIn

func (b *Builder) OrWhereNotIn(column any, values any) *Builder

OrWhereNotIn adds a "not in" clause with "or". Mirrors Builder::orWhereNotIn().

func (*Builder) OrWhereNotLike

func (b *Builder) OrWhereNotLike(column any, value string, caseSensitive bool) *Builder

OrWhereNotLike mirrors Laravel's orWhereNotLike.

func (*Builder) OrWhereNotNull

func (b *Builder) OrWhereNotNull(column any) *Builder

OrWhereNotNull adds a "is not null" clause with "or". Mirrors Builder::orWhereNotNull().

func (*Builder) OrWhereNowOrFuture

func (b *Builder) OrWhereNowOrFuture(columns any) *Builder

OrWhereNowOrFuture mirrors Laravel's orWhereNowOrFuture.

func (*Builder) OrWhereNowOrPast

func (b *Builder) OrWhereNowOrPast(columns any) *Builder

OrWhereNowOrPast mirrors Laravel's orWhereNowOrPast.

func (*Builder) OrWhereNull

func (b *Builder) OrWhereNull(column any) *Builder

OrWhereNull adds a "is null" clause with "or". Mirrors Builder::orWhereNull().

func (*Builder) OrWherePast

func (b *Builder) OrWherePast(columns any) *Builder

OrWherePast adds an "or where" clause testing whether a date column is in the past. Mirrors Builder::orWherePast().

func (*Builder) OrWhereRaw

func (b *Builder) OrWhereRaw(sql any, bindings []any) *Builder

OrWhereRaw adds a raw where clause with "or". Mirrors Builder::orWhereRaw().

func (*Builder) OrWhereRowValues

func (b *Builder) OrWhereRowValues(columns []any, operator string, values []any) *Builder

OrWhereRowValues adds an "or" tuple comparison. Mirrors Builder::orWhereRowValues().

func (*Builder) OrWhereTime

func (b *Builder) OrWhereTime(column any, args ...any) *Builder

OrWhereTime adds an "or where time" statement. Mirrors Builder::orWhereTime().

func (*Builder) OrWhereToday

func (b *Builder) OrWhereToday(columns any) *Builder

OrWhereToday adds an "or where date = today" clause. Mirrors Builder::orWhereToday().

func (*Builder) OrWhereTodayOrAfter

func (b *Builder) OrWhereTodayOrAfter(columns any) *Builder

OrWhereTodayOrAfter mirrors Laravel's orWhereTodayOrAfter.

func (*Builder) OrWhereTodayOrBefore

func (b *Builder) OrWhereTodayOrBefore(columns any) *Builder

OrWhereTodayOrBefore mirrors Laravel's orWhereTodayOrBefore.

func (*Builder) OrWhereValueBetween

func (b *Builder) OrWhereValueBetween(value any, columns []any) *Builder

OrWhereValueBetween mirrors Laravel's orWhereValueBetween.

func (*Builder) OrWhereValueNotBetween

func (b *Builder) OrWhereValueNotBetween(value any, columns []any) *Builder

OrWhereValueNotBetween mirrors Laravel's orWhereValueNotBetween.

func (*Builder) OrWhereYear

func (b *Builder) OrWhereYear(column any, args ...any) *Builder

OrWhereYear adds an "or where year" statement. Mirrors Builder::orWhereYear().

func (*Builder) OrderBy

func (b *Builder) OrderBy(column any, direction string) *Builder

OrderBy adds an order clause. Mirrors Builder::orderBy().

func (*Builder) OrderByDesc

func (b *Builder) OrderByDesc(column any) *Builder

OrderByDesc adds a descending order clause. Mirrors Builder::orderByDesc().

func (*Builder) OrderByRaw

func (b *Builder) OrderByRaw(sql string, bindings []any) *Builder

OrderByRaw adds a raw order clause. Mirrors Builder::orderByRaw().

func (*Builder) Pipe

func (b *Builder) Pipe(callback func(*Builder) any) any

Pipe passes the builder to the given callback and returns the callback's result, mirroring BuildsQueries::pipe() (return $callback($this) ?? $this). When the callback result is nil - the Go spelling of PHP's null and of a void callback - the receiver is returned instead, so the fluent chain is never broken. A nil callback is likewise a no-op returning the receiver.

func (*Builder) PrepareValueAndOperator

func (b *Builder) PrepareValueAndOperator(value, operator any, useDefault bool) (any, any, error)

PrepareValueAndOperator mirrors Builder::prepareValueAndOperator().

func (*Builder) Processor

func (b *Builder) Processor() Processor

Processor returns the post-processor supplied by the connection.

func (*Builder) Raw

func (b *Builder) Raw(value string) Expression

func (*Builder) RawBindings

func (b *Builder) RawBindings(typ string) []any

RawBindings returns the bindings for one component.

func (*Builder) RebindGrammar

func (b *Builder) RebindGrammar(grammar Grammar, processor Processor, driver string) *Builder

RebindGrammar returns a copy carrying the builder's clauses but compiling them with another grammar, processor and dialect. The clauses are recorded dialect-neutral and are rendered only at compile time, so a query moved onto a different connection must keep its clauses and change the grammar with them: hand a MySQL-built builder to Postgres and it renders backticks, hand it a processor that expects no RETURNING and the insert loses its key. Laravel has the same split — the clauses live on Query\Builder while the grammar and processor come from the connection it is attached to.

func (*Builder) RemoveExistingOrdersFor

func (b *Builder) RemoveExistingOrdersFor(column string) []core.Order

RemoveExistingOrdersFor drops orders on one column. Mirrors Builder::removeExistingOrdersFor().

func (*Builder) Reorder

func (b *Builder) Reorder(column any, direction string) *Builder

Reorder clears ordering then optionally adds one. Mirrors Builder::reorder().

func (*Builder) ReorderDesc

func (b *Builder) ReorderDesc(column any) *Builder

ReorderDesc mirrors Laravel's reorderDesc.

func (*Builder) RightJoin

func (b *Builder) RightJoin(table any, first any, operator any, second any) *Builder

RightJoin adds a right join. Mirrors Builder::rightJoin().

func (*Builder) RightJoinSub

func (b *Builder) RightJoinSub(query any, as string, first any, operator any, second any) *Builder

RightJoinSub adds a right subquery join. Mirrors Builder::rightJoinSub().

func (*Builder) RightJoinWhere

func (b *Builder) RightJoinWhere(table, first, operator, second any) *Builder

RightJoinWhere mirrors Laravel's rightJoinWhere.

func (*Builder) Select

func (b *Builder) Select(columns ...any) *Builder

Select sets the selected columns. Mirrors Builder::select().

Laravel also accepts a string-keyed array to alias a subselect; Go callers use SelectSub for that, which is a deliberate deviation because a variadic Go call cannot carry keys.

func (*Builder) SelectRaw

func (b *Builder) SelectRaw(expression string, bindings []any) *Builder

SelectRaw adds a raw select expression. Mirrors Builder::selectRaw().

func (*Builder) SelectSub

func (b *Builder) SelectSub(query any, as string) *Builder

SelectSub adds a subselect aliased as `as`. Mirrors Builder::selectSub().

func (*Builder) Selects

func (b *Builder) Selects() []any

Selects returns the selected columns, or nil when none were set.

func (*Builder) SetAggregate

func (b *Builder) SetAggregate(function string, columns []any)

SetAggregate sets the aggregate function and its columns. It mirrors Builder::setAggregate: when the query has no groups the orders and their bindings are cleared too, so an ordered query aggregated through the accessor does not keep an ORDER BY Laravel drops (and the order binding cannot outnumber the placeholders left in the compiled SQL). With a group by the order survives, because it still orders the grouped rows.

func (*Builder) SetBindings

func (b *Builder) SetBindings(values []any, typ string) error

SetBindings replaces the bindings for one component. Mirrors Builder::setBindings(), which stores the values as given: Laravel casts a binding only in addBinding and cleanBindings, so an enum set here is not unwrapped. The values are copied so the builder does not alias the caller's slice.

func (*Builder) SetDriver

func (b *Builder) SetDriver(driver string)

SetDriver records the dialect name, used to convert placeholders at execution time.

func (*Builder) SetError

func (b *Builder) SetError(err error)

SetError records a compilation error while preserving the first failure.

func (*Builder) SetSelects

func (b *Builder) SetSelects(columns []any)

SetSelects replaces the selected columns.

func (*Builder) SetUseUpsertAlias

func (b *Builder) SetUseUpsertAlias(alias bool)

SetUseUpsertAlias records the connection's use_upsert_alias setting on the builder. Laravel's MySQL grammar reads it from the connection in compileUpsert; Go carries it on the builder, which represents $query, and the MySQL grammar reads it there.

func (*Builder) SharedLock

func (b *Builder) SharedLock() *Builder

SharedLock takes a shared lock. Mirrors Builder::sharedLock().

func (*Builder) Skip

func (b *Builder) Skip(value int) *Builder

Skip is an alias for Offset. Mirrors Builder::skip().

func (*Builder) State

func (b *Builder) State() *State

State exposes the compilation clauses to the grammar.

func (*Builder) TableSource

func (b *Builder) TableSource() any

TableSource returns the table the query targets: a string, an Expression, or nil when unset. database/db uses it to preserve the "table is required" error and to inspect the from clause.

func (*Builder) Take

func (b *Builder) Take(value int) *Builder

Take is an alias for Limit. Mirrors Builder::take().

func (*Builder) Tap

func (b *Builder) Tap(callback func(*Builder)) *Builder

Tap passes the builder to the given callback and returns the receiver unchanged, mirroring BuildsQueries::tap(). The callback's return value is ignored; nil callbacks are a no-op so the fluent chain is never broken.

func (*Builder) ToAggregateSQL

func (b *Builder) ToAggregateSQL(aggregate core.Aggregate) (string, []any)

ToAggregateSQL compiles an aggregate select and its bindings. The aggregate is applied to a copy so the builder itself is left unchanged.

The copy mirrors what Laravel's aggregate() does before it compiles:

$this->cloneWithout($this->unions || $this->havings ? [] : ['columns'])
     ->cloneWithoutBindings($this->unions || $this->havings ? [] : ['select'])
     ->setAggregate($function, $columns)
     ->get($columns);

Without unions or havings the select list is dropped and, with it, the select bindings: the compiled aggregate selects no columns of its own (compileColumns is skipped whenever an aggregate is set), so a subselect that contributed a "select" binding no longer has a placeholder in the SQL and must not hand its value to the executor. With unions or havings the select list survives inside the derived table, so its bindings must survive with it.

setAggregate() also drops the orders and their bindings when the query has no groups, which is why an aggregate over an ordered query compiles without an order by clause.

func (*Builder) ToDeleteSQL

func (b *Builder) ToDeleteSQL() (string, []any)

ToDeleteSQL compiles a delete statement and its bindings.

func (*Builder) ToExistsSQL

func (b *Builder) ToExistsSQL() (string, []any)

ToExistsSQL compiles an exists statement and its bindings.

func (*Builder) ToInsertGetIdSQL

func (b *Builder) ToInsertGetIdSQL(values any, sequence string) (string, []any)

ToInsertGetIdSQL compiles an insert that returns the generated id. The values may be an ordered InsertValues, which fixes the column order Laravel keeps for a single insertGetId record, or a []map[string]any, whose columns are ordered by name (the historic map-shaped behaviour).

func (*Builder) ToInsertOrIgnoreSQL

func (b *Builder) ToInsertOrIgnoreSQL(values []map[string]any) (string, []any)

ToInsertOrIgnoreSQL compiles an insert that ignores conflicts.

func (*Builder) ToInsertOrIgnoreUsingSQL

func (b *Builder) ToInsertOrIgnoreUsingSQL() (string, []any)

ToInsertOrIgnoreUsingSQL compiles the insert-or-ignore-using statement InsertOrIgnoreUsing recorded and returns it with its bindings. It mirrors what Laravel hands to affectingStatement — grammar.compileInsertOrIgnoreUsing(columns, sql) with cleanBindings(bindings) — so the base and SqlServer grammars refuse and record errInsertIgnoreNotSupported, surfaced through Builder.Error().

func (*Builder) ToInsertSQL

func (b *Builder) ToInsertSQL(values []map[string]any) (string, []any)

ToInsertSQL compiles an insert statement and its bindings.

func (*Builder) ToInsertUsingSQL

func (b *Builder) ToInsertUsingSQL() (string, []any)

ToInsertUsingSQL compiles the insert-using statement InsertUsing recorded and returns it with its bindings. It mirrors what Laravel hands to affectingStatement — grammar.compileInsertUsing(columns, sql) with cleanBindings(bindings). No dialect overrides compileInsertUsing: MySql, SQLite and Postgres each build their ignore variant on top of it in their own entry points rather than here.

func (*Builder) ToSQL

func (b *Builder) ToSQL() string

ToSQL compiles the builder into SQL. Mirrors Builder::toSql().

func (*Builder) ToSelectSQL

func (b *Builder) ToSelectSQL() (string, []any)

ToSelectSQL compiles a select statement and its bindings.

func (*Builder) ToTruncateSQL

func (b *Builder) ToTruncateSQL() []core.Statement

ToTruncateSQL compiles the truncate statements. SQLite needs two.

func (*Builder) ToUpdateFromSQL

func (b *Builder) ToUpdateFromSQL(values any) (string, []any)

ToUpdateFromSQL is PostgreSQL's explicit UPDATE ... FROM path.

func (*Builder) ToUpdateSQL

func (b *Builder) ToUpdateSQL(values any) (string, []any)

ToUpdateSQL compiles an update statement and its bindings. The values may be an ordered UpdateValues (Laravel's update array, whose insertion order fixes the SET list) or a plain map[string]any, which is ordered by column name. The binding order matches the SQL: set values first, then the where clause, exactly as Grammar::prepareBindingsForUpdate produces.

func (*Builder) ToUpsertSQL

func (b *Builder) ToUpsertSQL(values []map[string]any, uniqueBy []string, update []core.UpsertUpdate) (string, []any)

ToUpsertSQL compiles an upsert statement and its bindings.

func (*Builder) Union

func (b *Builder) Union(query any, all bool) *Builder

Union adds a union clause. Mirrors Builder::union().

func (*Builder) UnionAll

func (b *Builder) UnionAll(query any) *Builder

UnionAll adds a union all clause. Mirrors Builder::unionAll().

func (*Builder) Unless

func (b *Builder) Unless(value any, callback func(*Builder, any) *Builder, defaultCallback ...func(*Builder, any) *Builder) *Builder

Unless runs callback when value is (or resolves to) falsy, and defaultCallback when value is truthy and a default was given. Mirrors Conditionable::unless(), the negation of when(): Laravel resolves a Closure value the same way, then takes the `if (! $value)` branch in place of `if ($value)`. Like When, the callback receives the builder and the resolved value, a non-nil result becomes the return value (Laravel's `return $callback(...) ?? $this`) and a nil result keeps the receiver. The higher-order proxy form is not offered for the same reason as When's.

func (*Builder) UpdateValues

func (b *Builder) UpdateValues() core.UpdateValues

UpdateValues returns the ordered assignments IncrementEach recorded, or nil when it recorded none. The caller compiles them with ToUpdateSQL, mirroring the array Laravel's incrementEach hands to update().

func (*Builder) UseIndex

func (b *Builder) UseIndex(index string) *Builder

UseIndex suggests an index. Mirrors Builder::useIndex().

func (*Builder) When

func (b *Builder) When(value any, callback func(*Builder, any) *Builder, defaultCallback ...func(*Builder, any) *Builder) *Builder

When runs callback when value is (or resolves to) truthy, and defaultCallback when value is falsy and a default was given. Mirrors Conditionable::when(), which the query Builder consumes through Database\Concerns\BuildsQueries. A func(*Builder) any value is resolved with the builder first, exactly like Laravel's `$value instanceof Closure ? $value($this) : $value`.

The callback receives the builder and the resolved value; a non-nil result becomes the return value (Laravel's `return $callback(...) ?? $this`), while a nil result keeps the receiver, so the fluent chain is never broken. Laravel's higher-order proxy form — when() with no callback, or with a lone value — has no Go analogue and is not offered; callers pass the callback directly.

func (*Builder) Where

func (b *Builder) Where(column any, args ...any) *Builder

Where adds an "and" where clause. Mirrors Builder::where().

func (*Builder) WhereAfterToday

func (b *Builder) WhereAfterToday(columns any) *Builder

WhereAfterToday mirrors Laravel's whereAfterToday.

func (*Builder) WhereAll

func (b *Builder) WhereAll(columns []any, operator any, value any, boolean string) *Builder

WhereAll nests one condition repeated across columns joined by and. Mirrors Builder::whereAll().

func (*Builder) WhereAny

func (b *Builder) WhereAny(columns []any, operator any, value any, boolean string) *Builder

WhereAny nests one condition repeated across columns joined by or. Mirrors Builder::whereAny().

func (*Builder) WhereBeforeToday

func (b *Builder) WhereBeforeToday(columns any) *Builder

WhereBeforeToday mirrors Laravel's whereBeforeToday.

func (*Builder) WhereBetween

func (b *Builder) WhereBetween(column any, values []any, boolean string, not bool) *Builder

WhereBetween adds a "between" clause. Mirrors Builder::whereBetween().

func (*Builder) WhereBetweenColumns

func (b *Builder) WhereBetweenColumns(column any, values []any, boolean string, not bool) *Builder

WhereBetweenColumns compares a column against two other columns. Mirrors Builder::whereBetweenColumns().

func (*Builder) WhereColumn

func (b *Builder) WhereColumn(first any, operator any, second any, boolean string) *Builder

WhereColumn compares two columns. Mirrors Builder::whereColumn(). An array first argument is a list of column comparisons, expanded through addArrayOfWheres like Laravel's is_array($first) branch.

func (*Builder) WhereDate

func (b *Builder) WhereDate(column any, args ...any) *Builder

WhereDate compares the date part. Mirrors Builder::whereDate().

func (*Builder) WhereDay

func (b *Builder) WhereDay(column any, args ...any) *Builder

WhereDay compares the day of month. Mirrors Builder::whereDay().

func (*Builder) WhereExists

func (b *Builder) WhereExists(callback any, boolean string, not bool) *Builder

WhereExists adds an exists clause. Mirrors Builder::whereExists().

func (*Builder) WhereFullText

func (b *Builder) WhereFullText(columns any, value string, options []string, boolean string) *Builder

WhereFullText adds a fulltext clause. Mirrors Builder::whereFullText().

func (*Builder) WhereFuture

func (b *Builder) WhereFuture(columns any) *Builder

WhereFuture adds a where clause testing whether a date column is in the future. Mirrors Builder::whereFuture(): the ">" operator, joined to the previous predicate by "and". It shares wherePastOrFuture with the past family.

func (*Builder) WhereIn

func (b *Builder) WhereIn(column any, values any, boolean string, not bool) *Builder

WhereIn adds an "in" clause. Mirrors Builder::whereIn().

func (*Builder) WhereIntegerInRaw

func (b *Builder) WhereIntegerInRaw(column any, values []any, boolean string, not bool) *Builder

WhereIntegerInRaw adds an "in" clause whose values are inlined, never parameterised. Mirrors Builder::whereIntegerInRaw().

func (*Builder) WhereIntegerNotInRaw

func (b *Builder) WhereIntegerNotInRaw(column any, values []any, boolean string) *Builder

WhereIntegerNotInRaw mirrors Laravel's whereIntegerNotInRaw.

func (*Builder) WhereJsonContains

func (b *Builder) WhereJsonContains(column string, value any, boolean string, not bool) *Builder

WhereJsonContains adds a JSON contains clause. Mirrors Builder::whereJsonContains().

func (*Builder) WhereJsonContainsKey

func (b *Builder) WhereJsonContainsKey(column string, boolean string, not bool) *Builder

WhereJsonContainsKey adds a JSON key existence clause. Mirrors Builder::whereJsonContainsKey().

func (*Builder) WhereJsonDoesntContain

func (b *Builder) WhereJsonDoesntContain(column string, value any, boolean string) *Builder

WhereJsonDoesntContain adds a JSON "doesn't contain" clause. Mirrors Builder::whereJsonDoesntContain().

func (*Builder) WhereJsonDoesntContainKey

func (b *Builder) WhereJsonDoesntContainKey(column string, boolean string) *Builder

WhereJsonDoesntContainKey adds a clause that determines if a JSON path does not exist. Mirrors Builder::whereJsonDoesntContainKey().

func (*Builder) WhereJsonDoesntOverlap

func (b *Builder) WhereJsonDoesntOverlap(column string, value any, boolean string) *Builder

WhereJsonDoesntOverlap mirrors Laravel's whereJsonDoesntOverlap.

func (*Builder) WhereJsonLength

func (b *Builder) WhereJsonLength(column string, args ...any) *Builder

WhereJsonLength compares a JSON array length. Mirrors Builder::whereJsonLength().

func (*Builder) WhereJsonOverlaps

func (b *Builder) WhereJsonOverlaps(column string, value any, boolean string, not bool) *Builder

WhereJsonOverlaps adds a JSON overlaps clause. Mirrors Builder::whereJsonOverlaps().

func (*Builder) WhereLike

func (b *Builder) WhereLike(column any, value string, caseSensitive bool, boolean string, not bool) *Builder

WhereLike adds a "like" clause. Mirrors Builder::whereLike().

func (*Builder) WhereMonth

func (b *Builder) WhereMonth(column any, args ...any) *Builder

WhereMonth compares the month. Mirrors Builder::whereMonth().

func (*Builder) WhereNested

func (b *Builder) WhereNested(callback func(*Builder) *Builder, boolean string) *Builder

WhereNested starts a nested where. Mirrors Builder::whereNested().

func (*Builder) WhereNone

func (b *Builder) WhereNone(columns []any, operator any, value any, boolean string) *Builder

WhereNone nests one condition repeated across columns, negated. Mirrors Builder::whereNone().

func (*Builder) WhereNot

func (b *Builder) WhereNot(column any, args ...any) *Builder

WhereNot adds an "and not" where clause. Mirrors Builder::whereNot(). An array first argument is wrapped in the negation: Laravel runs whereNested(..., $boolean.' not') and re-enters where() inside, so the nested clauses keep the plain boolean and the negation wraps the whole group.

func (*Builder) WhereNotBetween

func (b *Builder) WhereNotBetween(column any, values []any, boolean string) *Builder

WhereNotBetween adds a "not between" clause. Mirrors Builder::whereNotBetween().

func (*Builder) WhereNotBetweenColumns

func (b *Builder) WhereNotBetweenColumns(column any, values []any, boolean string) *Builder

WhereNotBetweenColumns mirrors Laravel's whereNotBetweenColumns.

func (*Builder) WhereNotExists

func (b *Builder) WhereNotExists(callback any, boolean string) *Builder

WhereNotExists adds a "not exists" clause. Mirrors Builder::whereNotExists().

func (*Builder) WhereNotIn

func (b *Builder) WhereNotIn(column any, values any, boolean string) *Builder

WhereNotIn adds a "not in" clause. Mirrors Builder::whereNotIn().

func (*Builder) WhereNotLike

func (b *Builder) WhereNotLike(column any, value string, caseSensitive bool, boolean string) *Builder

WhereNotLike adds a "not like" clause. Mirrors Builder::whereNotLike().

func (*Builder) WhereNotNull

func (b *Builder) WhereNotNull(columns any, boolean string) *Builder

WhereNotNull adds a "is not null" clause. Mirrors Builder::whereNotNull().

func (*Builder) WhereNowOrFuture

func (b *Builder) WhereNowOrFuture(columns any) *Builder

WhereNowOrFuture mirrors Laravel's whereNowOrFuture.

func (*Builder) WhereNowOrPast

func (b *Builder) WhereNowOrPast(columns any) *Builder

WhereNowOrPast mirrors Laravel's whereNowOrPast.

func (*Builder) WhereNull

func (b *Builder) WhereNull(columns any, boolean string, not bool) *Builder

WhereNull adds a "is null" clause. Mirrors Builder::whereNull().

func (*Builder) WherePast

func (b *Builder) WherePast(columns any) *Builder

WherePast adds a where clause testing whether a date column is in the past. Mirrors Builder::wherePast(): the "<" operator, joined to the previous predicate by "and".

func (*Builder) WhereRaw

func (b *Builder) WhereRaw(sql any, bindings []any, boolean string) *Builder

WhereRaw adds a raw where clause. Mirrors Builder::whereRaw().

func (*Builder) WhereRowValues

func (b *Builder) WhereRowValues(columns []any, operator string, values []any, boolean ...string) *Builder

WhereRowValues compares tuples. Mirrors Builder::whereRowValues().

func (*Builder) WhereSub

func (b *Builder) WhereSub(column any, operator any, callback any, boolean string) *Builder

WhereSub compares a column against a sub-select. Mirrors Builder::whereSub().

func (*Builder) WhereTime

func (b *Builder) WhereTime(column any, args ...any) *Builder

WhereTime compares the time part. Mirrors Builder::whereTime().

func (*Builder) WhereToday

func (b *Builder) WhereToday(columns any, boolean string) *Builder

WhereToday compares the date part with today's date. Mirrors Builder::whereToday().

func (*Builder) WhereTodayOrAfter

func (b *Builder) WhereTodayOrAfter(columns any) *Builder

WhereTodayOrAfter mirrors Laravel's whereTodayOrAfter.

func (*Builder) WhereTodayOrBefore

func (b *Builder) WhereTodayOrBefore(columns any) *Builder

WhereTodayOrBefore mirrors Laravel's whereTodayOrBefore.

func (*Builder) WhereValueBetween

func (b *Builder) WhereValueBetween(value any, columns []any, boolean string, not bool) *Builder

WhereValueBetween compares a value against two columns. Mirrors Builder::whereValueBetween().

func (*Builder) WhereValueNotBetween

func (b *Builder) WhereValueNotBetween(value any, columns []any, boolean string) *Builder

WhereValueNotBetween mirrors Laravel's whereValueNotBetween.

func (*Builder) WhereYear

func (b *Builder) WhereYear(column any, args ...any) *Builder

WhereYear compares the year. Mirrors Builder::whereYear().

type Cursor

type Cursor struct {
	// Parameters holds the sort key of the anchor row, one entry per ORDER BY column, in ORDER BY
	// order. It is a slice, not a map: map iteration order is random, which would make every
	// encoding of the same cursor differ.
	Parameters CursorParameters
	// PointsNext reports whether the anchor row is the last row of the page just returned, so the
	// next fetch scans forward. False means scan backwards with every ORDER BY direction reversed.
	PointsNext bool
}

Cursor is the decoded page anchor: one value per ORDER BY column, in ORDER BY order, plus the direction bit. It mirrors Illuminate\Pagination\Cursor and round-trips through Encode and DecodeCursor in the same wire format, so a cursor issued by Laravel can be consumed here and vice versa.

func DecodeCursor

func DecodeCursor(encoded string) (Cursor, error)

DecodeCursor parses an encoded cursor produced by Encode or by Laravel's Cursor::encode. It is strict where Laravel is lenient: every failure returns a named error rather than a nil cursor.

Numbers are decoded as json.Number, so an id above 2^53 reaches the caller intact instead of being rounded through float64.

func NewCursor

func NewCursor(parameters CursorParameters, pointsNext bool) Cursor

NewCursor builds a cursor. Direction defaults to next at the call site; pass false to scan backwards.

func (Cursor) Encode

func (c Cursor) Encode() (string, error)

Encode renders the cursor in Laravel's wire format: unpadded base64url over compact JSON, with the parameters in slice order and the direction bit appended as _pointsToNextItems. Laravel escapes "/" as "\/" and Go does not; both are valid JSON, so either side decodes either form.

func (Cursor) Has

func (c Cursor) Has(column string) bool

Has reports whether column carries a value in the cursor.

func (Cursor) MarshalJSON

func (c Cursor) MarshalJSON() ([]byte, error)

MarshalJSON emits the same compact object Encode base64-wraps, so the cursor can be nested in a caller's own response without a second trip through base64.

func (Cursor) Parameter

func (c Cursor) Parameter(column string) (any, error)

Parameter returns the value stored for column. It reports errors.QueryCursorParameterMissing when the cursor and the query's ORDER BY disagree, mirroring Laravel's UnexpectedValueException. Lookup is by first match, in slice order.

func (Cursor) PointsToPreviousItems

func (c Cursor) PointsToPreviousItems() bool

PointsToPreviousItems is the inverse of PointsNext: true means the ORDER BY directions are reversed for this fetch and the returned rows must be reversed to read front-to-back.

func (Cursor) Values

func (c Cursor) Values(columns []string) ([]any, error)

Values returns the values for columns in the caller's order, which is the ORDER BY order of the query being run, never the cursor's own order. It fails on the first column the cursor does not carry.

type CursorPaginator

type CursorPaginator struct {
	// Items is the page, already trimmed to PerPage and, for a backwards fetch, reversed so it reads
	// front-to-back.
	Items []map[string]any
	// PerPage is the page size actually used, clamped to at least 1.
	PerPage int
	// Cursor is the anchor the page was fetched from. The zero value is the first page.
	Cursor Cursor
	// HasCursor distinguishes an explicit cursor (even an empty one) from the first page.
	HasCursor bool
	// CursorName is the query-parameter name the encoded cursors travel under.
	CursorName string
	// Parameters is the ORDER BY column list, in ORDER BY order. It is the key set a minted cursor
	// carries, never the SELECT list.
	Parameters []string
	// contains filtered or unexported fields
}

CursorPaginator is the result of one keyset page fetch. It holds no SQL, no database handle and no request state: everything it needs was decided before it was constructed, and everything it exposes is derived from Items, PerPage and the anchor cursor. It mirrors Illuminate\Pagination\ CursorPaginator, minus URLs, views and the Arrayable/Jsonable idiom adapters.

Items is the page as it should be displayed: at most PerPage rows, in display order. For a backwards fetch the scan order is reversed here so the caller never sees it.

func NewCursorPaginator

func NewCursorPaginator(items []map[string]any, perPage int, cursor Cursor, hasCursor bool, parameters []string) CursorPaginator

NewCursorPaginator builds the page result. It clamps perPage to >= 1, records whether the probe row indicates more (hasMore = len(items) > perPage), truncates the probe row BEFORE any reversal (the dropped row is the extra row in the scan direction), and, when a real cursor points to previous items, reverses the page so it reads front-to-back. The next cursor is minted from the last displayed row and the previous cursor from the first, each only when its end-of-page rule says it exists.

func (CursorPaginator) HasMorePages

func (p CursorPaginator) HasMorePages() bool

HasMorePages reports whether another page exists in the fetch direction. A backwards page always has a next page (it is travelling back towards where it came from), which is why the last branch does not consult hasMore.

func (CursorPaginator) HasPages

func (p CursorPaginator) HasPages() bool

HasPages reports whether more than one page could be navigated to.

func (CursorPaginator) NextCursor

func (p CursorPaginator) NextCursor() (Cursor, bool)

NextCursor returns the forward cursor over the last displayed row, and whether it exists.

func (CursorPaginator) NextCursorEncoded

func (p CursorPaginator) NextCursorEncoded() (string, bool, error)

NextCursorEncoded returns the encoded forward cursor and whether it exists. A cursor-minting failure (an ordered column absent from the row) is returned here rather than hidden behind the boolean.

func (CursorPaginator) OnFirstPage

func (p CursorPaginator) OnFirstPage() bool

OnFirstPage reports whether the page is the first in the result set.

func (CursorPaginator) OnLastPage

func (p CursorPaginator) OnLastPage() bool

OnLastPage reports whether the page is the last in the result set.

func (CursorPaginator) PreviousCursor

func (p CursorPaginator) PreviousCursor() (Cursor, bool)

PreviousCursor returns the backward cursor over the first displayed row, and whether it exists.

func (CursorPaginator) PreviousCursorEncoded

func (p CursorPaginator) PreviousCursorEncoded() (string, bool, error)

PreviousCursorEncoded returns the encoded backward cursor and whether it exists. See NextCursorEncoded for the error contract.

func (CursorPaginator) ToMap

func (p CursorPaginator) ToMap() map[string]any

ToMap renders the page as Laravel's cursor-pagination JSON shape: data, per_page, next_cursor and prev_cursor only. There is no total (this path never counts), no path and no URLs (those are transport, and the caller owns its router). A cursor end that does not exist, or that failed to mint, is emitted as nil.

type CursorParameter

type CursorParameter struct {
	// Column is the ORDER BY column name as the query knows it, not the alias and not the SELECT
	// expression.
	Column string
	// Value is the sort key of the anchor row for Column. Scalars are expected; nested objects and
	// arrays are rejected by the codec.
	Value any
}

CursorParameter is one ordered column/value pair of a cursor.

type CursorParameters

type CursorParameters []CursorParameter

CursorParameters is the ordered list of a cursor's column/value pairs. Duplicate columns are rejected at encode time; a later entry would silently shadow an earlier one.

type Expression

type Expression = core.Expression

func Raw

func Raw(value string) Expression

type Grammar

type Grammar = grammars.Grammar

These aliases preserve the builder API while dialect implementations live in grammars.

func NewGrammar

func NewGrammar(driver, prefix string) (Grammar, bool)

type GrammarJoin

type GrammarJoin = core.Join

type GrammarQuery

type GrammarQuery = core.Query

type IndexHint

type IndexHint = core.IndexHint

IndexHint mirrors Illuminate\Database\Query\IndexHint.

type JoinClause

type JoinClause struct {
	*Builder

	// Type is the join type: inner, left, right, cross or lateral.
	Type string
	// Table is the joined table: a string or an Expression.
	Table any
	// contains filtered or unexported fields
}

JoinClause is a builder specialised to a join. It embeds *Builder, mirroring PHP's `class JoinClause extends Builder`, so on clauses are stored in the same where descriptors and compiled by the same compileWheres. Because isJoinClause is set, that compilation emits `on ...` instead of `where ...`, and whereNested strips three characters rather than six.

func NewJoinClause

func NewJoinClause(parent *Builder, typ string, table any) *JoinClause

NewJoinClause creates a join clause bound to the parent's grammar.

func NewJoinLateralClause

func NewJoinLateralClause(parent *Builder, typ string, table any) *JoinClause

NewJoinLateralClause creates a lateral join clause. Mirrors Builder::newJoinLateralClause(), which builds a JoinLateralClause rather than a plain JoinClause.

func (*JoinClause) IsLateral

func (j *JoinClause) IsLateral() bool

func (*JoinClause) JoinTable

func (j *JoinClause) JoinTable() any

func (*JoinClause) JoinType

func (j *JoinClause) JoinType() string

func (*JoinClause) On

func (j *JoinClause) On(first any, operator any, second any, boolean string) *JoinClause

On adds an on clause. Mirrors JoinClause::on(): a callback becomes a nested where, anything else is a column comparison.

func (*JoinClause) OrOn

func (j *JoinClause) OrOn(first any, operator any, second any) *JoinClause

OrOn adds an "or on" clause. Mirrors JoinClause::orOn().

type Processor

type Processor = processors.Processor

func NewProcessor

func NewProcessor(driver string) Processor

NewProcessor selects the connection's post-processor, mirroring Laravel's getDefaultPostProcessor.

type State

type State = core.State

type UnitEnum

type UnitEnum = core.UnitEnum

UnitEnum is implemented by an enum type whose cases are identified by name: the Go counterpart of a PHP pure enum (UnitEnum). Go has no enum construct, so a type opts in by implementing EnumName, and CastBinding then binds a case as its name.

Directories

Path Synopsis
Package core defines the shared query representation and value utilities used by builders, SQL grammars and execution adapters.
Package core defines the shared query representation and value utilities used by builders, SQL grammars and execution adapters.

Jump to

Keyboard shortcuts

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