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

grammars

package
v1.20.0-alpha.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SelectComponents = []string{
	"aggregate", "columns", "from", "indexHint", "joins", "wheres",
	"groups", "havings", "orders", "limit", "offset", "lock",
}

SelectComponents is Laravel's $selectComponents order. The grammar compiles in this order.

Functions

func AliasOf

func AliasOf(from any) string

AliasOf returns the alias or unaliased table name of a query source.

func EncodeJSON

func EncodeJSON(value any) any

EncodeJSON renders a value as JSON, mirroring PHP's json_encode for the shapes an update value can take: strings are quoted, booleans and null keep their spelling, and slices and maps recurse. It is what the grammars bind for a json-encoded update value: SQLite and Postgres array values, and every non-expression Postgres json-selector value, scalar or not.

func RemoveLeadingBoolean

func RemoveLeadingBoolean(value string) string

RemoveLeadingBoolean strips the connector from a compiled condition group.

func TableAlias

func TableAlias(from any) string

TableAlias returns the SQL alias or table name of a query source.

func UnrecognisedDriverWarning

func UnrecognisedDriverWarning(driver string) error

UnrecognisedDriverWarning returns the declared error to log for a driver NewGrammar does not recognise, and nil for a recognised driver or one already reported. Callers log the error as a warning rather than failing: the framework deliberately lets a connection carry a database/sql driver name with no dedicated grammar, because a driver module may bring its own, and such a connection runs on the base grammar. The warning names the driver and the recognised set, so a mistyped driver is signalled at configuration time instead of surfacing as base-grammar SQL at the database. It reports each driver at most once per process: the construction paths run per transaction and per query clone, where a repeating warning would be noise.

Types

type BaseGrammar

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

BaseGrammar implements the shared parts of Laravel's query grammar. Dialects embed it and override only the methods whose SQL differs. Go embedding does not dispatch virtually, so BaseGrammar keeps a self reference to the concrete dialect and routes shared logic through it.

func NewBaseGrammar

func NewBaseGrammar(prefix string) *BaseGrammar

NewBaseGrammar creates the shared grammar. Call Attach with the concrete dialect afterwards.

func (*BaseGrammar) AppendUpdateValueBinding

func (g *BaseGrammar) AppendUpdateValueBinding(out []any, value any) []any

AppendUpdateValueBinding appends one assignment's binding contribution to out. A subquery value contributes the bindings of its sub-select, spliced in at the assignment's position, which is what Grammar::prepareBindingsForUpdate()'s Arr::flatten does to the bindings closure Builder::update() stores for a query value.

func (*BaseGrammar) Attach

func (g *BaseGrammar) Attach(self Grammar)

Attach wires the concrete dialect so shared implementations reach its overrides.

func (*BaseGrammar) Columnize

func (g *BaseGrammar) Columnize(columns []any) string

Columnize joins wrapped columns with a comma. Mirrors Grammar::columnize().

func (*BaseGrammar) CompileAggregate

func (g *BaseGrammar) CompileAggregate(b core.Query, aggregate core.Aggregate) string

CompileAggregate mirrors Grammar::compileAggregate().

func (*BaseGrammar) CompileColumns

func (g *BaseGrammar) CompileColumns(b core.Query, columns []any) string

CompileColumns mirrors Grammar::compileColumns().

func (*BaseGrammar) CompileComponents

func (g *BaseGrammar) CompileComponents(b core.Query) []string

CompileComponents compiles each set component in Laravel's fixed order. Mirrors Grammar::compileComponents().

func (*BaseGrammar) CompileDelete

func (g *BaseGrammar) CompileDelete(b core.Query) string

CompileDelete mirrors Grammar::compileDelete().

func (*BaseGrammar) CompileDeleteWithJoins

func (g *BaseGrammar) CompileDeleteWithJoins(b core.Query, table string, where string) string

CompileDeleteWithJoins mirrors Grammar::compileDeleteWithJoins().

func (*BaseGrammar) CompileDeleteWithoutJoins

