class MySqlBuilder extends Builder

Traits

Constants

protected DEFAULT_STRING_LENGTH

protected DEFAULT_TIME_PRECISION

protected DEFAULT_MORPH_KEY_TYPE

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Connection $connection

The database connection instance.

from  Builder
MySqlGrammar $grammar
protected null|Connection, string, null|Blueprint $resolver

The Blueprint resolver callback.

from  Builder
static null|non-negative-int $defaultStringLength

The default string length for migrations.

from  Builder
static int|null $defaultTimePrecision

The default time precision for migrations.

from  Builder
static "int"|"ulid"|"uuid" $defaultMorphKeyType

The default relationship morph key type.

from  Builder

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 database Schema manager.

from  Builder
static void
defaultStringLength(int $length)

Set the default string length for migrations.

from  Builder
static void
defaultTimePrecision(int|null $precision)

Set the default time precision for migrations.

from  Builder
static void
defaultMorphKeyType(string $type)

Set the default morph key type for migrations.

from  Builder
static void
morphUsingUuids()

Set the default morph key type for migrations to UUIDs.

from  Builder
static void
morphUsingUlids()

Set the default morph key type for migrations to ULIDs.

from  Builder
bool
createDatabase(string $name)

Create a database in the schema.

from  Builder
bool
dropDatabaseIfExists(string $name)

Drop a database from the schema if the database exists.

from  Builder
array
getSchemas()

Get the schemas that belong to the connection.

from  Builder
bool
hasTable(string $table)

Determine if the given table exists.

from  Builder
bool
hasView(string $view)

Determine if the given view exists.

from  Builder
array
getTables(array|string|null $schema = null)

Get the tables that belong to the connection.

from  Builder
array
getTableListing(array|string|null $schema = null, bool $schemaQualified = true)

Get the names of the tables that belong to the connection.

from  Builder
array
getViews(array|string|null $schema = null)

Get the views that belong to the connection.

from  Builder
array
getTypes(array|string|null $schema = null)

Get the user-defined types that belong to the connection.

from  Builder
bool
hasColumn(string $table, string $column)

Determine if the given table has a given column.

from  Builder
bool
hasColumns(string $table, array $columns)

Determine if the given table has given columns.

from  Builder
void
whenTableHasColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table has a given column.

from  Builder
void
whenTableDoesntHaveColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table doesn't have a given column.

from  Builder
void
whenTableHasIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table has a given index.

from  Builder
void
whenTableDoesntHaveIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table doesn't have a given index.

from  Builder
string
getColumnType(string $table, string $column, bool $fullDefinition = false)

Get the data type for the given column name.

from  Builder
array
getColumnListing(string $table)

Get the column listing for a given table.

from  Builder
array
getColumn(string $table, string $column)

Get the column for a given table.

from  Builder
array
getColumns(string $table)

Get the columns for a given table.

from  Builder
array
getIndexes(string $table)

Get the indexes for a given table.

from  Builder
array
getIndexListing(string $table)

Get the names of the indexes for a given table.

from  Builder
string
qualifyIndexName(string $name)

Qualify an explicit index name.

from  Builder
bool
hasIndex(string $table, array|string $index, string|null $type = null)

Determine if the given table has a given index.

from  Builder
bool
hasForeignKey(string $table, array|string $foreignKey)

Determine if the table has a given foreign key.

from  Builder
array
getForeignKeys(string $table)

Get the foreign keys for a given table.

from  Builder
array
getPartitions(string $table)

Get the partitions of a given table.

from  Builder
void
table(string $table, Closure $callback)

Modify a table on the schema.

from  Builder
void
create(string $table, Closure $callback)

Create a new table on the schema.

from  Builder
void
createRangePartition(string $table, string $partition, array $from, array $to)

Create a partition of a range-partitioned table for the given bounds.

from  Builder
void
createMigrationRepositoryTable(string $table)

Create the migration repository table for this database driver.

from  Builder
void
drop(string $table)

Drop a table from the schema.

from  Builder
void
dropIfExists(string $table)

Drop a table from the schema if it exists.

from  Builder
void
dropColumns(string $table, array|string $columns)

Drop columns from a table schema.

from  Builder
void
dropAllTables()

Drop all tables from the database.

void
dropAllViews()

Drop all views from the database.

void
dropAllTypes()

Drop all types from the database.

from  Builder
void
truncateTables(array $tables)

Truncate the given tables if they contain rows.

