class MySqlGrammar extends Grammar

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
MySqlConnection $connection
protected string[] $operators

The grammar specific operators.

protected string[] $bitwiseOperators

The grammar specific bitwise operators.

from  Grammar
protected string[] $selectComponents

The components that make up a select clause.

from  Grammar

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(Connection $connection)

Create a new grammar instance.

from  Grammar
array
wrapArray(array $values)

Wrap an array of values.

from  Grammar
string
wrapTable(Expression|string $table, string|null $prefix = null)

Wrap a table in keyword identifiers.

from  Grammar
string
wrapIdentifier(string $value)

Wrap a single identifier in keyword identifiers.

from  Grammar
string|int|float
wrap(Expression|string $value)

Wrap a value in keyword identifiers.

from  Grammar
string
wrapAliasedValue(string $value)

Wrap a value that has an alias.

from  Grammar
string
wrapAliasedTable(string $value, string|null $prefix = null)

Wrap a table that has an alias.

from  Grammar
string
wrapSegments(array $segments)

Wrap the given value segments.

from  Grammar
string
wrapValue(string $value)

Wrap a single string in keyword identifiers.

string
wrapJsonSelector(string $value)

Wrap the given JSON selector.

bool
isJsonSelector(string $value)

Determine if the given string is a JSON selector.

from  Grammar
string
columnize(array $columns)

Convert an array of column names into a delimited string.

from  Grammar
string
parameterize(array $values)

Create query parameter place-holders for an array.

from  Grammar
string|int|float
parameter(mixed $value)

Get the appropriate query parameter place-holder for a value.

from  Grammar
string
quoteString(string|array $value)

Quote the given string literal.

string
escape(string|float|int|bool|null $value, bool $binary = false)

Escape a value for safe SQL embedding.

from  Grammar
bool
isExpression(mixed $value)

Determine if the given value is a raw expression.

from  Grammar
string|int|float
getValue(Expression|string|int|float $expression)

Transforms expressions to their scalar types.

from  Grammar
string
getDateFormat()

Get the format for database stored dates.

from  Grammar
static void
flushState()

Flush all static state.

from  Grammar
array
wrapJsonFieldAndPath(string $column)

Split the given JSON selector into the field and the optional path and wrap them separately.

string
wrapJsonPath(string $value, string $delimiter = '->')

Wrap the given JSON path.

string
wrapJsonPathSegment(string $segment)

Wrap the given JSON path segment.

string
compileSelect(Builder $query)

Compile a select query into SQL.

from  Grammar
string
compileSelectQuery(Builder $query)

Compile a select query without statement-level decoration.

from  Grammar
string
compileSelectTimeout(Builder $query, string $sql)

Compile the query timeout for a complete select statement.

array
compileComponents(Builder $query)

Compile the components necessary for a select clause.

from  Grammar
string
compileAggregate(Builder $query, array $aggregate)

Compile an aggregated select clause.

from  Grammar
string|null
compileColumns(Builder $query, array $columns)

Compile the "select *" portion of the query.

from  Grammar
string
compileFrom(Builder $query, Expression|string $table)

Compile the "from" portion of the query.

from  Grammar
string
compileJoins(Builder $query, array $joins)

Compile the "join" portions of the query.

from  Grammar
string
compileJoinLateral(JoinLateralClause $join, string $expression)

Compile a "lateral join" clause.

bool
supportsStraightJoins()

Determine if the grammar supports straight joins.

string
compileWheres(Builder $query)

Compile the "where" portions of the query.

from  Grammar
array
compileWheresToArray(Builder $query)

Get an array of all the where clauses for the query.

from  Grammar
string
concatenateWhereClauses(Builder $query, array $sql)

Format the where clause statements into one string.

from  Grammar
string
whereRaw(Builder $query, array $where)

Compile a raw where clause.

from  Grammar
string
whereBasic(Builder $query, array $where)

Compile a basic where clause.

from  Grammar
string
whereBinary(Builder $query, array $where)

Compile a "where binary" clause.

string
whereBitwise(Builder $query, array $where)

Compile a bitwise operator where clause.

from  Grammar
string
whereLike(Builder $query, array $where)

Compile a "where like" clause.

string
whereIn(Builder $query, array $where)

Compile a "where in" clause.

from  Grammar
string
whereNotIn(Builder $query, array $where)

Compile a "where not in" clause.

from  Grammar
string
whereNotInRaw(Builder $query, array $where)