func (g *BaseGrammar) CompileDeleteWithoutJoins(b core.Query, table string, where string) string

CompileDeleteWithoutJoins mirrors Grammar::compileDeleteWithoutJoins().

func (*BaseGrammar) CompileExists

func (g *BaseGrammar) CompileExists(b core.Query) string

CompileExists mirrors Grammar::compileExists().

func (*BaseGrammar) CompileFrom

func (g *BaseGrammar) CompileFrom(b core.Query, table any) string

CompileFrom mirrors Grammar::compileFrom().

func (*BaseGrammar) CompileGroupLimit

func (g *BaseGrammar) CompileGroupLimit(b core.Query) string

CompileGroupLimit mirrors Grammar::compileGroupLimit().

func (*BaseGrammar) CompileGroups

func (g *BaseGrammar) CompileGroups(b core.Query, groups []any) string

CompileGroups mirrors Grammar::compileGroups().

func (*BaseGrammar) CompileHaving

func (g *BaseGrammar) CompileHaving(b core.Query, having core.Having) string

CompileHaving mirrors Grammar::compileHaving().

func (*BaseGrammar) CompileHavings

func (g *BaseGrammar) CompileHavings(b core.Query) string

CompileHavings mirrors Grammar::compileHavings().

func (*BaseGrammar) CompileIndexHint

func (g *BaseGrammar) CompileIndexHint(b core.Query, hint *core.IndexHint) string

CompileIndexHint is dialect specific. The base compiles nothing.

func (*BaseGrammar) CompileInsert

func (g *BaseGrammar) CompileInsert(b core.Query, values []map[string]any) string

CompileInsert mirrors Grammar::compileInsert().

func (*BaseGrammar) CompileInsertGetId

func (g *BaseGrammar) CompileInsertGetId(b core.Query, values []map[string]any, sequence string) string

CompileInsertGetId mirrors Grammar::compileInsertGetId(). Dialects that need a returning clause override this.

func (*BaseGrammar) CompileInsertOrIgnore

func (g *BaseGrammar) CompileInsertOrIgnore(b core.Query, values []map[string]any) string

CompileInsertOrIgnore mirrors Grammar::compileInsertOrIgnore(). The base refuses.

func (*BaseGrammar) CompileInsertOrIgnoreUsing

func (g *BaseGrammar) CompileInsertOrIgnoreUsing(b core.Query, columns []any, sql string) string

CompileInsertOrIgnoreUsing mirrors Grammar::compileInsertOrIgnoreUsing(). The base refuses.

func (*BaseGrammar) CompileInsertUsing

func (g *BaseGrammar) CompileInsertUsing(b core.Query, columns []any, sql string) string

CompileInsertUsing mirrors Grammar::compileInsertUsing().

func (*BaseGrammar) CompileInsertWithOutput

func (g *BaseGrammar) CompileInsertWithOutput(b core.Query, values []map[string]any, output string) string

CompileInsertWithOutput places a dialect's OUTPUT clause before inserted values.

func (*BaseGrammar) CompileJoinLateral

func (g *BaseGrammar) CompileJoinLateral(join core.Join, expression string) string

CompileJoinLateral mirrors Grammar::compileJoinLateral(). The base does not support lateral joins and compiles nothing; CompileJoins records errLateralJoinNotSupported, mirroring the RuntimeException the base throws.

func (*BaseGrammar) CompileJoins

func (g *BaseGrammar) CompileJoins(b core.Query, joins []core.Join) string

CompileJoins mirrors Grammar::compileJoins().

func (*BaseGrammar) CompileJsonContains

func (g *BaseGrammar) CompileJsonContains(column string, value string) string

func (*BaseGrammar) CompileJsonContainsKey

func (g *BaseGrammar) CompileJsonContainsKey(column string) string

func (*BaseGrammar) CompileJsonLength

func (g *BaseGrammar) CompileJsonLength(column string, operator string, value string) string

func (*BaseGrammar) CompileJsonOverlaps