from  Builder
array
withoutCoveredPartitions(array $tables, array $except = [])

Remove the partitions whose ancestors are among the given tables or excepted.

from  Builder
void
rename(string $from, string $to)

Rename a table on the schema.

from  Builder
bool
enableForeignKeyConstraints()

Enable foreign key constraints.

from  Builder
bool
disableForeignKeyConstraints()

Disable foreign key constraints.

from  Builder
mixed
withoutForeignKeyConstraints(Closure $callback)

Disable foreign key constraints during the execution of a callback.

from  Builder
bool
foreignKeyConstraintsAreEnabled()

Determine whether foreign key constraints are enabled.

void
setForeignKeyConstraints(bool $enabled)

Set the foreign key constraint state for an internal suppression scope.

from  Builder
void
executeSessionStatement(string $statement)

Execute internal physical-session maintenance.

from  Builder
void
ensureVectorExtensionExists(string|null $schema = null)

Create the vector extension on the schema if it does not exist.

from  Builder
void
ensureExtensionExists(string $name, string|null $schema = null)

Create a new extension on the schema if it does not exist.

from  Builder
void
executeBlueprint(Blueprint $blueprint)

Execute the given schema blueprint.

from  Builder
void
build(Blueprint $blueprint)

Execute the blueprint to build / modify the table.

from  Builder
void
executeStatements(array $statements)

Execute the given schema statements in order.

from  Builder
array
selectMetadata(string $query)

Read schema metadata from the same write connection that migrations mutate.

from  Builder
mixed
scalarMetadata(string $query)

Read a scalar result through the metadata execution hook.

from  Builder
bool
commandsAreDeclaredOn(Blueprint $blueprint, string $grammar)

Determine whether every executable command is declared by the framework grammar.

from  Builder
createBlueprint(string $table, Closure|null $callback = null)

Create a new command set with a Closure.

from  Builder
array|null
getCurrentSchemaListing()

Get the names of current schemas for the connection.

string|null
getCurrentSchemaName()

Get the default schema name for the connection.

from  Builder
array
parseSchemaAndTable(string $reference, bool|string|null $withDefaultSchema = null)

Parse the given database object reference and extract the schema and table.

from  Builder
getConnection()

Get the database connection instance.

from  Builder
void
blueprintResolver(Closure $resolver)

Set the Schema Blueprint resolver callback.

from  Builder
static void
flushState()

Flush all static state.

from  Builder

Details

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

Register a custom macro.

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 44
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

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 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 72
static void flushMacros()

Flush the existing macros.

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

Return Value

void

in Macroable at line 83
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 108
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Builder at line 70
__construct(Connection $connection)

Create a new database Schema manager.

Parameters

Connection $connection

in Builder at line 84
static void defaultStringLength(int $length)

Set the default string length for migrations.

The length persists in a static property for the worker lifetime and applies to every Blueprint::string() across all coroutines.

Parameters

int $length

Return Value

void

in Builder at line 96
static void defaultTimePrecision(int|null $precision)

Set the default time precision for migrations.

The precision persists in a static property for the worker lifetime and applies to every time/datetime column across all coroutines.

Parameters

int|null $precision

Return Value

void

in Builder at line 110
static void defaultMorphKeyType(string $type)

Set the default morph key type for migrations.

The type persists in a static property for the worker lifetime and applies to every morph() column across all coroutines.

Parameters

string $type

Return Value

void

Exceptions

InvalidArgumentException

in Builder at line 125
static void morphUsingUuids()

Set the default morph key type for migrations to UUIDs.

Sets the worker-wide morph type via defaultMorphKeyType().

Return Value

void

in Builder at line 136
static void morphUsingUlids()

Set the default morph key type for migrations to ULIDs.

Sets the worker-wide morph type via defaultMorphKeyType().

Return Value

void

in Builder at line 145
bool createDatabase(string $name)

Create a database in the schema.

Parameters

string $name

Return Value

bool

in Builder at line 155
bool dropDatabaseIfExists(string $name)

Drop a database from the schema if the database exists.

Parameters

string $name

Return Value

bool

in Builder at line 167
array getSchemas()

Get the schemas that belong to the connection.

Return Value

array

in Builder at line 177
bool hasTable(string $table)

Determine if the given table exists.

Parameters

string $table

Return Value

bool

in Builder at line 199
bool hasView(string $view)

Determine if the given view exists.

Parameters

string $view