Compile a "where not in raw" clause.

from  Grammar
string
whereInRaw(Builder $query, array $where)

Compile a "where in raw" clause.

from  Grammar
string
whereNull(Builder $query, array $where)

Add a "where null" clause to the query.

string
whereNotNull(Builder $query, array $where)

Add a "where not null" clause to the query.

string
whereNullSafeEquals(Builder $query, array $where)

Compile a "where null safe equals" clause.

string
whereBetween(Builder $query, array $where)

Compile a "between" where clause.

from  Grammar
string
whereBetweenColumns(Builder $query, array $where)

Compile a "between" where clause.

from  Grammar
string
whereValueBetween(Builder $query, array $where)

Compile a "value between" where clause.

from  Grammar
string
whereDate(Builder $query, array $where)

Compile a "where date" clause.

from  Grammar
string
whereTime(Builder $query, array $where)

Compile a "where time" clause.

from  Grammar
string
whereDay(Builder $query, array $where)

Compile a "where day" clause.

from  Grammar
string
whereMonth(Builder $query, array $where)

Compile a "where month" clause.

from  Grammar
string
whereYear(Builder $query, array $where)

Compile a "where year" clause.

from  Grammar
string
dateBasedWhere(string $type, Builder $query, array $where)

Compile a date based where clause.

from  Grammar
string
whereColumn(Builder $query, array $where)

Compile a where clause comparing two columns.

from  Grammar
string
whereNested(Builder $query, array $where)

Compile a nested where clause.

from  Grammar
string
whereSub(Builder $query, array $where)

Compile a where condition with a sub-select.

from  Grammar
string
whereExists(Builder $query, array $where)

Compile a where exists clause.

from  Grammar
string
whereNotExists(Builder $query, array $where)

Compile a where not exists clause.

from  Grammar
string
whereRowValues(Builder $query, array $where)

Compile a where row values condition.

from  Grammar
string
whereJsonBoolean(Builder $query, array $where)

Compile a "where JSON boolean" clause.

from  Grammar
string
whereJsonContains(Builder $query, array $where)

Compile a "where JSON contains" clause.

from  Grammar
string
compileJsonContains(string $column, string $value)

Compile a "JSON contains" statement into SQL.

string
whereJsonOverlaps(Builder $query, array $where)

Compile a "where JSON overlaps" clause.

from  Grammar
string
compileJsonOverlaps(string $column, string $value)

Compile a "JSON overlaps" statement into SQL.

mixed
prepareBindingForJsonContains(mixed $binding)

Prepare the binding for a "JSON contains" statement.

from  Grammar
string
whereJsonContainsKey(Builder $query, array $where)

Compile a "where JSON contains key" clause.

from  Grammar
string
compileJsonContainsKey(string $column)

Compile a "JSON contains key" statement into SQL.

string
whereJsonLength(Builder $query, array $where)

Compile a "where JSON length" clause.

from  Grammar
string
compileJsonLength(string $column, string $operator, string $value)

Compile a "JSON length" statement into SQL.

string
compileJsonValueCast(string $value)

Compile a "JSON value cast" statement into SQL.

string
whereFullText(Builder $query, array $where)

Compile a "where fulltext" clause.

string
whereExpression(Builder $query, array $where)

Compile a clause based on an expression.

from  Grammar
string
compileVectorDistanceExpression(Expression|string $column)

Compile a vector distance expression for the given column.

from  Grammar
bool
supportsVectorDistance()

Determine if the grammar supports vector distance queries.

from  Grammar
string
compileGroups(Builder $query, array $groups)

Compile the "group by" portions of the query.

from  Grammar
string
compileHavings(Builder $query)

Compile the "having" portions of the query.

from  Grammar
string
compileHaving(array $having)

Compile a single having clause.

from  Grammar
string
compileBasicHaving(array $having)

Compile a basic having clause.

from  Grammar
string
compileHavingBetween(array $having)

Compile a "between" having clause.

from  Grammar
string
compileHavingNull(array $having)

Compile a having null clause.

from  Grammar
string
compileHavingNotNull(array $having)

Compile a having not null clause.

from  Grammar
string
compileHavingBit(array $having)

Compile a having clause involving a bit operator.

from  Grammar
string
compileHavingExpression(array $having)

Compile a having clause involving an expression.

from  Grammar
string
compileNestedHavings(array $having)

Compile a nested having clause.

from  Grammar
string
compileOrders(Builder $query, array $orders)