func (g *BaseGrammar) CompileJsonOverlaps(column string, value string) string

func (*BaseGrammar) CompileJsonUpdateColumn

func (g *BaseGrammar) CompileJsonUpdateColumn(key string, value any) string

func (*BaseGrammar) CompileJsonValueCast

func (g *BaseGrammar) CompileJsonValueCast(value string) string

CompileJsonValueCast mirrors Grammar::compileJsonValueCast(). The base is an identity.

func (*BaseGrammar) CompileLegacyGroupLimit

func (g *BaseGrammar) CompileLegacyGroupLimit(b core.Query) string

CompileLegacyGroupLimit is only implemented by MySQL.

func (*BaseGrammar) CompileLimit

func (g *BaseGrammar) CompileLimit(b core.Query, limit *int) string

CompileLimit mirrors Grammar::compileLimit().

func (*BaseGrammar) CompileLock

func (g *BaseGrammar) CompileLock(b core.Query, value any) string

CompileLock mirrors Grammar::compileLock().

func (*BaseGrammar) CompileOffset

func (g *BaseGrammar) CompileOffset(b core.Query, offset *int) string

CompileOffset mirrors Grammar::compileOffset().

func (*BaseGrammar) CompileOrders

func (g *BaseGrammar) CompileOrders(b core.Query, orders []core.Order) string

CompileOrders mirrors Grammar::compileOrders().

func (*BaseGrammar) CompileRandom

func (g *BaseGrammar) CompileRandom(seed any) string

CompileRandom mirrors Grammar::compileRandom().

func (*BaseGrammar) CompileRowNumber

func (g *BaseGrammar) CompileRowNumber(partition string, orders string) string

CompileRowNumber mirrors Grammar::compileRowNumber(), used by the group limit rewrite.

func (*BaseGrammar) CompileSelect

func (g *BaseGrammar) CompileSelect(b core.Query) string

CompileSelect compiles a select statement. Mirrors Grammar::compileSelect().

func (*BaseGrammar) CompileTruncate

func (g *BaseGrammar) CompileTruncate(b core.Query) []core.Statement

CompileTruncate mirrors Grammar::compileTruncate().

func (*BaseGrammar) CompileUnionAggregate

func (g *BaseGrammar) CompileUnionAggregate(b core.Query) string

CompileUnionAggregate mirrors Grammar::compileUnionAggregate().

func (*BaseGrammar) CompileUnions

func (g *BaseGrammar) CompileUnions(b core.Query) string

CompileUnions mirrors Grammar::compileUnions().

func (*BaseGrammar) CompileUpdate

func (g *BaseGrammar) CompileUpdate(b core.Query, values core.UpdateValues) string

CompileUpdate mirrors Grammar::compileUpdate().

func (*BaseGrammar) CompileUpdateColumns

func (g *BaseGrammar) CompileUpdateColumns(b core.Query, values core.UpdateValues) string

CompileUpdateColumns mirrors Grammar::compileUpdateColumns().

func (*BaseGrammar) CompileUpdateWithJoins

func (g *BaseGrammar) CompileUpdateWithJoins(b core.Query, table string, columns string, where string) string

CompileUpdateWithJoins mirrors Grammar::compileUpdateWithJoins().

func (*BaseGrammar) CompileUpdateWithoutJoins

func (g *BaseGrammar) CompileUpdateWithoutJoins(b core.Query, table string, columns string, where string) string

CompileUpdateWithoutJoins mirrors Grammar::compileUpdateWithoutJoins().

func (*BaseGrammar) CompileUpsert

func (g *BaseGrammar) CompileUpsert(b core.Query, values []map[string]any, uniqueBy []string, update []core.UpsertUpdate) string

CompileUpsert mirrors Grammar::compileUpsert(). The base refuses.

func (*BaseGrammar) CompileWhere

func (g *BaseGrammar) CompileWhere(b core.Query, where core.Where) string

CompileWhere dispatches on the descriptor type. Mirrors Grammar::compileWheresToArray(), which builds the method name as "where{$where['type']}".

