Documentation
¶
Index ¶
- Constants
- Variables
- func CanonicalDialect(driver string) string
- func CastBinding(value any) any
- func CleanBindings(values []any) []any
- func ExpressionValue(value any) string
- func FlattenValue(value any) any
- func IsExpression(value any) bool
- func IsQueryable(value any) bool
- func ReplacePlaceholders(sql, driver string) string
- func UnrecognisedDriverWarning(driver string) error
- type BackedEnum
- type BaseGrammar
- type Builder
- func (b *Builder) AddArrayOfWheres(column any, boolean string) *Builder
- func (b *Builder) AddBinding(value any, typ string) error
- func (b *Builder) AddNestedHavingQuery(query *Builder, boolean string) *Builder
- func (b *Builder) AddNestedWhereQuery(query *Builder, boolean string) *Builder
- func (b *Builder) AddSelect(columns ...any) *Builder
- func (b *Builder) AddWhereExistsQuery(query *Builder, boolean string, not bool) *Builder
- func (b *Builder) AfterQuery(callback func(any) any) *Builder
- func (b *Builder) Aggregate() *core.Aggregate
- func (b *Builder) ApplyAfterQueryCallbacks(result any) any
- func (b *Builder) ApplyBeforeQueryCallbacks()
- func (b *Builder) BeforeQuery(callback func(*Builder) *Builder) *Builder
- func (b *Builder) Bindings() map[string][]any
- func (b *Builder) ClearDistinct()
- func (b *Builder) Clone() *Builder
- func (b *Builder) CloneForGrammar() GrammarQuery
- func (b *Builder) CloneWithout(components ...string) *Builder
- func (b *Builder) CloneWithoutBindings(except ...string) *Builder
- func (b *Builder) CrossJoin(table any, first any, operator any, second any) *Builder
- func (b *Builder) CrossJoinSub(query any, as string) *Builder
- func (b *Builder) CursorPaginate(perPage int, cursor *Cursor) (CursorPaginator, error)
- func (b *Builder) DecrementEach(columns any, extra ...core.UpdateValue) *Builder
- func (b *Builder) Distinct(columns ...any) *Builder
- func (b *Builder) DistinctColumns() []any
- func (b *Builder) DistinctFlag() bool
- func (b *Builder) Driver() string
- func (b *Builder) DynamicWhere(method string, parameters []any) *Builder
- func (b *Builder) Error() error
- func (b *Builder) ForNestedWhere() *Builder
- func (b *Builder) ForPage(page int, perPage ...int) *Builder
- func (b *Builder) ForPageAfterId(perPage int, lastID any, column string) *Builder
- func (b *Builder) ForPageBeforeId(perPage int, lastID any, column string) *Builder
- func (b *Builder) ForSubQuery() *Builder
- func (b *Builder) ForceIndex(index string) *Builder
- func (b *Builder) From(table any, as string) *Builder
- func (b *Builder) FromRaw(expression string, bindings []any) *Builder
- func (b *Builder) FromSub(query any, as string) *Builder
- func (b *Builder) GetBindings() []any
- func (b *Builder) GetColumns() []string
- func (b *Builder) GetCountForPagination(columns ...any) (string, []any)
- func (b *Builder) GetGrammar() Grammar
- func (b *Builder) GetLimit() *int
- func (b *Builder) GetOffset() *int
- func (b *Builder) GetProcessor() Processor
- func (b *Builder) GetRawBindings() map[string][]any
- func (b *Builder) Grammar() Grammar
- func (b *Builder) GroupBy(groups ...any) *Builder
- func (b *Builder) GroupByRaw(sql string, bindings []any) *Builder
- func (b *Builder) GroupLimit(value int, column string) *Builder
- func (b *Builder) HasAfterQueryCallbacks() bool
- func (b *Builder) Having(column any, args ...any) *Builder
- func (b *Builder) HavingBetween(column any, values []any, boolean string, not bool) *Builder
- func (b *Builder) HavingNested(callback func(*Builder) *Builder, boolean string) *Builder
- func (b *Builder) HavingNotNull(columns any, boolean string) *Builder
- func (b *Builder) HavingNull(columns any, boolean string, not bool) *Builder
- func (b *Builder) HavingRaw(sql string, bindings []any, boolean string) *Builder
- func (b *Builder) IgnoreIndex(index string) *Builder
- func (b *Builder) InRandomOrder(seed any) *Builder
- func (b *Builder) IncrementEach(columns any, extra ...core.UpdateValue) *Builder
- func (b *Builder) InsertGetID(connection processors.Connection, values any, sequence string) (any, error)
- func (b *Builder) InsertOrIgnoreUsing(columns []any, query any) *Builder
- func (b *Builder) InsertUsing(columns []any, query any) *Builder
- func (b *Builder) InvalidOperator(operator any) bool
- func (b *Builder) InvalidOperatorAndValue(operator, value any) bool
- func (b *Builder) IsBitwiseOperator(operator string) bool
- func (b *Builder) IsJoinClause() bool
- func (b *Builder) Join(table any, first any, operator any, second any, typ string, where bool) *Builder
- func (b *Builder) JoinLateral(query any, as string, typ string) *Builder
- func (b *Builder) JoinRaw(expression string, bindings []any, typ string) *Builder
- func (b *Builder) JoinSub(query any, as string, first any, operator any, second any, typ string, ...) *Builder
- func (b *Builder) JoinWhere(table any, first any, operator any, second any, typ string) *Builder
- func (b *Builder) Latest(column string) *Builder
- func (b *Builder) LeftJoin(table any, first any, operator any, second any) *Builder
- func (b *Builder) LeftJoinLateral(query any, as string) *Builder
- func (b *Builder) LeftJoinSub(query any, as string, first any, operator any, second any) *Builder
- func (b *Builder) LeftJoinWhere(table, first, operator, second any) *Builder
- func (b *Builder) Limit(value int) *Builder
- func (b *Builder) LimitValue() (int, bool)
- func (b *Builder) Lock(value any) *Builder
- func (b *Builder) LockForUpdate() *Builder
- func (b *Builder) MergeBindings(other *Builder)
- func (b *Builder) MergeWheres(wheres []core.Where, bindings []any) *Builder
- func (b *Builder) NewQuery() *Builder
- func (b *Builder) Offset(value int) *Builder
- func (b *Builder) OffsetValue() (int, bool)
- func (b *Builder) Oldest(column string) *Builder
- func (b *Builder) OrHaving(column any, args ...any) *Builder
- func (b *Builder) OrHavingNotNull(columns any) *Builder
- func (b *Builder) OrHavingNull(columns any) *Builder
- func (b *Builder) OrHavingRaw(sql string, bindings []any) *Builder
- func (b *Builder) OrWhere(column any, args ...any) *Builder
- func (b *Builder) OrWhereAfterToday(columns any) *Builder
- func (b *Builder) OrWhereAll(columns []any, args ...any) *Builder
- func (b *Builder) OrWhereAny(columns []any, args ...any) *Builder
- func (b *Builder) OrWhereBeforeToday(columns any) *Builder
- func (b *Builder) OrWhereBetween(column any, values []any) *Builder
- func (b *Builder) OrWhereBetweenColumns(column any, values []any) *Builder
- func (b *Builder) OrWhereColumn(first any, operator any, second any) *Builder
- func (b *Builder) OrWhereDate(column any, args ...any) *Builder
- func (b *Builder) OrWhereDay(column any, args ...any) *Builder
- func (b *Builder) OrWhereExists(callback any) *Builder
- func (b *Builder) OrWhereFullText(columns any, value string, options []string) *Builder
- func (b *Builder) OrWhereFuture(columns any) *Builder
- func (b *Builder) OrWhereIn(column any, values any) *Builder
- func (b *Builder) OrWhereIntegerInRaw(column any, values []any) *Builder
- func (b *Builder) OrWhereIntegerNotInRaw(column any, values []any) *Builder
- func (b *Builder) OrWhereJsonContains(column string, value any) *Builder
- func (b *Builder) OrWhereJsonContainsKey(column string) *Builder
- func (b *Builder) OrWhereJsonDoesntContain(column string, value any) *Builder
- func (b *Builder) OrWhereJsonDoesntContainKey(column string) *Builder
- func (b *Builder) OrWhereJsonDoesntOverlap(column string, value any) *Builder
- func (b *Builder) OrWhereJsonLength(column string, args ...any) *Builder
- func (b *Builder) OrWhereJsonOverlaps(column string, value any) *Builder
- func (b *Builder) OrWhereLike(column any, value string, caseSensitive bool) *Builder
- func (b *Builder) OrWhereMonth(column any, args ...any) *Builder
- func (b *Builder) OrWhereNone(columns []any, args ...any) *Builder
- func (b *Builder) OrWhereNot(column any, args ...any) *Builder
- func (b *Builder) OrWhereNotBetween(column any, values []any) *Builder
- func (b *Builder) OrWhereNotBetweenColumns(column any, values []any) *Builder
- func (b *Builder) OrWhereNotExists(query any) *Builder
- func (b *Builder) OrWhereNotIn(column any, values any) *Builder
- func (b *Builder) OrWhereNotLike(column any, value string, caseSensitive bool) *Builder
- func (b *Builder) OrWhereNotNull(column any) *Builder
- func (b *Builder) OrWhereNowOrFuture(columns any) *Builder
- func (b *Builder) OrWhereNowOrPast(columns any) *Builder
- func (b *Builder) OrWhereNull(column any) *Builder
- func (b *Builder) OrWherePast(columns any) *Builder
- func (b *Builder) OrWhereRaw(sql any, bindings []any) *Builder
- func (b *Builder) OrWhereRowValues(columns []any, operator string, values []any) *Builder
- func (b *Builder) OrWhereTime(column any, args ...any) *Builder
- func (b *Builder) OrWhereToday(columns any) *Builder
- func (b *Builder) OrWhereTodayOrAfter(columns any) *Builder
- func (b *Builder) OrWhereTodayOrBefore(columns any) *Builder
- func (b *Builder) OrWhereValueBetween(value any, columns []any) *Builder
- func (b *Builder) OrWhereValueNotBetween(value any, columns []any) *Builder
- func (b *Builder) OrWhereYear(column any, args ...any) *Builder
- func (b *Builder) OrderBy(column any, direction string) *Builder
- func (b *Builder) OrderByDesc(column any) *Builder
- func (b *Builder) OrderByRaw(sql string, bindings []any) *Builder
- func (b *Builder) Pipe(callback func(*Builder) any) any
- func (b *Builder) PrepareValueAndOperator(value, operator any, useDefault bool) (any, any, error)
- func (b *Builder) Processor() Processor
- func (b *Builder) Raw(value string) Expression
- func (b *Builder) RawBindings(typ string) []any
- func (b *Builder) RebindGrammar(grammar Grammar, processor Processor, driver string) *Builder
- func (b *Builder) RemoveExistingOrdersFor(column string) []core.Order
- func (b *Builder) Reorder(column any, direction string) *Builder
- func (b *Builder) ReorderDesc(column any) *Builder
- func (b *Builder) RightJoin(table any, first any, operator any, second any) *Builder
- func (b *Builder) RightJoinSub(query any, as string, first any, operator any, second any) *Builder
- func (b *Builder) RightJoinWhere(table, first, operator, second any) *Builder
- func (b *Builder) Select(columns ...any) *Builder
- func (b *Builder) SelectRaw(expression string, bindings []any) *Builder
- func (b *Builder) SelectSub(query any, as string) *Builder
- func (b *Builder) Selects() []any
- func (b *Builder) SetAggregate(function string, columns []any)
- func (b *Builder) SetBindings(values []any, typ string) error
- func (b *Builder) SetDriver(driver string)
- func (b *Builder) SetError(err error)
- func (b *Builder) SetSelects(columns []any)
- func (b *Builder) SetUseUpsertAlias(alias bool)
- func (b *Builder) SharedLock() *Builder
- func (b *Builder) Skip(value int) *Builder
- func (b *Builder) State() *State
- func (b *Builder) TableSource() any
- func (b *Builder) Take(value int) *Builder
- func (b *Builder) Tap(callback func(*Builder)) *Builder
- func (b *Builder) ToAggregateSQL(aggregate core.Aggregate) (string, []any)
- func (b *Builder) ToDeleteSQL() (string, []any)
- func (b *Builder) ToExistsSQL() (string, []any)
- func (b *Builder) ToInsertGetIdSQL(values any, sequence string) (string, []any)
- func (b *Builder) ToInsertOrIgnoreSQL(values []map[string]any) (string, []any)
- func (b *Builder) ToInsertOrIgnoreUsingSQL() (string, []any)
- func (b *Builder) ToInsertSQL(values []map[string]any) (string, []any)
- func (b *Builder) ToInsertUsingSQL() (string, []any)
- func (b *Builder) ToSQL() string
- func (b *Builder) ToSelectSQL() (string, []any)
- func (b *Builder) ToTruncateSQL() []core.Statement
- func (b *Builder) ToUpdateFromSQL(values any) (string, []any)
- func (b *Builder) ToUpdateSQL(values any) (string, []any)
- func (b *Builder) ToUpsertSQL(values []map[string]any, uniqueBy []string, update []core.UpsertUpdate) (string, []any)
- func (b *Builder) Union(query any, all bool) *Builder
- func (b *Builder) UnionAll(query any) *Builder
- func (b *Builder) Unless(value any, callback func(*Builder, any) *Builder, ...) *Builder
- func (b *Builder) UpdateValues() core.UpdateValues
- func (b *Builder) UseIndex(index string) *Builder
- func (b *Builder) When(value any, callback func(*Builder, any) *Builder, ...) *Builder
- func (b *Builder) Where(column any, args ...any) *Builder
- func (b *Builder) WhereAfterToday(columns any) *Builder
- func (b *Builder) WhereAll(columns []any, operator any, value any, boolean string) *Builder
- func (b *Builder) WhereAny(columns []any, operator any, value any, boolean string) *Builder
- func (b *Builder) WhereBeforeToday(columns any) *Builder
- func (b *Builder) WhereBetween(column any, values []any, boolean string, not bool) *Builder
- func (b *Builder) WhereBetweenColumns(column any, values []any, boolean string, not bool) *Builder
- func (b *Builder) WhereColumn(first any, operator any, second any, boolean string) *Builder
- func (b *Builder) WhereDate(column any, args ...any) *Builder
- func (b *Builder) WhereDay(column any, args ...any) *Builder
- func (b *Builder) WhereExists(callback any, boolean string, not bool) *Builder
- func (b *Builder) WhereFullText(columns any, value string, options []string, boolean string) *Builder
- func (b *Builder) WhereFuture(columns any) *Builder
- func (b *Builder) WhereIn(column any, values any, boolean string, not bool) *Builder
- func (b *Builder) WhereIntegerInRaw(column any, values []any, boolean string, not bool) *Builder
- func (b *Builder) WhereIntegerNotInRaw(column any, values []any, boolean string) *Builder
- func (b *Builder) WhereJsonContains(column string, value any, boolean string, not bool) *Builder
- func (b *Builder) WhereJsonContainsKey(column string, boolean string, not bool) *Builder
- func (b *Builder) WhereJsonDoesntContain(column string, value any, boolean string) *Builder
- func (b *Builder) WhereJsonDoesntContainKey(column string, boolean string) *Builder
- func (b *Builder) WhereJsonDoesntOverlap(column string, value any, boolean string) *Builder
- func (b *Builder) WhereJsonLength(column string, args ...any) *Builder
- func (b *Builder) WhereJsonOverlaps(column string, value any, boolean string, not bool) *Builder
- func (b *Builder) WhereLike(column any, value string, caseSensitive bool, boolean string, not bool) *Builder
- func (b *Builder) WhereMonth(column any, args ...any) *Builder
- func (b *Builder) WhereNested(callback func(*Builder) *Builder, boolean string) *Builder
- func (b *Builder) WhereNone(columns []any, operator any, value any, boolean string) *Builder
- func (b *Builder) WhereNot(column any, args ...any) *Builder
- func (b *Builder) WhereNotBetween(column any, values []any, boolean string) *Builder
- func (b *Builder) WhereNotBetweenColumns(column any, values []any, boolean string) *Builder
- func (b *Builder) WhereNotExists(callback any, boolean string) *Builder
- func (b *Builder) WhereNotIn(column any, values any, boolean string) *Builder
- func (b *Builder) WhereNotLike(column any, value string, caseSensitive bool, boolean string) *Builder
- func (b *Builder) WhereNotNull(columns any, boolean string) *Builder
- func (b *Builder) WhereNowOrFuture(columns any) *Builder
- func (b *Builder) WhereNowOrPast(columns any) *Builder
- func (b *Builder) WhereNull(columns any, boolean string, not bool) *Builder
- func (b *Builder) WherePast(columns any) *Builder
- func (b *Builder) WhereRaw(sql any, bindings []any, boolean string) *Builder
- func (b *Builder) WhereRowValues(columns []any, operator string, values []any, boolean ...string) *Builder
- func (b *Builder) WhereSub(column any, operator any, callback any, boolean string) *Builder
- func (b *Builder) WhereTime(column any, args ...any) *Builder
- func (b *Builder) WhereToday(columns any, boolean string) *Builder
- func (b *Builder) WhereTodayOrAfter(columns any) *Builder
- func (b *Builder) WhereTodayOrBefore(columns any) *Builder
- func (b *Builder) WhereValueBetween(value any, columns []any, boolean string, not bool) *Builder
- func (b *Builder) WhereValueNotBetween(value any, columns []any, boolean string) *Builder
- func (b *Builder) WhereYear(column any, args ...any) *Builder
- type Cursor
- type CursorPaginator
- func (p CursorPaginator) HasMorePages() bool
- func (p CursorPaginator) HasPages() bool
- func (p CursorPaginator) NextCursor() (Cursor, bool)
- func (p CursorPaginator) NextCursorEncoded() (string, bool, error)
- func (p CursorPaginator) OnFirstPage() bool
- func (p CursorPaginator) OnLastPage() bool
- func (p CursorPaginator) PreviousCursor() (Cursor, bool)
- func (p CursorPaginator) PreviousCursorEncoded() (string, bool, error)
- func (p CursorPaginator) ToMap() map[string]any
- type CursorParameter
- type CursorParameters
- type Expression
- type Grammar
- type GrammarJoin
- type GrammarQuery
- type IndexHint
- type JoinClause
- type Processor
- type State
- type UnitEnum
Constants ¶
const ( DialectMySQL = core.DialectMySQL DialectPostgres = core.DialectPostgres DialectSqlite = core.DialectSqlite DialectSqlServer = core.DialectSqlServer )
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.
const DefaultCursorName = "cursor"
DefaultCursorName is the query-parameter name a cursor travels under, mirroring Laravel's CursorPaginator::$cursorName default.
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 ¶
var BindingTypes = core.BindingTypes
var SelectComponents = grammars.SelectComponents
Functions ¶
func CanonicalDialect ¶
func CastBinding ¶
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 ¶
CleanBindings drops expressions and casts the rest. Mirrors Builder::cleanBindings().
func ExpressionValue ¶
func FlattenValue ¶
FlattenValue collapses a slice to its first scalar. Mirrors Builder::flattenValue().
func IsExpression ¶
func IsQueryable ¶
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 ¶
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 ¶
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) AddArrayOfWheres ¶
AddArrayOfWheres expands an array first argument under an explicit boolean. Mirrors Builder::addArrayOfWheres() (Query/Builder.php:928), reached from where()'s is_array branch (Query/Builder.php:823); the ORM's Eloquent level needs it because Eloquent's whereNot is where($column, $operator, $value, $boolean.' not') (Eloquent Builder.php:407), so its array form arrives here as where(array, 'and not') and every column entry is negated inside the one nested group — `and not (not "b" = ? and not "c" = ?)`. (The raw builder's own WhereNot deliberately keeps Query\Builder::whereNot's shape, which nests twice: `and not (("b" = ? and "c" = ?))`.)
func (*Builder) AddBinding ¶
AddBinding appends a binding for one component. Mirrors Builder::addBinding().
func (*Builder) AddNestedHavingQuery ¶
AddNestedHavingQuery adds a builder as a nested having. Mirrors Builder::addNestedHavingQuery().
func (*Builder) AddNestedWhereQuery ¶
AddNestedWhereQuery adds a builder as a nested where. Mirrors Builder::addNestedWhereQuery().
func (*Builder) AddSelect ¶
AddSelect appends columns without clearing the list. Mirrors Builder::addSelect().
func (*Builder) AddWhereExistsQuery ¶
AddWhereExistsQuery adds a builder as an exists clause. Mirrors Builder::addWhereExistsQuery().
func (*Builder) AfterQuery ¶
AfterQuery registers a result transformation. Like Laravel, callbacks survive execution and a false-like callback result retains the preceding result.
func (*Builder) ApplyAfterQueryCallbacks ¶
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 ¶
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) ClearDistinct ¶
func (b *Builder) ClearDistinct()
ClearDistinct clears both distinct flags.
func (*Builder) Clone ¶
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 ¶
CloneWithout clones the builder with the named components cleared. Mirrors Builder::cloneWithout().
func (*Builder) CloneWithoutBindings ¶
CloneWithoutBindings clones the builder with the named binding components emptied. Mirrors Builder::cloneWithoutBindings().
func (*Builder) CrossJoinSub ¶
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 ¶
Distinct sets distinct, or distinct-on columns. Mirrors Builder::distinct().
func (*Builder) DistinctColumns ¶
DistinctColumns returns the distinct-on columns.
func (*Builder) DistinctFlag ¶
DistinctFlag reports whether distinct is set.
func (*Builder) Driver ¶
Driver returns the dialect name the builder was created for, if one was recorded.
func (*Builder) DynamicWhere ¶
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) ForNestedWhere ¶
ForNestedWhere creates a nested builder seeded with the parent's from. Mirrors Builder::forNestedWhere().
func (*Builder) ForPage ¶
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 ¶
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 ¶
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 ¶
ForSubQuery mirrors Builder::forSubQuery().
func (*Builder) ForceIndex ¶
ForceIndex forces an index. Mirrors Builder::forceIndex().
func (*Builder) From ¶
From sets the table, or a subquery when table is queryable. Mirrors Builder::from().
func (*Builder) GetBindings ¶
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 (*Builder) GetCountForPagination ¶
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 (*Builder) GetProcessor ¶
func (*Builder) GetRawBindings ¶
func (*Builder) GroupByRaw ¶
GroupByRaw appends a raw grouping expression. Mirrors Builder::groupByRaw().
func (*Builder) GroupLimit ¶
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 (*Builder) HavingBetween ¶
HavingBetween adds a having between clause. Mirrors Builder::havingBetween().
func (*Builder) HavingNested ¶
HavingNested nests having clauses. Mirrors Builder::havingNested().
func (*Builder) HavingNotNull ¶
HavingNotNull adds a having not null clause. Mirrors Builder::havingNotNull().
func (*Builder) HavingNull ¶
HavingNull adds a having null clause. Mirrors Builder::havingNull().
func (*Builder) IgnoreIndex ¶
IgnoreIndex ignores an index. Mirrors Builder::ignoreIndex().
func (*Builder) InRandomOrder ¶
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 ¶
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 ¶
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 ¶
InvalidOperator mirrors Builder::invalidOperator().
func (*Builder) InvalidOperatorAndValue ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
JoinWhere adds a join with the condition in the where clause. Mirrors Builder::joinWhere().
func (*Builder) LeftJoinLateral ¶
LeftJoinLateral adds a lateral left join. Mirrors Builder::leftJoinLateral(), which is joinLateral($query, $as, 'left').
func (*Builder) LeftJoinSub ¶
LeftJoinSub adds a left subquery join. Mirrors Builder::leftJoinSub().
func (*Builder) LeftJoinWhere ¶
LeftJoinWhere mirrors Laravel's leftJoinWhere.
func (*Builder) Limit ¶
Limit sets the limit, or the union limit while unions exist. Mirrors Builder::limit().
func (*Builder) LimitValue ¶
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) LockForUpdate ¶
LockForUpdate locks for update. Mirrors Builder::lockForUpdate().
func (*Builder) MergeBindings ¶
MergeBindings merges another builder's bindings. Mirrors Builder::mergeBindings().
func (*Builder) MergeWheres ¶
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 ¶
NewQuery mirrors Builder::newQuery(): a fresh builder sharing the grammar, processor, and dialect.
func (*Builder) Offset ¶
Offset sets the offset, or the union offset while unions exist. Mirrors Builder::offset().
func (*Builder) OffsetValue ¶
OffsetValue reports the offset set on the builder, mirroring Builder::getOffset(). The bool is false when no offset was set.
func (*Builder) OrHavingNotNull ¶
OrHavingNotNull mirrors Laravel's orHavingNotNull.
func (*Builder) OrHavingNull ¶
OrHavingNull mirrors Laravel's orHavingNull.
func (*Builder) OrHavingRaw ¶
OrHavingRaw adds a raw having clause joined with "or". Mirrors Builder::orHavingRaw(), which is havingRaw() with the or boolean.
func (*Builder) OrWhereAfterToday ¶
OrWhereAfterToday mirrors Laravel's orWhereAfterToday.
func (*Builder) OrWhereAll ¶
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 ¶
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 ¶
OrWhereBeforeToday mirrors Laravel's orWhereBeforeToday.
func (*Builder) OrWhereBetween ¶
OrWhereBetween adds a "between" clause with "or". Mirrors Builder::orWhereBetween().
func (*Builder) OrWhereBetweenColumns ¶
OrWhereBetweenColumns mirrors Laravel's orWhereBetweenColumns.
func (*Builder) OrWhereColumn ¶
OrWhereColumn compares two columns with "or". Mirrors Builder::orWhereColumn().
func (*Builder) OrWhereDate ¶
OrWhereDate mirrors Laravel's orWhereDate.
func (*Builder) OrWhereDay ¶
OrWhereDay adds an "or where day" statement. Mirrors Builder::orWhereDay().
func (*Builder) OrWhereExists ¶
OrWhereExists adds an exists clause with "or". Mirrors Builder::orWhereExists().
func (*Builder) OrWhereFullText ¶
OrWhereFullText mirrors Laravel's orWhereFullText.
func (*Builder) OrWhereFuture ¶
OrWhereFuture adds an "or where" clause testing whether a date column is in the future. Mirrors Builder::orWhereFuture().
func (*Builder) OrWhereIntegerInRaw ¶
OrWhereIntegerInRaw mirrors Laravel's orWhereIntegerInRaw.
func (*Builder) OrWhereIntegerNotInRaw ¶
OrWhereIntegerNotInRaw mirrors Laravel's orWhereIntegerNotInRaw.
func (*Builder) OrWhereJsonContains ¶
OrWhereJsonContains adds a JSON "contains" clause with "or". Mirrors Builder::orWhereJsonContains().
func (*Builder) OrWhereJsonContainsKey ¶
OrWhereJsonContainsKey adds a JSON key existence clause with "or". Mirrors Builder::orWhereJsonContainsKey().
func (*Builder) OrWhereJsonDoesntContain ¶
OrWhereJsonDoesntContain adds a JSON "doesn't contain" clause with "or". Mirrors Builder::orWhereJsonDoesntContain().
func (*Builder) OrWhereJsonDoesntContainKey ¶
OrWhereJsonDoesntContainKey adds an "or" clause that determines if a JSON path does not exist. Mirrors Builder::orWhereJsonDoesntContainKey().
func (*Builder) OrWhereJsonDoesntOverlap ¶
OrWhereJsonDoesntOverlap mirrors Laravel's orWhereJsonDoesntOverlap.
func (*Builder) OrWhereJsonLength ¶
OrWhereJsonLength compares a JSON array length with "or". Mirrors Builder::orWhereJsonLength().
func (*Builder) OrWhereJsonOverlaps ¶
OrWhereJsonOverlaps mirrors Laravel's orWhereJsonOverlaps.
func (*Builder) OrWhereLike ¶
OrWhereLike mirrors Laravel's orWhereLike.
func (*Builder) OrWhereMonth ¶
OrWhereMonth adds an "or where month" statement. Mirrors Builder::orWhereMonth().
func (*Builder) OrWhereNone ¶
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 ¶
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 ¶
OrWhereNotBetween mirrors Laravel's orWhereNotBetween.
func (*Builder) OrWhereNotBetweenColumns ¶
OrWhereNotBetweenColumns mirrors Laravel's orWhereNotBetweenColumns.
func (*Builder) OrWhereNotExists ¶
OrWhereNotExists mirrors Laravel's orWhereNotExists.
func (*Builder) OrWhereNotIn ¶
OrWhereNotIn adds a "not in" clause with "or". Mirrors Builder::orWhereNotIn().
func (*Builder) OrWhereNotLike ¶
OrWhereNotLike mirrors Laravel's orWhereNotLike.
func (*Builder) OrWhereNotNull ¶
OrWhereNotNull adds a "is not null" clause with "or". Mirrors Builder::orWhereNotNull().
func (*Builder) OrWhereNowOrFuture ¶
OrWhereNowOrFuture mirrors Laravel's orWhereNowOrFuture.
func (*Builder) OrWhereNowOrPast ¶
OrWhereNowOrPast mirrors Laravel's orWhereNowOrPast.
func (*Builder) OrWhereNull ¶
OrWhereNull adds a "is null" clause with "or". Mirrors Builder::orWhereNull().
func (*Builder) OrWherePast ¶
OrWherePast adds an "or where" clause testing whether a date column is in the past. Mirrors Builder::orWherePast().
func (*Builder) OrWhereRaw ¶
OrWhereRaw adds a raw where clause with "or". Mirrors Builder::orWhereRaw().
func (*Builder) OrWhereRowValues ¶
OrWhereRowValues adds an "or" tuple comparison. Mirrors Builder::orWhereRowValues().
func (*Builder) OrWhereTime ¶
OrWhereTime adds an "or where time" statement. Mirrors Builder::orWhereTime().
func (*Builder) OrWhereToday ¶
OrWhereToday adds an "or where date = today" clause. Mirrors Builder::orWhereToday().
func (*Builder) OrWhereTodayOrAfter ¶
OrWhereTodayOrAfter mirrors Laravel's orWhereTodayOrAfter.
func (*Builder) OrWhereTodayOrBefore ¶
OrWhereTodayOrBefore mirrors Laravel's orWhereTodayOrBefore.
func (*Builder) OrWhereValueBetween ¶
OrWhereValueBetween mirrors Laravel's orWhereValueBetween.
func (*Builder) OrWhereValueNotBetween ¶
OrWhereValueNotBetween mirrors Laravel's orWhereValueNotBetween.
func (*Builder) OrWhereYear ¶
OrWhereYear adds an "or where year" statement. Mirrors Builder::orWhereYear().
func (*Builder) OrderByDesc ¶
OrderByDesc adds a descending order clause. Mirrors Builder::orderByDesc().
func (*Builder) OrderByRaw ¶
OrderByRaw adds a raw order clause. Mirrors Builder::orderByRaw().
func (*Builder) Pipe ¶
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 ¶
PrepareValueAndOperator mirrors Builder::prepareValueAndOperator().
func (*Builder) Raw ¶
func (b *Builder) Raw(value string) Expression
func (*Builder) RawBindings ¶
RawBindings returns the bindings for one component.
func (*Builder) RebindGrammar ¶
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 ¶
RemoveExistingOrdersFor drops orders on one column. Mirrors Builder::removeExistingOrdersFor().
func (*Builder) Reorder ¶
Reorder clears ordering then optionally adds one. Mirrors Builder::reorder().
func (*Builder) ReorderDesc ¶
ReorderDesc mirrors Laravel's reorderDesc.
func (*Builder) RightJoinSub ¶
RightJoinSub adds a right subquery join. Mirrors Builder::rightJoinSub().
func (*Builder) RightJoinWhere ¶
RightJoinWhere mirrors Laravel's rightJoinWhere.
func (*Builder) Select ¶
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) SelectSub ¶
SelectSub adds a subselect aliased as `as`. Mirrors Builder::selectSub().
func (*Builder) SetAggregate ¶
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 ¶
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 ¶
SetDriver records the dialect name, used to convert placeholders at execution time.
func (*Builder) SetSelects ¶
SetSelects replaces the selected columns.
func (*Builder) SetUseUpsertAlias ¶
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 ¶
SharedLock takes a shared lock. Mirrors Builder::sharedLock().
func (*Builder) TableSource ¶
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) Tap ¶
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 ¶
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 ¶
ToDeleteSQL compiles a delete statement and its bindings.
func (*Builder) ToExistsSQL ¶
ToExistsSQL compiles an exists statement and its bindings.
func (*Builder) ToInsertGetIdSQL ¶
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 ¶
ToInsertOrIgnoreSQL compiles an insert that ignores conflicts.
func (*Builder) ToInsertOrIgnoreUsingSQL ¶
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 ¶
ToInsertSQL compiles an insert statement and its bindings.
func (*Builder) ToInsertUsingSQL ¶
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) ToSelectSQL ¶
ToSelectSQL compiles a select statement and its bindings.
func (*Builder) ToTruncateSQL ¶
ToTruncateSQL compiles the truncate statements. SQLite needs two.
func (*Builder) ToUpdateFromSQL ¶
ToUpdateFromSQL is PostgreSQL's explicit UPDATE ... FROM path.
func (*Builder) ToUpdateSQL ¶
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) 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) 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) WhereAfterToday ¶
WhereAfterToday mirrors Laravel's whereAfterToday.
func (*Builder) WhereAll ¶
WhereAll nests one condition repeated across columns joined by and. Mirrors Builder::whereAll().
func (*Builder) WhereAny ¶
WhereAny nests one condition repeated across columns joined by or. Mirrors Builder::whereAny().
func (*Builder) WhereBeforeToday ¶
WhereBeforeToday mirrors Laravel's whereBeforeToday.
func (*Builder) WhereBetween ¶
WhereBetween adds a "between" clause. Mirrors Builder::whereBetween().
func (*Builder) WhereBetweenColumns ¶
WhereBetweenColumns compares a column against two other columns. Mirrors Builder::whereBetweenColumns().
func (*Builder) WhereColumn ¶
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) WhereExists ¶
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 ¶
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) WhereIntegerInRaw ¶
WhereIntegerInRaw adds an "in" clause whose values are inlined, never parameterised. Mirrors Builder::whereIntegerInRaw().
func (*Builder) WhereIntegerNotInRaw ¶
WhereIntegerNotInRaw mirrors Laravel's whereIntegerNotInRaw.
func (*Builder) WhereJsonContains ¶
WhereJsonContains adds a JSON contains clause. Mirrors Builder::whereJsonContains().
func (*Builder) WhereJsonContainsKey ¶
WhereJsonContainsKey adds a JSON key existence clause. Mirrors Builder::whereJsonContainsKey().
func (*Builder) WhereJsonDoesntContain ¶
WhereJsonDoesntContain adds a JSON "doesn't contain" clause. Mirrors Builder::whereJsonDoesntContain().
func (*Builder) WhereJsonDoesntContainKey ¶
WhereJsonDoesntContainKey adds a clause that determines if a JSON path does not exist. Mirrors Builder::whereJsonDoesntContainKey().
func (*Builder) WhereJsonDoesntOverlap ¶
WhereJsonDoesntOverlap mirrors Laravel's whereJsonDoesntOverlap.
func (*Builder) WhereJsonLength ¶
WhereJsonLength compares a JSON array length. Mirrors Builder::whereJsonLength().
func (*Builder) WhereJsonOverlaps ¶
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 ¶
WhereMonth compares the month. Mirrors Builder::whereMonth().
func (*Builder) WhereNested ¶
WhereNested starts a nested where. Mirrors Builder::whereNested().
func (*Builder) WhereNone ¶
WhereNone nests one condition repeated across columns, negated. Mirrors Builder::whereNone().
func (*Builder) WhereNot ¶
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 ¶
WhereNotBetween adds a "not between" clause. Mirrors Builder::whereNotBetween().
func (*Builder) WhereNotBetweenColumns ¶
WhereNotBetweenColumns mirrors Laravel's whereNotBetweenColumns.
func (*Builder) WhereNotExists ¶
WhereNotExists adds a "not exists" clause. Mirrors Builder::whereNotExists().
func (*Builder) WhereNotIn ¶
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 ¶
WhereNotNull adds a "is not null" clause. Mirrors Builder::whereNotNull().
func (*Builder) WhereNowOrFuture ¶
WhereNowOrFuture mirrors Laravel's whereNowOrFuture.
func (*Builder) WhereNowOrPast ¶
WhereNowOrPast mirrors Laravel's whereNowOrPast.
func (*Builder) WherePast ¶
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) WhereRowValues ¶
func (b *Builder) WhereRowValues(columns []any, operator string, values []any, boolean ...string) *Builder
WhereRowValues compares tuples. Mirrors Builder::whereRowValues().
func (*Builder) WhereSub ¶
WhereSub compares a column against a sub-select. Mirrors Builder::whereSub().
func (*Builder) WhereToday ¶
WhereToday compares the date part with today's date. Mirrors Builder::whereToday().
func (*Builder) WhereTodayOrAfter ¶
WhereTodayOrAfter mirrors Laravel's whereTodayOrAfter.
func (*Builder) WhereTodayOrBefore ¶
WhereTodayOrBefore mirrors Laravel's whereTodayOrBefore.
func (*Builder) WhereValueBetween ¶
WhereValueBetween compares a value against two columns. Mirrors Builder::whereValueBetween().
func (*Builder) WhereValueNotBetween ¶
WhereValueNotBetween mirrors Laravel's whereValueNotBetween.
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 ¶
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 ¶
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) MarshalJSON ¶
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 ¶
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 ¶
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.
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 Grammar ¶
These aliases preserve the builder API while dialect implementations live in grammars.
func NewGrammar ¶
type GrammarJoin ¶
type GrammarQuery ¶
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 ¶
NewProcessor selects the connection's post-processor, mirroring Laravel's getDefaultPostProcessor.
Source Files
¶
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. |