Compile the "order by" portions of the query.

from  Grammar
array
compileOrdersToArray(Builder $query, array $orders)

Compile the query orders to an array.

from  Grammar
string
compileInOrderOf(array $order)

Compile an "in order of" clause.

from  Grammar
string
compileRandom(string|int $seed)

Compile the random statement into SQL.

string
compileLimit(Builder $query, int $limit)

Compile the "limit" portions of the query.

from  Grammar
string
compileGroupLimit(Builder $query)

Compile a group limit clause.

string
compileRowNumber(string $partition, string $orders)

Compile a row number clause.

from  Grammar
string
compileOffset(Builder $query, int $offset)

Compile the "offset" portions of the query.

from  Grammar
string
compileUnions(Builder $query)

Compile the "union" queries attached to the main query.

from  Grammar
string
compileUnion(array $union)

Compile a single union statement.

from  Grammar
string
wrapUnion(string $sql)

Wrap a union subquery in parentheses.

from  Grammar
string
compileUnionAggregate(Builder $query)

Compile a union aggregate query into SQL.

from  Grammar
string
compileExists(Builder $query)

Compile an exists statement into SQL.

from  Grammar
string
compileInsert(Builder $query, array $values)

Compile an insert statement into SQL.

string
compileInsertOrIgnore(Builder $query, array $values)

Compile an insert ignore statement into SQL.

string
compileInsertOrIgnoreReturning(Builder $query, array $values, array $returning, array|null $uniqueBy)

Compile an insert or ignore statement with a returning clause into SQL.

from  Grammar
string
compileInsertGetId(Builder $query, array $values, string|null $sequence)

Compile an insert and get ID statement into SQL.

from  Grammar
string
compileInsertUsing(Builder $query, array $columns, string $sql)

Compile an insert statement using a subquery into SQL.

from  Grammar
string
compileInsertOrIgnoreUsing(Builder $query, array $columns, string $sql)

Compile an insert ignore statement using a subquery into SQL.

string
compileUpdate(Builder $query, array $values)

Compile an update statement into SQL.

from  Grammar
string
compileUpdateColumns(Builder $query, array $values)

Compile the columns for an update statement.

array
groupJsonColumnsForUpdate(array $values)

Group update values by column in order of first appearance.

string
compileUpdateWithoutJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement without joins into SQL.

string
compileUpdateWithJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement with joins into SQL.

from  Grammar
string
compileUpsert(Builder $query, array $values, array $uniqueBy, array $update)

Compile an "upsert" statement into SQL.

array
prepareBindingsForUpdate(array $bindings, array $values)

Prepare the bindings for an update statement.

array
prepareBindingsForUpdateWithJoins(array $bindings, array $values)

Prepare the bindings for an update statement with joins.

array
prepareValueBindingsForUpdate(array $values)

Prepare update values in column order, encoding JSON assignments.

from  Grammar
string
compileDelete(Builder $query)

Compile a delete statement into SQL.

from  Grammar
string
compileDeleteWithoutJoins(Builder $query, string $table, string $where)

Compile a delete query that does not use joins.

string
compileDeleteWithJoins(Builder $query, string $table, string $where)

Compile a delete query that uses joins.

string
qualifyRowIdentifier(Builder $query, string $identifier)

Qualify the row identifier selected by a limited or joined write rewrite.

from  Grammar
array
prepareBindingsForDelete(array $bindings)

Prepare the bindings for a delete statement.

from  Grammar
array
compileTruncate(Builder $query)

Compile a truncate table statement into SQL.

from  Grammar
string
compileLock(Builder $query, bool|string $value)

Compile the lock into SQL.

string|null
compileThreadCount()

Compile a query to get the number of open connections for a database.

bool
supportsSavepoints()

Determine if the grammar supports savepoints.

from  Grammar
string
compileSavepoint(string $name)

Compile the SQL statement to define a savepoint.

from  Grammar
string
compileSavepointRollBack(string $name)

Compile the SQL statement to execute a savepoint rollback.

from  Grammar
string
wrapJsonBooleanSelector(string $value)

Wrap the given JSON selector for boolean values.

string
wrapJsonBooleanValue(string $value)

Wrap the given JSON boolean value.

from  Grammar
string
concatenate(array $segments)

Concatenate an array of segments, removing empties.

from  Grammar
string
removeLeadingBoolean(string $value)

Remove the leading boolean from a statement.