func (*BaseGrammar) CompileWheres

func (g *BaseGrammar) CompileWheres(b core.Query) string

CompileWheres mirrors Grammar::compileWheres().

func (*BaseGrammar) GetBitwiseOperators

func (g *BaseGrammar) GetBitwiseOperators() []string

GetBitwiseOperators returns dialect specific bitwise operators. The base adds none.

func (*BaseGrammar) GetDateFormat

func (g *BaseGrammar) GetDateFormat() string

GetDateFormat returns the dialect date format. Mirrors Grammar::getDateFormat().

func (*BaseGrammar) GetOperators

func (g *BaseGrammar) GetOperators() []string

GetOperators returns dialect specific operators. The base adds none.

func (*BaseGrammar) GetValue

func (g *BaseGrammar) GetValue(expression core.Expression) string

GetValue returns an expression's raw SQL. Mirrors Grammar::getValue().

func (*BaseGrammar) IsJsonSelector

func (g *BaseGrammar) IsJsonSelector(value string) bool

IsJsonSelector reports whether a value is a JSON selector. Mirrors Grammar::isJsonSelector().

func (*BaseGrammar) JsonFieldAndPath

func (g *BaseGrammar) JsonFieldAndPath(value string) (string, string)

JsonFieldAndPath returns the quoted field and JSON path for an external dialect.

func (*BaseGrammar) Parameter

func (g *BaseGrammar) Parameter(value any) string

Parameter returns the placeholder for a value. Mirrors Grammar::parameter().

func (*BaseGrammar) Parameterize

func (g *BaseGrammar) Parameterize(values []any) string

Parameterize joins placeholders with a comma. Mirrors Grammar::parameterize().

func (*BaseGrammar) Prefix

func (g *BaseGrammar) Prefix() string

Prefix returns the table prefix.

func (*BaseGrammar) PrepareBindingForJsonContains

func (g *BaseGrammar) PrepareBindingForJsonContains(value any) any

PrepareBindingForJsonContains normalises a JSON contains binding. The base json-encodes the value, matching Grammar::prepareBindingForJsonContains(); SQLite and SQL Server override to pass scalars through unchanged.

func (*BaseGrammar) PrepareBindingsForDelete

func (g *BaseGrammar) PrepareBindingsForDelete(bindings map[string][]any) []any

PrepareBindingsForDelete mirrors Grammar::prepareBindingsForDelete().

func (*BaseGrammar) PrepareBindingsForUpdate

func (g *BaseGrammar) PrepareBindingsForUpdate(bindings map[string][]any, values core.UpdateValues) []any

PrepareBindingsForUpdate mirrors Grammar::prepareBindingsForUpdate().

func (*BaseGrammar) PrepareWhereLikeBinding

func (g *BaseGrammar) PrepareWhereLikeBinding(value string, caseSensitive bool) string

PrepareWhereLikeBinding normalises a like binding. The base is an identity.

func (*BaseGrammar) SelectComponents

func (g *BaseGrammar) SelectComponents() []string

SelectComponents returns the clause order this dialect compiles in. Mirrors Grammar::$selectComponents.

func (*BaseGrammar) SetEscaper

func (g *BaseGrammar) SetEscaper(escape func(any, bool) string)

SetEscaper supplies the connection's literal escaping, as Laravel's Grammar::escape does. SQL previews use the framework's value formatter when no connection escaper was supplied.

func (*BaseGrammar) SetValueWrapper

func (g *BaseGrammar) SetValueWrapper(wrapper func(string) string)

SetValueWrapper sets the dialect's identifier quoting.

func (*BaseGrammar) SubstituteBindingsIntoRawSQL

func (g *BaseGrammar) SubstituteBindingsIntoRawSQL(sql string, bindings []any) string

SubstituteBindingsIntoRawSQL ports Grammar::substituteBindingsIntoRawSql. Escaped quotes and escaped question marks do not consume bindings, nor do question marks inside string literals.