Return Value

bool

in Builder at line 220
array getTables(array|string|null $schema = null)

Get the tables that belong to the connection.

Parameters

array|string|null $schema

Return Value

array

in Builder at line 232
array getTableListing(array|string|null $schema = null, bool $schemaQualified = true)

Get the names of the tables that belong to the connection.

Parameters

array|string|null $schema
bool $schemaQualified

Return Value

array

in Builder at line 245
array getViews(array|string|null $schema = null)

Get the views that belong to the connection.

Parameters

array|string|null $schema

Return Value

array

in Builder at line 257
array getTypes(array|string|null $schema = null)

Get the user-defined types that belong to the connection.

Parameters

array|string|null $schema

Return Value

array

in Builder at line 267
bool hasColumn(string $table, string $column)

Determine if the given table has a given column.

Parameters

string $table
string $column

Return Value

bool

in Builder at line 281
bool hasColumns(string $table, array $columns)

Determine if the given table has given columns.

Parameters

string $table
array $columns

Return Value

bool

in Builder at line 298
void whenTableHasColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table has a given column.

Parameters

string $table
string $column
Closure $callback

Return Value

void

in Builder at line 308
void whenTableDoesntHaveColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table doesn't have a given column.

Parameters

string $table
string $column
Closure $callback

Return Value

void

in Builder at line 318
void whenTableHasIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table has a given index.

Parameters

string $table
array|string $index
Closure $callback
string|null $type

Return Value

void

in Builder at line 328
void whenTableDoesntHaveIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table doesn't have a given index.

Parameters

string $table
array|string $index
Closure $callback
string|null $type

Return Value

void

in Builder at line 340
string getColumnType(string $table, string $column, bool $fullDefinition = false)

Get the data type for the given column name.

Parameters

string $table
string $column
bool $fullDefinition

Return Value

string

Exceptions

InvalidArgumentException

in Builder at line 356
array getColumnListing(string $table)

Get the column listing for a given table.

Parameters

string $table

Return Value

array

in Builder at line 366
array getColumn(string $table, string $column)

Get the column for a given table.

Parameters

string $table
string $column

Return Value

array

in Builder at line 390
array getColumns(string $table)

Get the columns for a given table.

Parameters

string $table

Return Value

array

in Builder at line 408
array getIndexes(string $table)

Get the indexes for a given table.

Parameters

string $table

Return Value

array

in Builder at line 426
array getIndexListing(string $table)

Get the names of the indexes for a given table.

Parameters

string $table

Return Value

array

in Builder at line 438
string qualifyIndexName(string $name)

Qualify an explicit index name.

The configured table prefix is applied only when index prefixing is enabled. Names are always lowercased, with dashes and dots normalized to underscores to match generated index names.

Parameters

string $name

Return Value

string

in Builder at line 450
bool hasIndex(string $table, array|string $index, string|null $type = null)

Determine if the given table has a given index.

Parameters

string $table
array|string $index
string|null $type

Return Value

bool

in Builder at line 473
bool hasForeignKey(string $table, array|string $foreignKey)

Determine if the table has a given foreign key.

Parameters

string $table
array|string $foreignKey

Return Value

bool

in Builder at line 489
array getForeignKeys(string $table)

Get the foreign keys for a given table.

Parameters

string $table

Return Value

array

in Builder at line 507
array getPartitions(string $table)

Get the partitions of a given table.

Parameters

string $table

Return Value

array

in Builder at line 523
void table(string $table, Closure $callback)

Modify a table on the schema.

Parameters

string $table
Closure $callback

Return Value

void

in Builder at line 531
void create(string $table, Closure $callback)

Create a new table on the schema.

Parameters

string $table
Closure $callback

Return Value

void

in Builder at line 548
void createRangePartition(string $table, string $partition, array $from, array $to)

Create a partition of a range-partitioned table for the given bounds.

Each bound lists one value per partition column, from inclusive and to exclusive.

Parameters

string $table
string $partition
array $from
array $to

Return Value

void

in Builder at line 558
void createMigrationRepositoryTable(string $table)

Create the migration repository table for this database driver.

Parameters

string $table

Return Value

void

in Builder at line 573
void drop(string $table)

Drop a table from the schema.

Parameters

string $table

Return Value

void

in Builder at line 583
void dropIfExists(string $table)

Drop a table from the schema if it exists.

Parameters

string $table

Return Value

void