from  Grammar
string
substituteBindingsIntoRawSql(string $sql, array $bindings)

Substitute the given bindings into the given raw SQL query.

from  Grammar
array
getOperators()

Get the grammar specific operators.

from  Grammar
array
getBitwiseOperators()

Get the grammar specific bitwise operators.

from  Grammar
string
compileIndexHint(Builder $query, IndexHint $indexHint)

Compile the index hints for the query.

bool
useLegacyGroupLimit(Builder $query)

Determine whether to use a legacy group limit clause for MySQL < 8.0.

string
compileLegacyGroupLimit(Builder $query)

Compile a group limit clause for MySQL < 8.0.

string
compileJsonUpdateColumn(string $key, array $values)

Prepare a JSON column being updated using the JSON_SET function.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Grammar at line 24
__construct(Connection $connection)

Create a new grammar instance.

Parameters

Connection $connection

in Grammar at line 35
array wrapArray(array $values)

Wrap an array of values.

Parameters

array $values

Return Value

array

in Grammar at line 43
string wrapTable(Expression|string $table, string|null $prefix = null)

Wrap a table in keyword identifiers.

Parameters

Expression|string $table
string|null $prefix

Return Value

string

in Grammar at line 76
string wrapIdentifier(string $value)

Wrap a single identifier in keyword identifiers.

Parameters

string $value

Return Value

string

in Grammar at line 84
string|int|float wrap(Expression|string $value)

Wrap a value in keyword identifiers.

Parameters

Expression|string $value

Return Value

string|int|float

in Grammar at line 110
protected string wrapAliasedValue(string $value)

Wrap a value that has an alias.

Parameters

string $value

Return Value

string

in Grammar at line 120
protected string wrapAliasedTable(string $value, string|null $prefix = null)

Wrap a table that has an alias.

Parameters

string $value
string|null $prefix

Return Value

string

in Grammar at line 134
protected string wrapSegments(array $segments)

Wrap the given value segments.

Parameters

array $segments

Return Value

string

at line 560
protected string wrapValue(string $value)

Wrap a single string in keyword identifiers.

Parameters

string $value

Return Value

string

at line 568
protected string wrapJsonSelector(string $value)

Wrap the given JSON selector.

Parameters

string $value

Return Value

string

in Grammar at line 168
protected bool isJsonSelector(string $value)

Determine if the given string is a JSON selector.

Parameters

string $value

Return Value

bool

in Grammar at line 178
string columnize(array $columns)

Convert an array of column names into a delimited string.

Parameters

array $columns

Return Value

string

in Grammar at line 186
string parameterize(array $values)

Create query parameter place-holders for an array.

Parameters

array $values

Return Value

string

in Grammar at line 194
string|int|float parameter(mixed $value)

Get the appropriate query parameter place-holder for a value.

Parameters

mixed $value

Return Value

string|int|float

at line 546
string quoteString(string|array $value)

Quote the given string literal.

Parameters

string|array $value

Return Value

string

in Grammar at line 216
string escape(string|float|int|bool|null $value, bool $binary = false)

Escape a value for safe SQL embedding.

Parameters

string|float|int|bool|null $value
bool $binary

Return Value

string

in Grammar at line 224
bool isExpression(mixed $value)

Determine if the given value is a raw expression.

Parameters

mixed $value

Return Value

bool

in Grammar at line 232
string|int|float getValue(Expression|string|int|float $expression)

Transforms expressions to their scalar types.

Parameters

Expression|string|int|float $expression

Return Value

string|int|float

in Grammar at line 244
string getDateFormat()

Get the format for database stored dates.

Return Value

string

in Grammar at line 255
static void flushState()

Flush all static state.

Return Value

void

in CompilesJsonPaths at line 15
protected array wrapJsonFieldAndPath(string $column)

Split the given JSON selector into the field and the optional path and wrap them separately.

Parameters

string $column

Return Value

array

in CompilesJsonPaths at line 29
protected string wrapJsonPath(string $value, string $delimiter = '->')

Wrap the given JSON path.

Parameters

string $value
string $delimiter

Return Value

string

in CompilesJsonPaths at line 44
protected string wrapJsonPathSegment(string $segment)

Wrap the given JSON path segment.

Parameters

string $segment

Return Value

string

in Grammar at line 62
string compileSelect(Builder $query)

Compile a select query into SQL.

Parameters

Builder $query

Return Value

string

in Grammar at line 77
protected string compileSelectQuery(Builder $query)

