abstract class Grammar extends Grammar (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Connection $connection

The connection used for escaping values.

from  Grammar
protected string[] $modifiers

The possible column modifiers.

protected bool $transactions

If this Grammar supports schema changes wrapped in a transaction.

protected array $fluentCommands

The commands to be executed outside of create or alter command.

Methods

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

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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
string[]
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.

string
wrap(Expression|string $value)

Wrap a value in keyword identifiers.

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(list<string> $segments)

Wrap the given value segments.

from  Grammar
string
wrapValue(string $value)

Wrap a single string in keyword identifiers.

from  Grammar
string
wrapJsonSelector(string $value)

Wrap the given JSON selector.

from  Grammar
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
parameter(mixed $value)

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

from  Grammar
string
quoteString(string|string[] $value)

Quote the given string literal.

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

Escapes 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
string
getTablePrefix() deprecated

Get the grammar's table prefix.

from  Grammar
$this
setTablePrefix(string $prefix) deprecated

Set the grammar's table prefix.

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
compileCreateDatabase(string $name)

Compile a create database command.

string
compileDropDatabaseIfExists(string $name)

Compile a drop database if exists command.

string
compileSchemas()

Compile the query to determine the schemas.

string|null
compileTableExists(string|null $schema, string $table)

Compile the query to determine if the given table exists.

string
compileTables(string|string[]|null $schema)

Compile the query to determine the tables.

string
compileViews(string|string[]|null $schema)

Compile the query to determine the views.

string
compileTypes(string|string[]|null $schema)

Compile the query to determine the user-defined types.

string
compileColumns(string|null $schema, string $table)

Compile the query to determine the columns.

string
compileIndexes(string|null $schema, string $table)

Compile the query to determine the indexes.

void
compileVectorIndex(Blueprint $blueprint, Fluent $command)

Compile a vector index key command.

string
compileForeignKeys(string|null $schema, string $table)

Compile the query to determine the foreign keys.

list<string>|string
compileRenameColumn(Blueprint $blueprint, Fluent $command)

Compile a rename column command.

list<string>|string
compileChange(Blueprint $blueprint, Fluent $command)

Compile a change column command into a series of SQL statements.

string
compileFulltext(Blueprint $blueprint, Fluent $command)

Compile a fulltext index key command.

string
compileDropFullText(Blueprint $blueprint, Fluent $command)

Compile a drop fulltext index command.

string
compileForeign(Blueprint $blueprint, Fluent $command)

Compile a foreign key command.

string
compileDropForeign(Blueprint $blueprint, Fluent $command)

Compile a drop foreign key command.

array
getColumns(Blueprint $blueprint)

Compile the blueprint's added column definitions.

string
getColumn(Blueprint $blueprint, ColumnDefinition $column)

Compile the column definition.

string
getType(Fluent $column)

Get the SQL for the column data type.

void
typeComputed(Fluent $column)

Create the column definition for a generated, computed column type.

string
typeVector(Fluent $column)

Create the column definition for a vector type.

string
typeTsvector(Fluent $column)

Create the column definition for a tsvector type.

string
typeRaw(Fluent $column)

Create the column definition for a raw column type.

string
addModifiers(string $sql, Blueprint $blueprint, Fluent $column)

Add the column modifiers to the definition.

Fluent|null
getCommandByName(Blueprint $blueprint, string $name)

Get the command with a given name if it exists on the blueprint.

array
getCommandsByName(Blueprint $blueprint, string $name)

Get all of the commands with a given name.

bool
hasCommand(Blueprint $blueprint, string $name)

Determine if a command with a given name exists on the blueprint.

string[]
prefixArray(string $prefix, array $values)

Add a prefix to an array of values.

string
getDefaultValue(mixed $value)

Format a value so that it can be used in "default" clauses.

array
getFluentCommands()

Get the fluent commands for the grammar.

bool
supportsSchemaTransactions()

Check if this Grammar supports schema changes wrapped in a transaction.

Details

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

__construct(Connection $connection)

Create a new grammar instance.

Parameters

Connection $connection

string[] wrapArray(array $values)

Wrap an array of values.

Parameters

array $values

Return Value

string[]

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

string wrap(Expression|string $value)

Wrap a value in keyword identifiers.

Parameters

Expression|string $value

Return Value

string

protected string wrapAliasedValue(string $value)

Wrap a value that has an alias.

Parameters

string $value

Return Value

string

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

protected string wrapSegments(list<string> $segments)

Wrap the given value segments.

Parameters

list<string> $segments

Return Value

string

protected string wrapValue(string $value)

Wrap a single string in keyword identifiers.

Parameters

string $value

Return Value

string

protected string wrapJsonSelector(string $value)

Wrap the given JSON selector.

Parameters

string $value

Return Value

string

Exceptions

RuntimeException

protected bool isJsonSelector(string $value)

Determine if the given string is a JSON selector.

Parameters

string $value

Return Value

bool

string columnize(array $columns)

Convert an array of column names into a delimited string.

Parameters

array $columns

Return Value

string

string parameterize(array $values)

Create query parameter place-holders for an array.

Parameters

array $values

Return Value

string

string parameter(mixed $value)

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

Parameters

mixed $value

Return Value

string

string quoteString(string|string[] $value)

Quote the given string literal.

Parameters

string|string[] $value

Return Value

string

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

Escapes a value for safe SQL embedding.

Parameters

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

Return Value

string

bool isExpression(mixed $value)

Determine if the given value is a raw expression.

Parameters

mixed $value

Return Value

bool

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

string getDateFormat()

Get the format for database stored dates.

Return Value

string

string getTablePrefix() deprecated

deprecated Use DB::getTablePrefix()

Get the grammar's table prefix.

Return Value

string

$this setTablePrefix(string $prefix) deprecated

deprecated Use DB::setTablePrefix()

Set the grammar's table prefix.

Parameters

string $prefix

Return Value

$this

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

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

Wrap the given JSON path.

Parameters

string $value
string $delimiter

Return Value

string

protected string wrapJsonPathSegment(string $segment)

Wrap the given JSON path segment.

Parameters

string $segment

Return Value

string

string compileCreateDatabase(string $name)

Compile a create database command.

Parameters

string $name

Return Value

string

string compileDropDatabaseIfExists(string $name)

Compile a drop database if exists command.

Parameters

string $name

Return Value

string

string compileSchemas()

Compile the query to determine the schemas.

Return Value

string

Exceptions

RuntimeException

string|null compileTableExists(string|null $schema, string $table)

Compile the query to determine if the given table exists.

Parameters

string|null $schema
string $table

Return Value

string|null

string compileTables(string|string[]|null $schema)

Compile the query to determine the tables.

Parameters

string|string[]|null $schema

Return Value

string

Exceptions

RuntimeException

string compileViews(string|string[]|null $schema)

Compile the query to determine the views.

Parameters

string|string[]|null $schema

Return Value

string

Exceptions

RuntimeException

string compileTypes(string|string[]|null $schema)

Compile the query to determine the user-defined types.

Parameters

string|string[]|null $schema

Return Value

string

Exceptions

RuntimeException

string compileColumns(string|null $schema, string $table)

Compile the query to determine the columns.

Parameters

string|null $schema
string $table

Return Value

string

Exceptions

RuntimeException

string compileIndexes(string|null $schema, string $table)

Compile the query to determine the indexes.

Parameters

string|null $schema
string $table

Return Value

string

Exceptions

RuntimeException

void compileVectorIndex(Blueprint $blueprint, Fluent $command)

Compile a vector index key command.

Parameters

Blueprint $blueprint
Fluent $command

Return Value

void

Exceptions

RuntimeException

string compileForeignKeys(string|null $schema, string $table)

Compile the query to determine the foreign keys.

Parameters

string|null $schema
string $table

Return Value

string

Exceptions

RuntimeException

list<string>|string compileRenameColumn(Blueprint $blueprint, Fluent $command)

Compile a rename column command.

Parameters

Blueprint $blueprint
Fluent $command

Return Value

list<string>|string

list<string>|string compileChange(Blueprint $blueprint, Fluent $command)

Compile a change column command into a series of SQL statements.

Parameters

Blueprint $blueprint
Fluent $command

Return Value

list<string>|string

Exceptions

RuntimeException

string compileFulltext(Blueprint $blueprint, Fluent $command)

Compile a fulltext index key command.

Parameters

Blueprint $blueprint
Fluent $command

Return Value

string

Exceptions

RuntimeException

string compileDropFullText(Blueprint $blueprint, Fluent $command)

Compile a drop fulltext index command.

Parameters

Blueprint $blueprint
Fluent $command

Return Value

string

Exceptions

RuntimeException

string compileForeign(Blueprint $blueprint, Fluent $command)

Compile a foreign key command.

Parameters

Blueprint $blueprint
Fluent $command

Return Value

string

string compileDropForeign(Blueprint $blueprint, Fluent $command)

Compile a drop foreign key command.

Parameters

Blueprint $blueprint
Fluent $command

Return Value

string

Exceptions

RuntimeException

protected array getColumns(Blueprint $blueprint)

Compile the blueprint's added column definitions.

Parameters

Blueprint $blueprint

Return Value

array

protected string getColumn(Blueprint $blueprint, ColumnDefinition $column)

Compile the column definition.

Parameters

Blueprint $blueprint
ColumnDefinition $column

Return Value

string

protected string getType(Fluent $column)

Get the SQL for the column data type.

Parameters

Fluent $column

Return Value

string

protected void typeComputed(Fluent $column)

Create the column definition for a generated, computed column type.

Parameters

Fluent $column

Return Value

void

Exceptions

RuntimeException

protected string typeVector(Fluent $column)

Create the column definition for a vector type.

Parameters

Fluent $column

Return Value

string

Exceptions

RuntimeException

protected string typeTsvector(Fluent $column)

Create the column definition for a tsvector type.

Parameters

Fluent $column

Return Value

string

Exceptions

RuntimeException

protected string typeRaw(Fluent $column)

Create the column definition for a raw column type.

Parameters

Fluent $column

Return Value

string

protected string addModifiers(string $sql, Blueprint $blueprint, Fluent $column)

Add the column modifiers to the definition.

Parameters

string $sql
Blueprint $blueprint
Fluent $column

Return Value

string

protected Fluent|null getCommandByName(Blueprint $blueprint, string $name)

Get the command with a given name if it exists on the blueprint.

Parameters

Blueprint $blueprint
string $name

Return Value

Fluent|null

protected array getCommandsByName(Blueprint $blueprint, string $name)

Get all of the commands with a given name.

Parameters

Blueprint $blueprint
string $name

Return Value

array

protected bool hasCommand(Blueprint $blueprint, string $name)

Determine if a command with a given name exists on the blueprint.

Parameters

Blueprint $blueprint
string $name

Return Value

bool

string[] prefixArray(string $prefix, array $values)

Add a prefix to an array of values.

Parameters

string $prefix
array $values

Return Value

string[]

protected string getDefaultValue(mixed $value)

Format a value so that it can be used in "default" clauses.

Parameters

mixed $value

Return Value

string

array getFluentCommands()

Get the fluent commands for the grammar.

Return Value

array

bool supportsSchemaTransactions()

Check if this Grammar supports schema changes wrapped in a transaction.

Return Value

bool

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.