in Builder at line 595
void dropColumns(string $table, array|string $columns)

Drop columns from a table schema.

Parameters

string $table
array|string $columns

Return Value

void

at line 18
void dropAllTables()

Drop all tables from the database.

Return Value

void

at line 37
void dropAllViews()

Drop all views from the database.

Return Value

void

in Builder at line 627
void dropAllTypes()

Drop all types from the database.

Return Value

void

Exceptions

LogicException

in Builder at line 637
void truncateTables(array $tables)

Truncate the given tables if they contain rows.

Parameters

array $tables

Return Value

void

in Builder at line 661
array withoutCoveredPartitions(array $tables, array $except = [])

Remove the partitions whose ancestors are among the given tables or excepted.

An operation on a partitioned table covers its partitions, and an excepted one keeps them, so only partitions of other tables remain, as tables of their own.

Parameters

array $tables
array $except

Return Value

array

in Builder at line 689
void rename(string $from, string $to)

Rename a table on the schema.

Parameters

string $from
string $to

Return Value

void

in Builder at line 699
bool enableForeignKeyConstraints()

Enable foreign key constraints.

Return Value

bool

in Builder at line 709
bool disableForeignKeyConstraints()

Disable foreign key constraints.

Return Value

bool

in Builder at line 724
mixed withoutForeignKeyConstraints(Closure $callback)

Disable foreign key constraints during the execution of a callback.

Parameters

Closure $callback

Return Value

mixed

at line 54
protected bool foreignKeyConstraintsAreEnabled()

Determine whether foreign key constraints are enabled.

Return Value

bool

in Builder at line 764
protected void setForeignKeyConstraints(bool $enabled)

Set the foreign key constraint state for an internal suppression scope.

Parameters

bool $enabled

Return Value

void

in Builder at line 784
protected void executeSessionStatement(string $statement)

Execute internal physical-session maintenance.

Parameters

string $statement

Return Value

void

in Builder at line 792
void ensureVectorExtensionExists(string|null $schema = null)

Create the vector extension on the schema if it does not exist.

Parameters

string|null $schema

Return Value

void

in Builder at line 802
void ensureExtensionExists(string $name, string|null $schema = null)

Create a new extension on the schema if it does not exist.

Parameters

string $name
string|null $schema

Return Value

void

Exceptions

RuntimeException

in Builder at line 819
void executeBlueprint(Blueprint $blueprint)

Execute the given schema blueprint.

Parameters

Blueprint $blueprint

Return Value

void

in Builder at line 827
protected void build(Blueprint $blueprint)

Execute the blueprint to build / modify the table.

Parameters

Blueprint $blueprint

Return Value

void

in Builder at line 837
protected void executeStatements(array $statements)

Execute the given schema statements in order.

Parameters

array $statements

Return Value

void

in Builder at line 849
protected array selectMetadata(string $query)

Read schema metadata from the same write connection that migrations mutate.

Parameters

string $query

Return Value

array

in Builder at line 859
protected mixed scalarMetadata(string $query)

Read a scalar result through the metadata execution hook.

Parameters

string $query

Return Value

mixed

Exceptions

MultipleColumnsSelectedException

in Builder at line 875
protected bool commandsAreDeclaredOn(Blueprint $blueprint, string $grammar)

Determine whether every executable command is declared by the framework grammar.

Parameters

Blueprint $blueprint
string $grammar

Return Value

bool

in Builder at line 893
protected Blueprint createBlueprint(string $table, Closure|null $callback = null)

Create a new command set with a Closure.

Parameters

string $table
Closure|null $callback

Return Value

Blueprint

at line 66
array|null getCurrentSchemaListing()

Get the names of current schemas for the connection.

Return Value

array|null

in Builder at line 917
string|null getCurrentSchemaName()

Get the default schema name for the connection.

Return Value

string|null

in Builder at line 929
array parseSchemaAndTable(string $reference, bool|string|null $withDefaultSchema = null)

Parse the given database object reference and extract the schema and table.

Parameters

string $reference
bool|string|null $withDefaultSchema

Return Value

array

Exceptions

InvalidArgumentException

in Builder at line 954
Connection getConnection()

Get the database connection instance.

Return Value

Connection

in Builder at line 964
void blueprintResolver(Closure $resolver)

Set the Schema Blueprint resolver callback.

Parameters

Closure $resolver

Return Value

void

in Builder at line 972
static void flushState()

Flush all static state.

Return Value

void