Compile a select query without statement-level decoration.

Embedded fragments are assembled by their builder's grammar because connection-owned details such as table prefixes resolve through that grammar. They bypass compileSelect because only a complete executed statement carries statement-level decoration.

Parameters

Builder $query

Return Value

string

at line 31
protected string compileSelectTimeout(Builder $query, string $sql)

Compile the query timeout for a complete select statement.

Parameters

Builder $query
string $sql

Return Value

string

in Grammar at line 132
protected array compileComponents(Builder $query)

Compile the components necessary for a select clause.

Parameters

Builder $query

Return Value

array

in Grammar at line 152
protected string compileAggregate(Builder $query, array $aggregate)

Compile an aggregated select clause.

Parameters

Builder $query
array $aggregate

Return Value

string

in Grammar at line 171
protected string|null compileColumns(Builder $query, array $columns)

Compile the "select *" portion of the query.

Parameters

Builder $query
array $columns

Return Value

string|null

in Grammar at line 192
protected string compileFrom(Builder $query, Expression|string $table)

Compile the "from" portion of the query.

Parameters

Builder $query
Expression|string $table

Return Value

string

in Grammar at line 200
protected string compileJoins(Builder $query, array $joins)

Compile the "join" portions of the query.

Parameters

Builder $query
array $joins

Return Value

string

at line 404
string compileJoinLateral(JoinLateralClause $join, string $expression)

Compile a "lateral join" clause.

Parameters

JoinLateralClause $join
string $expression

Return Value

string

at line 412
protected bool supportsStraightJoins()

Determine if the grammar supports straight joins.

Return Value

bool

in Grammar at line 242
string compileWheres(Builder $query)

Compile the "where" portions of the query.

Parameters

Builder $query

Return Value

string

in Grammar at line 260
protected array compileWheresToArray(Builder $query)

Get an array of all the where clauses for the query.

Parameters

Builder $query

Return Value

array

in Grammar at line 270
protected string concatenateWhereClauses(Builder $query, array $sql)

Format the where clause statements into one string.

Parameters

Builder $query
array $sql

Return Value

string

in Grammar at line 280
protected string whereRaw(Builder $query, array $where)

Compile a raw where clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 288
protected string whereBasic(Builder $query, array $where)

Compile a basic where clause.

Parameters

Builder $query
array $where

Return Value

string

at line 51
protected string whereBinary(Builder $query, array $where)

Compile a "where binary" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 310
protected string whereBitwise(Builder $query, array $where)

Compile a bitwise operator where clause.

Parameters

Builder $query
array $where

Return Value

string

at line 61
protected string whereLike(Builder $query, array $where)

Compile a "where like" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 334
protected string whereIn(Builder $query, array $where)

Compile a "where in" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 346
protected string whereNotIn(Builder $query, array $where)

Compile a "where not in" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 360
protected string whereNotInRaw(Builder $query, array $where)

Compile a "where not in raw" clause.

For safety, whereIntegerInRaw ensures this method is only used with integer values.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 374
protected string whereInRaw(Builder $query, array $where)

Compile a "where in raw" clause.

For safety, whereIntegerInRaw ensures this method is only used with integer values.

Parameters

Builder $query
array $where

Return Value

string

at line 83
protected string whereNull(Builder $query, array $where)

Add a "where null" clause to the query.

Parameters

Builder $query
array $where

Return Value

string

at line 99
protected string whereNotNull(Builder $query, array $where)

Add a "where not null" clause to the query.

Parameters

Builder $query
array $where

Return Value

string

at line 75
protected string whereNullSafeEquals(Builder $query, array $where)

Compile a "where null safe equals" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 410
protected string whereBetween(Builder $query, array $where)

Compile a "between" where clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 424
protected string whereBetweenColumns(Builder $query, array $where)

Compile a "between" where clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 438
protected string whereValueBetween(Builder $query, array $where)

Compile a "value between" where clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 452
protected string whereDate(Builder $query, array $where)

Compile a "where date" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 460
protected string whereTime(Builder $query, array $where)

Compile a "where time" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 468
protected string whereDay(Builder $query, array $where)

Compile a "where day" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 476
protected string whereMonth(Builder $query, array $where)

Compile a "where month" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 484
protected string whereYear(Builder $query, array $where)

Compile a "where year" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 492
protected string dateBasedWhere(string $type, Builder $query, array $where)

Compile a date based where clause.

Parameters