func (*BaseGrammar) UseLegacyGroupLimit

func (g *BaseGrammar) UseLegacyGroupLimit(b core.Query) bool

UseLegacyGroupLimit reports whether the dialect needs the legacy group limit rewrite.

func (*BaseGrammar) WhereBasic

func (g *BaseGrammar) WhereBasic(b core.Query, where core.Where) string

WhereBasic mirrors Grammar::whereBasic().

func (*BaseGrammar) WhereBetween

func (g *BaseGrammar) WhereBetween(b core.Query, where core.Where) string

WhereBetween mirrors Grammar::whereBetween().

func (*BaseGrammar) WhereBetweenColumns

func (g *BaseGrammar) WhereBetweenColumns(b core.Query, where core.Where) string

WhereBetweenColumns mirrors Grammar::whereBetweenColumns().

func (*BaseGrammar) WhereBitwise

func (g *BaseGrammar) WhereBitwise(b core.Query, where core.Where) string

WhereBitwise mirrors Grammar::whereBitwise(), which delegates to whereBasic.

func (*BaseGrammar) WhereColumn

func (g *BaseGrammar) WhereColumn(b core.Query, where core.Where) string

WhereColumn mirrors Grammar::whereColumn().

func (*BaseGrammar) WhereDate

func (g *BaseGrammar) WhereDate(b core.Query, where core.Where) string

WhereDate mirrors Grammar::whereDate().

func (*BaseGrammar) WhereDay

func (g *BaseGrammar) WhereDay(b core.Query, where core.Where) string

WhereDay mirrors Grammar::whereDay().

func (*BaseGrammar) WhereExists

func (g *BaseGrammar) WhereExists(b core.Query, where core.Where) string

WhereExists mirrors Grammar::whereExists().

func (*BaseGrammar) WhereExpression

func (g *BaseGrammar) WhereExpression(b core.Query, where core.Where) string

WhereExpression mirrors Grammar::whereExpression().

func (*BaseGrammar) WhereFullText

func (g *BaseGrammar) WhereFullText(b core.Query, where core.Where) string

WhereFullText mirrors Grammar::whereFullText(). The base refuses.

func (*BaseGrammar) WhereIn

func (g *BaseGrammar) WhereIn(b core.Query, where core.Where) string

WhereIn mirrors Grammar::whereIn().

func (*BaseGrammar) WhereInRaw

func (g *BaseGrammar) WhereInRaw(b core.Query, where core.Where) string

WhereInRaw mirrors Grammar::whereInRaw().

func (*BaseGrammar) WhereJsonBoolean

func (g *BaseGrammar) WhereJsonBoolean(b core.Query, where core.Where) string

WhereJsonBoolean mirrors Grammar::whereJsonBoolean(). The base grammar has no JSON selector of its own, so wrapping the column comes back empty; Laravel's base grammar throws "this database engine does not support JSON operations" there, and the port records the same capability error on the builder, exactly as the JSON contains, key and length compilers do.

func (*BaseGrammar) WhereJsonContains

func (g *BaseGrammar) WhereJsonContains(b core.Query, where core.Where) string

WhereJsonContains mirrors Grammar::whereJsonContains().

func (*BaseGrammar) WhereJsonContainsKey

func (g *BaseGrammar) WhereJsonContainsKey(b core.Query, where core.Where) string

WhereJsonContainsKey mirrors Grammar::whereJsonContainsKey().

func (*BaseGrammar) WhereJsonLength

func (g *BaseGrammar) WhereJsonLength(b core.Query, where core.Where) string

WhereJsonLength mirrors Grammar::whereJsonLength().

func (*BaseGrammar) WhereJsonOverlaps

func (g *BaseGrammar) WhereJsonOverlaps(b core.Query, where core.Where) string

WhereJsonOverlaps mirrors Grammar::whereJsonOverlaps().

func (*BaseGrammar) WhereLike

func (g *BaseGrammar) WhereLike(b core.Query, where core.Where) string