string $type
Builder $query
array $where

Return Value

string

in Grammar at line 502
protected string whereColumn(Builder $query, array $where)

Compile a where clause comparing two columns.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 512
protected string whereNested(Builder $query, array $where)

Compile a nested where clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 525
protected string whereSub(Builder $query, array $where)

Compile a where condition with a sub-select.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 542
protected string whereExists(Builder $query, array $where)

Compile a where exists clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 552
protected string whereNotExists(Builder $query, array $where)

Compile a where not exists clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 562
protected string whereRowValues(Builder $query, array $where)

Compile a where row values condition.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 574
protected string whereJsonBoolean(Builder $query, array $where)

Compile a "where JSON boolean" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 595
protected string whereJsonContains(Builder $query, array $where)

Compile a "where JSON contains" clause.

Parameters

Builder $query
array $where

Return Value

string

at line 243
protected string compileJsonContains(string $column, string $value)

Compile a "JSON contains" statement into SQL.

Parameters

string $column
string $value

Return Value

string

in Grammar at line 618
protected string whereJsonOverlaps(Builder $query, array $where)

Compile a "where JSON overlaps" clause.

Parameters

Builder $query
array $where

Return Value

string

at line 253
protected string compileJsonOverlaps(string $column, string $value)

Compile a "JSON overlaps" statement into SQL.

Parameters

string $column
string $value

Return Value

string

in Grammar at line 641
mixed prepareBindingForJsonContains(mixed $binding)

Prepare the binding for a "JSON contains" statement.

Parameters

mixed $binding

Return Value

mixed

in Grammar at line 649
protected string whereJsonContainsKey(Builder $query, array $where)

Compile a "where JSON contains key" clause.

Parameters

Builder $query
array $where

Return Value

string

at line 263
protected string compileJsonContainsKey(string $column)

Compile a "JSON contains key" statement into SQL.

Parameters

string $column

Return Value

string

in Grammar at line 671
protected string whereJsonLength(Builder $query, array $where)

Compile a "where JSON length" clause.

Parameters

Builder $query
array $where

Return Value

string

at line 273
protected string compileJsonLength(string $column, string $operator, string $value)

Compile a "JSON length" statement into SQL.

Parameters

string $column
string $operator
string $value

Return Value

string

at line 283
string compileJsonValueCast(string $value)

Compile a "JSON value cast" statement into SQL.

Parameters

string $value

Return Value

string

at line 115
string whereFullText(Builder $query, array $where)

Compile a "where fulltext" clause.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 711
string whereExpression(Builder $query, array $where)

Compile a clause based on an expression.

Parameters

Builder $query
array $where

Return Value

string

in Grammar at line 721
string compileVectorDistanceExpression(Expression|string $column)

Compile a vector distance expression for the given column.

Parameters

Expression|string $column

Return Value

string

Exceptions

RuntimeException

in Grammar at line 729
bool supportsVectorDistance()

Determine if the grammar supports vector distance queries.

Return Value

bool

in Grammar at line 737
protected string compileGroups(Builder $query, array $groups)

Compile the "group by" portions of the query.

Parameters

Builder $query
array $groups

Return Value

string

in Grammar at line 745
protected string compileHavings(Builder $query)

Compile the "having" portions of the query.

Parameters

Builder $query

Return Value

string

in Grammar at line 755
protected string compileHaving(array $having)

Compile a single having clause.

Parameters

array $having

Return Value

string

in Grammar at line 775
protected string compileBasicHaving(array $having)

Compile a basic having clause.

Parameters

array $having

Return Value

string

in Grammar at line 787
protected string compileHavingBetween(array $having)

Compile a "between" having clause.

Parameters

array $having

Return Value

string

in Grammar at line 803
protected string compileHavingNull(array $having)

Compile a having null clause.

Parameters

array $having

Return Value

string

in Grammar at line 813
protected string compileHavingNotNull(array $having)

Compile a having not null clause.

Parameters

array $having

Return Value

string

in Grammar at line 823
protected string compileHavingBit(array $having)

Compile a having clause involving a bit operator.

Parameters

array $having

Return Value

string

in Grammar at line 835
protected string compileHavingExpression(array $having)

Compile a having clause involving an expression.

Parameters

array $having

Return Value

string

in Grammar at line 843
protected string compileNestedHavings(array $having)

Compile a nested having clause.

Parameters

array $having

Return Value

string