WhereLike mirrors Grammar::whereLike().

func (*BaseGrammar) WhereMonth

func (g *BaseGrammar) WhereMonth(b core.Query, where core.Where) string

WhereMonth mirrors Grammar::whereMonth().

func (*BaseGrammar) WhereNested

func (g *BaseGrammar) WhereNested(b core.Query, where core.Where) string

WhereNested mirrors Grammar::whereNested(). The child compiles to "where ..." or "on ...", so the leading keyword is stripped by its length.

func (*BaseGrammar) WhereNotExists

func (g *BaseGrammar) WhereNotExists(b core.Query, where core.Where) string

WhereNotExists mirrors Grammar::whereNotExists().

func (*BaseGrammar) WhereNotIn

func (g *BaseGrammar) WhereNotIn(b core.Query, where core.Where) string

WhereNotIn mirrors Grammar::whereNotIn().

func (*BaseGrammar) WhereNotInRaw

func (g *BaseGrammar) WhereNotInRaw(b core.Query, where core.Where) string

WhereNotInRaw mirrors Grammar::whereNotInRaw().

func (*BaseGrammar) WhereNotNull

func (g *BaseGrammar) WhereNotNull(b core.Query, where core.Where) string

WhereNotNull mirrors Grammar::whereNotNull().

func (*BaseGrammar) WhereNull

func (g *BaseGrammar) WhereNull(b core.Query, where core.Where) string

WhereNull mirrors Grammar::whereNull().

func (*BaseGrammar) WhereRaw

func (g *BaseGrammar) WhereRaw(b core.Query, where core.Where) string

WhereRaw mirrors Grammar::whereRaw().

func (*BaseGrammar) WhereRowValues

func (g *BaseGrammar) WhereRowValues(b core.Query, where core.Where) string

WhereRowValues mirrors Grammar::whereRowValues().

func (*BaseGrammar) WhereSub

func (g *BaseGrammar) WhereSub(b core.Query, where core.Where) string

WhereSub mirrors Grammar::whereSub().

func (*BaseGrammar) WhereTime

func (g *BaseGrammar) WhereTime(b core.Query, where core.Where) string

WhereTime mirrors Grammar::whereTime().

func (*BaseGrammar) WhereValueBetween

func (g *BaseGrammar) WhereValueBetween(b core.Query, where core.Where) string

WhereValueBetween mirrors Grammar::whereValueBetween().

func (*BaseGrammar) WhereYear

func (g *BaseGrammar) WhereYear(b core.Query, where core.Where) string

WhereYear mirrors Grammar::whereYear().

func (*BaseGrammar) Wrap

func (g *BaseGrammar) Wrap(value any) string

Wrap quotes a column or value. Mirrors Grammar::wrap().

func (*BaseGrammar) WrapJsonBooleanSelector

func (g *BaseGrammar) WrapJsonBooleanSelector(value string) string

func (*BaseGrammar) WrapJsonBooleanValue

func (g *BaseGrammar) WrapJsonBooleanValue(value string) string

func (*BaseGrammar) WrapJsonSelector

func (g *BaseGrammar) WrapJsonSelector(value string) string

func (*BaseGrammar) WrapTable

func (g *BaseGrammar) WrapTable(table any) string

WrapTable quotes a table. Mirrors Grammar::wrapTable().

func (*BaseGrammar) WrapUnion

func (g *BaseGrammar) WrapUnion(sql string) string

WrapUnion mirrors Grammar::wrapUnion().

func (*BaseGrammar) WrapValue

func (g *BaseGrammar) WrapValue(value string) string

WrapValue quotes a single identifier. Mirrors Grammar::wrapValue().

type Grammar

type Grammar = contractsquery.Grammar

Grammar is the public contract implemented by query dialects.

func NewGrammar

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

NewGrammar returns the grammar for a driver name. The second result reports whether the driver is recognised; an unrecognised driver yields the base grammar and false.

External dialects are supplied by their configured driver.

Jump to

Keyboard shortcuts

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