in Grammar at line 851
protected string compileOrders(Builder $query, array $orders)

Compile the "order by" portions of the query.

Parameters

Builder $query
array $orders

Return Value

string

in Grammar at line 863
protected array compileOrdersToArray(Builder $query, array $orders)

Compile the query orders to an array.

Parameters

Builder $query
array $orders

Return Value

array

in Grammar at line 881
protected string compileInOrderOf(array $order)

Compile an "in order of" clause.

Parameters

array $order

Return Value

string

at line 293
string compileRandom(string|int $seed)

Compile the random statement into SQL.

Parameters

string|int $seed

Return Value

string

Exceptions

InvalidArgumentException

in Grammar at line 905
protected string compileLimit(Builder $query, int $limit)

Compile the "limit" portions of the query.

Parameters

Builder $query
int $limit

Return Value

string

at line 159
protected string compileGroupLimit(Builder $query)

Compile a group limit clause.

Parameters

Builder $query

Return Value

string

in Grammar at line 956
protected string compileRowNumber(string $partition, string $orders)

Compile a row number clause.

Parameters

string $partition
string $orders

Return Value

string

in Grammar at line 966
protected string compileOffset(Builder $query, int $offset)

Compile the "offset" portions of the query.

Parameters

Builder $query
int $offset

Return Value

string

in Grammar at line 974
protected string compileUnions(Builder $query)

Compile the "union" queries attached to the main query.

Parameters

Builder $query

Return Value

string

in Grammar at line 1000
protected string compileUnion(array $union)

Compile a single union statement.

Parameters

array $union

Return Value

string

in Grammar at line 1013
protected string wrapUnion(string $sql)

Wrap a union subquery in parentheses.

Parameters

string $sql

Return Value

string

in Grammar at line 1021
protected string compileUnionAggregate(Builder $query)

Compile a union aggregate query into SQL.

Parameters

Builder $query

Return Value

string

in Grammar at line 1033
string compileExists(Builder $query)

Compile an exists statement into SQL.

Parameters

Builder $query

Return Value

string

at line 321
string compileInsert(Builder $query, array $values)

Compile an insert statement into SQL.

Parameters

Builder $query
array $values

Return Value

string

at line 227
string compileInsertOrIgnore(Builder $query, array $values)

Compile an insert ignore statement into SQL.

Parameters

Builder $query
array $values

Return Value

string

in Grammar at line 1088
string compileInsertOrIgnoreReturning(Builder $query, array $values, array $returning, array|null $uniqueBy)

Compile an insert or ignore statement with a returning clause into SQL.

Parameters

Builder $query
array $values
array $returning
array|null $uniqueBy

Return Value

string

Exceptions

RuntimeException

in Grammar at line 1096
string compileInsertGetId(Builder $query, array $values, string|null $sequence)

Compile an insert and get ID statement into SQL.

Parameters

Builder $query
array $values
string|null $sequence

Return Value

string

in Grammar at line 1104
string compileInsertUsing(Builder $query, array $columns, string $sql)

Compile an insert statement using a subquery into SQL.

Parameters

Builder $query
array $columns
string $sql

Return Value

string

at line 235
string compileInsertOrIgnoreUsing(Builder $query, array $columns, string $sql)

Compile an insert ignore statement using a subquery into SQL.

Parameters

Builder $query
array $columns
string $sql

Return Value

string

in Grammar at line 1128
string compileUpdate(Builder $query, array $values)

Compile an update statement into SQL.

Parameters

Builder $query
array $values

Return Value

string

at line 333
protected string compileUpdateColumns(Builder $query, array $values)

Compile the columns for an update statement.

Parameters

Builder $query
array $values

Return Value

string

at line 359
protected array groupJsonColumnsForUpdate(array $values)

Group update values by column in order of first appearance.

Parameters

array $values

Return Value

array

at line 444
protected string compileUpdateWithoutJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement without joins into SQL.

Parameters

Builder $query
string $table
string $columns
string $where

Return Value

string

in Grammar at line 1183
protected string compileUpdateWithJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement with joins into SQL.

Parameters

Builder $query
string $table
string $columns
string $where

Return Value

string

at line 376
string compileUpsert(Builder $query, array $values, array $uniqueBy, array $update)

Compile an "upsert" statement into SQL.

Parameters

Builder $query
array $values
array $uniqueBy
array $update

Return Value

string

at line 464
array prepareBindingsForUpdate(array $bindings, array $values)

Prepare the bindings for an update statement.

Booleans, integers, and doubles are inserted into JSON updates as raw values.

Parameters

array $bindings
array $values

Return Value

array

at line 478
array prepareBindingsForUpdateWithJoins(array $bindings, array $values)

Prepare the bindings for an update statement with joins.

Parameters

array $bindings
array $values

Return Value

array

in Grammar at line 1225
protected array prepareValueBindingsForUpdate(array $values)

Prepare update values in column order, encoding JSON assignments.

Parameters

array $values

Return Value

array

in Grammar at line 1246
string compileDelete(Builder $query)

Compile a delete statement into SQL.

Parameters

Builder $query

Return Value

string

at line 494
protected string compileDeleteWithoutJoins(Builder $query, string $table, string $where)

Compile a delete query that does not use joins.

Parameters

Builder $query
string $table
string $where

Return Value

string

at line 518
protected string compileDeleteWithJoins(Builder $query, string $table, string $where)

Compile a delete query that uses joins.

Adds ORDER BY and LIMIT if present, for platforms that allow them (e.g., PlanetScale). Standard MySQL does not support ORDER BY or LIMIT with joined deletes and will throw a syntax error.

Parameters

Builder $query
string $table
string $where

Return Value

string

in Grammar at line 1284
protected string qualifyRowIdentifier(Builder $query, string $identifier)

Qualify the row identifier selected by a limited or joined write rewrite.

Parameters

Builder $query
string $identifier

Return Value

string

Exceptions

InvalidArgumentException

in Grammar at line 1304
array prepareBindingsForDelete(array $bindings)

Prepare the bindings for a delete statement.

Parameters

array $bindings

Return Value

array

in Grammar at line 1314
array compileTruncate(Builder $query)

Compile a truncate table statement into SQL.

Parameters

Builder $query

Return Value

array

at line 309
protected string compileLock(Builder $query, bool|string $value)

Compile the lock into SQL.

Parameters

Builder $query
bool|string $value

Return Value

string

at line 536
string|null compileThreadCount()

Compile a query to get the number of open connections for a database.

Return Value

string|null

in Grammar at line 1338
bool supportsSavepoints()

Determine if the grammar supports savepoints.

Return Value

bool

in Grammar at line 1346
string compileSavepoint(string $name)

Compile the SQL statement to define a savepoint.

Parameters

string $name

Return Value

string

in Grammar at line 1354
string compileSavepointRollBack(string $name)

Compile the SQL statement to execute a savepoint rollback.

Parameters

string $name

Return Value

string

at line 578
protected string wrapJsonBooleanSelector(string $value)

Wrap the given JSON selector for boolean values.

Parameters

string $value

Return Value

string

in Grammar at line 1370
protected string wrapJsonBooleanValue(string $value)

Wrap the given JSON boolean value.

Parameters

string $value

Return Value

string

in Grammar at line 1378
protected string concatenate(array $segments)

Concatenate an array of segments, removing empties.

Parameters

array $segments

Return Value

string

in Grammar at line 1388
protected string removeLeadingBoolean(string $value)

Remove the leading boolean from a statement.

Parameters

string $value

Return Value

string

in Grammar at line 1396
string substituteBindingsIntoRawSql(string $sql, array $bindings)

Substitute the given bindings into the given raw SQL query.

Parameters

string $sql
array $bindings

Return Value

string

in Grammar at line 1443
array getOperators()

Get the grammar specific operators.

Return Value

array

in Grammar at line 1453
array getBitwiseOperators()

Get the grammar specific bitwise operators.

Return Value

array

at line 137
protected string compileIndexHint(Builder $query, IndexHint $indexHint)

Compile the index hints for the query.

Parameters

Builder $query
IndexHint $indexHint

Return Value

string

Exceptions

InvalidArgumentException

at line 169
bool useLegacyGroupLimit(Builder $query)

Determine whether to use a legacy group limit clause for MySQL < 8.0.

Parameters

Builder $query

Return Value

bool

at line 182
protected string compileLegacyGroupLimit(Builder $query)

Compile a group limit clause for MySQL < 8.0.

Derived from https://softonsofa.com/tweaking-eloquent-relations-how-to-get-n-related-models-per-parent/.

Parameters

Builder $query

Return Value

string

at line 420
protected string compileJsonUpdateColumn(string $key, array $values)

Prepare a JSON column being updated using the JSON_SET function.

Parameters

string $key
array $values

Return Value

string