0 follower

Final Class Yiisoft\Db\Migration\MigrationBuilder

InheritanceYiisoft\Db\Migration\MigrationBuilder

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Db\Migration\MigrationBuilder
addColumn() Builds and executes an SQL statement for adding a new DB column. Yiisoft\Db\Migration\MigrationBuilder
addCommentOnColumn() Builds and execute a SQL statement for adding comment to column. Yiisoft\Db\Migration\MigrationBuilder
addCommentOnTable() Builds an SQL statement for adding comment to table. Yiisoft\Db\Migration\MigrationBuilder
addForeignKey() Builds and executes an SQL statement for adding a foreign key constraint to an existing table. Yiisoft\Db\Migration\MigrationBuilder
addPrimaryKey() Builds and executes an SQL statement for creating a primary key. Yiisoft\Db\Migration\MigrationBuilder
alterColumn() Builds and executes an SQL statement for changing the definition of a column. Yiisoft\Db\Migration\MigrationBuilder
batchInsert() Creates and executes a batch INSERT SQL statement. Yiisoft\Db\Migration\MigrationBuilder
columnBuilder() Yiisoft\Db\Migration\MigrationBuilder
createIndex() Builds and executes an SQL statement for creating a new index. Yiisoft\Db\Migration\MigrationBuilder
createTable() Builds and executes an SQL statement for creating a new DB table. Yiisoft\Db\Migration\MigrationBuilder
createView() Builds and executes an SQL statement for creating a view. Yiisoft\Db\Migration\MigrationBuilder
delete() Creates and executes a DELETE SQL statement. Yiisoft\Db\Migration\MigrationBuilder
dropColumn() Builds and executes an SQL statement for dropping a DB column. Yiisoft\Db\Migration\MigrationBuilder
dropCommentFromColumn() Builds and execute a SQL statement for dropping comment from column. Yiisoft\Db\Migration\MigrationBuilder
dropCommentFromTable() Builds a SQL statement for dropping comment from table. Yiisoft\Db\Migration\MigrationBuilder
dropForeignKey() Builds an SQL statement for dropping a foreign key constraint. Yiisoft\Db\Migration\MigrationBuilder
dropIndex() Builds and executes an SQL statement for dropping an index. Yiisoft\Db\Migration\MigrationBuilder
dropPrimaryKey() Builds and executes an SQL statement for dropping a primary key. Yiisoft\Db\Migration\MigrationBuilder
dropTable() Builds and executes an SQL statement for dropping a DB table. Yiisoft\Db\Migration\MigrationBuilder
dropView() Builds and executes an SQL statement for dropping a DB view. Yiisoft\Db\Migration\MigrationBuilder
execute() Executes a SQL statement. Yiisoft\Db\Migration\MigrationBuilder
getDb() Yiisoft\Db\Migration\MigrationBuilder
insert() Creates and executes an INSERT SQL statement. Yiisoft\Db\Migration\MigrationBuilder
renameColumn() Builds and executes an SQL statement for renaming a column. Yiisoft\Db\Migration\MigrationBuilder
renameTable() Builds and executes an SQL statement for renaming a DB table. Yiisoft\Db\Migration\MigrationBuilder
truncateTable() Builds and executes an SQL statement for truncating a DB table. Yiisoft\Db\Migration\MigrationBuilder
update() Creates and executes an UPDATE SQL statement. Yiisoft\Db\Migration\MigrationBuilder
upsert() Creates and executes a command to insert rows into a database table if they do not already exist (matching unique constraints), or update them if they do. Yiisoft\Db\Migration\MigrationBuilder

Protected Methods

Hide inherited methods

Method Description Defined By
beginCommand() Prepares for a command to be executed, and outputs to the console. Yiisoft\Db\Migration\MigrationBuilder
endCommand() Finalizes after the command has been executed, and outputs to the console the time elapsed. Yiisoft\Db\Migration\MigrationBuilder

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Db\Connection\ConnectionInterface $db, Yiisoft\Db\Migration\Informer\MigrationInformerInterface $informer, integer|null $maxSqlOutputLength null )
$db \Yiisoft\Db\Connection\ConnectionInterface
$informer Yiisoft\Db\Migration\Informer\MigrationInformerInterface
$maxSqlOutputLength integer|null

                public function __construct(
    private readonly ConnectionInterface $db,
    private readonly MigrationInformerInterface $informer,
    private readonly ?int $maxSqlOutputLength = null,
) {}

            
addColumn() public method

Builds and executes an SQL statement for adding a new DB column.

public void addColumn ( string $table, string $column, \Yiisoft\Db\Schema\Column\ColumnInterface|string $type )
$table string

The table that the new column will be added to. The table name will be properly quoted by the method.

$column string

The name of the new column. The name will be properly quoted by the method.

$type \Yiisoft\Db\Schema\Column\ColumnInterface|string

The column type which can contain a native database column type, {@see \Yiisoft\Db\Constant\ColumnType abstract} or {@see \Yiisoft\Db\Constant\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions into SQL representation. For example, it will convert string not null to varchar(255) not null and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).

The preferred way is to use {@see \Yiisoft\Db\Schema\Column\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

                public function addColumn(string $table, string $column, ColumnInterface|string $type): void
{
    if (is_string($type)) {
        $comment = null;
    } else {
        $comment = $type->getComment();
    }
    $typeAsString = $this->db->getQueryBuilder()->buildColumnDefinition($type);
    $time = $this->beginCommand("add column $column $typeAsString to table $table");
    $this->db->createCommand()->addColumn($table, $column, $type)->execute();
    if ($comment !== null) {
        $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();
    }
    $this->endCommand($time);
}

            
addCommentOnColumn() public method

Builds and execute a SQL statement for adding comment to column.

public void addCommentOnColumn ( string $table, string $column, string $comment )
$table string

The table whose column is to be commented. The method will properly quote the table name.

$column string

The name of the column to be commented. The method will properly quote the column name.

$comment string

The text of the comment to be added. The comment will be properly quoted by the method.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function addCommentOnColumn(string $table, string $column, string $comment): void
{
    $time = $this->beginCommand("Add comment on column $column");
    $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();
    $this->endCommand($time);
}

            
addCommentOnTable() public method

Builds an SQL statement for adding comment to table.

public void addCommentOnTable ( string $table, string $comment )
$table string

The table to be commented. The table name will be properly quoted by the method.

$comment string

The text of the comment to be added. The comment will be properly quoted by the method.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function addCommentOnTable(string $table, string $comment): void
{
    $time = $this->beginCommand("Add comment on table $table");
    $this->db->createCommand()->addCommentOnTable($table, $comment)->execute();
    $this->endCommand($time);
}

            
addForeignKey() public method

Builds and executes an SQL statement for adding a foreign key constraint to an existing table.

The method will quote the name, table, referenceTable parameters before using them in the generated SQL.

public void addForeignKey ( string $table, string $name, string|string[] $columns, string $referenceTable, string|string[] $referenceColumns, string|null $delete null, string|null $update null )
$table string

The name of the table to add foreign key constraint to.

$name string

The name of the foreign key constraint.

$columns string|string[]

The name of the column to add foreign key constraint to. If there are many columns, separate them with commas.

$referenceTable string

The name of the table that the foreign key references to.

$referenceColumns string|string[]

The name of the column that the foreign key references to. If there are many columns, separate them with commas.

$delete string|null

The ON DELETE option. See {@see \Yiisoft\Db\Constant\ReferentialAction} class for possible values.

$update string|null

The ON UPDATE option. See {@see \Yiisoft\Db\Constant\ReferentialAction} class for possible values.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function addForeignKey(
    string $table,
    string $name,
    array|string $columns,
    string $referenceTable,
    array|string $referenceColumns,
    ?string $delete = null,
    ?string $update = null,
): void {
    $time = $this->beginCommand(
        "Add foreign key $name: $table (" . implode(',', (array) $columns) . ')'
        . " references $referenceTable (" . implode(',', (array) $referenceColumns) . ')',
    );
    $this->db->createCommand()->addForeignKey(
        $table,
        $name,
        $columns,
        $referenceTable,
        $referenceColumns,
        $delete,
        $update,
    )->execute();
    $this->endCommand($time);
}

            
addPrimaryKey() public method

Builds and executes an SQL statement for creating a primary key.

The method will properly quote the table and column names.

public void addPrimaryKey ( string $table, string $name, array|string $columns )
$table string

The table that the primary key constraint will be added to.

$name string

The name of the primary key constraint.

$columns array|string

Comma separated string or array of columns that the primary key will consist of.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function addPrimaryKey(string $table, string $name, array|string $columns): void
{
    $time = $this->beginCommand(
        "Add primary key $name on $table (" . implode(',', (array) $columns) . ')',
    );
    $this->db->createCommand()->addPrimaryKey($table, $name, $columns)->execute();
    $this->endCommand($time);
}

            
alterColumn() public method

Builds and executes an SQL statement for changing the definition of a column.

public void alterColumn ( string $table, string $column, \Yiisoft\Db\Schema\Column\ColumnInterface|string $type )
$table string

The table whose column is to be changed. The method will properly quote the table name.

$column string

The name of the column to be changed. The name will be properly quoted by the method.

$type \Yiisoft\Db\Schema\Column\ColumnInterface|string

The column type which can contain a native database column type, {@see \Yiisoft\Db\Constant\ColumnType abstract} or {@see \Yiisoft\Db\Constant\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions into SQL representation. For example, it will convert string not null to varchar(255) not null and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).

The preferred way is to use {@see \Yiisoft\Db\Schema\Column\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function alterColumn(string $table, string $column, ColumnInterface|string $type): void
{
    if (is_string($type)) {
        $comment = null;
    } else {
        $comment = $type->getComment();
    }
    $typeAsString = $this->db->getQueryBuilder()->buildColumnDefinition($type);
    $time = $this->beginCommand("Alter column $column in table $table to $typeAsString");
    $this->db->createCommand()->alterColumn($table, $column, $type)->execute();
    if ($comment !== null) {
        $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();
    }
    $this->endCommand($time);
}

            
batchInsert() public method

Creates and executes a batch INSERT SQL statement.

The method will properly escape the column names and bind the values to be inserted.

public void batchInsert ( string $table, string[] $columns, iterable $rows )
$table string

The table that new rows will be inserted into.

$columns string[]

The column names.

$rows iterable

The rows to be batch inserted into the table

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function batchInsert(string $table, array $columns, iterable $rows): void
{
    $time = $this->beginCommand("Insert into $table");
    $this->db->createCommand()->insertBatch($table, $rows, $columns)->execute();
    $this->endCommand($time);
}

            
beginCommand() protected method

Prepares for a command to be executed, and outputs to the console.

protected float beginCommand ( string $description )
$description string

The description for the command, to be output to the console.

return float

The time before the command is executed, for the time elapsed to be calculated.

                protected function beginCommand(string $description): float
{
    $this->informer->beginCommand($description);
    return microtime(true);
}

            
columnBuilder() public method

public string columnBuilder ( )

                public function columnBuilder(): string
{
    return $this->columnBuilderClass ??= $this->db->getColumnBuilderClass();
}

            
createIndex() public method

Builds and executes an SQL statement for creating a new index.

public void createIndex ( string $table, string $name, string|string[] $columns, string|null $indexType null, string|null $indexMethod null )
$table string

The table that the new index will be created for. The table name will be properly quoted by the method.

$name string

The name of the index. The name will be properly quoted by the method.

$columns string|string[]

The column(s) that should be included in the index. If there are multiple columns, please separate them by commas or use an array. Each column name will be properly quoted by the method. Quoting will be skipped for column names that include a left parenthesis "(".

$indexType string|null

The type of the index supported by DBMS {@see \Yiisoft\Db\Constant\IndexType} - for example: UNIQUE, FULLTEXT, SPATIAL, BITMAP or null as default.

$indexMethod string|null

The index organization method (with USING, not all DBMS).

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function createIndex(
    string $table,
    string $name,
    array|string $columns,
    ?string $indexType = null,
    ?string $indexMethod = null,
): void {
    $time = $this->beginCommand(
        'Create'
        . ($indexType !== null ? ' ' . $indexType : '')
        . " index $name on $table (" . implode(',', (array) $columns) . ')'
        . ($indexMethod !== null ? ' using ' . $indexMethod : ''),
    );
    $this->db->createCommand()->createIndex($table, $name, $columns, $indexType, $indexMethod)->execute();
    $this->endCommand($time);
}

            
createTable() public method

Builds and executes an SQL statement for creating a new DB table.

The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name is the name of the column which will be properly quoted by the method, and definition is the type of the column which can contain a native database column type, {@see \Yiisoft\Db\Constant\ColumnType abstract} or {@see \Yiisoft\Db\Constant\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions into SQL representation. For example, it will convert string not null to varchar(255) not null and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).

The preferred way is to use {@see \Yiisoft\Db\Schema\Column\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

$this->createTable(
    'example_table',
    [
        'id' => ColumnBuilder::primaryKey(),
        'name' => ColumnBuilder::string(64)->notNull(),
        'type' => ColumnBuilder::integer()->notNull()->defaultValue(10),
        'description' => ColumnBuilder::text(),
        'rule_name' => ColumnBuilder::string(64),
        'data' => ColumnBuilder::text(),
        'created_at' => ColumnBuilder::datetime()->notNull(),
        'updated_at' => ColumnBuilder::datetime(),
    ],
);

If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly put into the generated SQL.

public void createTable ( string $table, (\Yiisoft\Db\Schema\Column\ColumnInterface|string)[] $columns, string|null $options null )
$table string

The name of the table to be created. The name will be properly quoted by the method.

$columns (\Yiisoft\Db\Schema\Column\ColumnInterface|string)[]

The columns (name => definition) in the new table.

$options string|null

Additional SQL fragment that will be appended to the generated SQL.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function createTable(string $table, array $columns, ?string $options = null): void
{
    $time = $this->beginCommand("create table $table");
    $this->db->createCommand()->createTable($table, $columns, $options)->execute();
    foreach ($columns as $column => $type) {
        if ($type instanceof ColumnInterface) {
            $comment = $type->getComment();
            if ($comment !== null) {
                $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();
            }
        }
    }
    $this->endCommand($time);
}

            
createView() public method

Builds and executes an SQL statement for creating a view.

public void createView ( string $viewName, \Yiisoft\Db\Query\QueryInterface|string $subQuery )
$viewName string

The name of the view to create.

$subQuery \Yiisoft\Db\Query\QueryInterface|string

The select statement which defines the view. This can be either a string or a {@see \Yiisoft\Db\Query\QueryInterface}.

throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

throws Exception

Note: The method will quote the viewName parameter before using it in the generated SQL.

                public function createView(string $viewName, QueryInterface|string $subQuery): void
{
    $time = $this->beginCommand("Create view $viewName");
    $this->db->createCommand()->createView($viewName, $subQuery)->execute();
    $this->endCommand($time);
}

            
delete() public method

Creates and executes a DELETE SQL statement.

public void delete ( string $table, array|string $condition '', array $params = [] )
$table string

The table where the data will be deleted from.

$condition array|string

The condition to put in the WHERE part. Please refer to {@see \Yiisoft\Db\Query\QueryInterface::where()} on how to specify condition.

$params array

The parameters to be bound to the query.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function delete(string $table, array|string $condition = '', array $params = []): void
{
    $time = $this->beginCommand("Delete from $table");
    $this->db->createCommand()->delete($table, $condition, $params)->execute();
    $this->endCommand($time);
}

            
dropColumn() public method

Builds and executes an SQL statement for dropping a DB column.

public void dropColumn ( string $table, string $column )
$table string

The table whose column is to be dropped. The name will be properly quoted by the method.

$column string

The name of the column to be dropped. The name will be properly quoted by the method.

                public function dropColumn(string $table, string $column): void
{
    $time = $this->beginCommand("drop column $column from table $table");
    $this->db->createCommand()->dropColumn($table, $column)->execute();
    $this->endCommand($time);
}

            
dropCommentFromColumn() public method

Builds and execute a SQL statement for dropping comment from column.

public void dropCommentFromColumn ( string $table, string $column )
$table string

The table whose column is to be commented. The method will properly quote the table name.

$column string

The name of the column to be commented. The method will properly quote the column name.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function dropCommentFromColumn(string $table, string $column): void
{
    $time = $this->beginCommand("Drop comment from column $column");
    $this->db->createCommand()->dropCommentFromColumn($table, $column)->execute();
    $this->endCommand($time);
}

            
dropCommentFromTable() public method

Builds a SQL statement for dropping comment from table.

public void dropCommentFromTable ( string $table )
$table string

The table whose column is to be commented. The method will properly quote the table name.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function dropCommentFromTable(string $table): void
{
    $time = $this->beginCommand("drop comment from table $table");
    $this->db->createCommand()->dropCommentFromTable($table)->execute();
    $this->endCommand($time);
}

            
dropForeignKey() public method

Builds an SQL statement for dropping a foreign key constraint.

public void dropForeignKey ( string $table, string $name )
$table string

The table whose foreign is to be dropped. The name will be properly quoted by the method.

$name string

The name of the foreign key constraint to be dropped. The method will properly quote the name.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function dropForeignKey(string $table, string $name): void
{
    $time = $this->beginCommand("Drop foreign key $name from table $table");
    $this->db->createCommand()->dropForeignKey($table, $name)->execute();
    $this->endCommand($time);
}

            
dropIndex() public method

Builds and executes an SQL statement for dropping an index.

public void dropIndex ( string $table, string $name )
$table string

The table whose index is to be dropped. The name will be properly quoted by the method.

$name string

The name of the index to be dropped. The name will be properly quoted by the method.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function dropIndex(string $table, string $name): void
{
    if ($this->hasIndex($table, $name) === false) {
        $time = $this->beginCommand("Drop index $name on $table skipped. Index does not exist.");
        $this->endCommand($time);
        return;
    }
    $time = $this->beginCommand("Drop index $name on $table");
    $this->db->createCommand()->dropIndex($table, $name)->execute();
    $this->endCommand($time);
}

            
dropPrimaryKey() public method

Builds and executes an SQL statement for dropping a primary key.

public void dropPrimaryKey ( string $table, string $name )
$table string

The table that the primary key constraint will be removed from.

$name string

The name of the primary key constraint to be removed.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function dropPrimaryKey(string $table, string $name): void
{
    $time = $this->beginCommand("Drop primary key $name");
    $this->db->createCommand()->dropPrimaryKey($table, $name)->execute();
    $this->endCommand($time);
}

            
dropTable() public method

Builds and executes an SQL statement for dropping a DB table.

public void dropTable ( string $table )
$table string

The table to be dropped. The name will be properly quoted by the method.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function dropTable(string $table): void
{
    $time = $this->beginCommand("Drop table $table");
    $this->db->createCommand()->dropTable($table)->execute();
    $this->endCommand($time);
}

            
dropView() public method

Builds and executes an SQL statement for dropping a DB view.

public void dropView ( string $viewName )
$viewName string

The name of the view to be dropped.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

Note: The method will quote the viewName parameter before using it in the generated SQL.

                public function dropView(string $viewName): void
{
    $time = $this->beginCommand("Drop view $viewName");
    $this->db->createCommand()->dropView($viewName)->execute();
    $this->endCommand($time);
}

            
endCommand() protected method

Finalizes after the command has been executed, and outputs to the console the time elapsed.

protected void endCommand ( float $time )
$time float

The time before the command was executed.

                protected function endCommand(float $time): void
{
    $this->informer->endCommand('Done in ' . sprintf('%.3f', microtime(true) - $time) . 's.');
}

            
execute() public method

Executes a SQL statement.

This method executes the specified SQL statement using {@see \Yiisoft\Db\Connection\ConnectionInterface}.

See also \Yiisoft\Db\Command\CommandInterface::execute() for more details.

public void execute ( string $sql, array $params = [] )
$sql string

The SQL statement to be executed.

$params array

Input parameters (name => value) for the SQL execution.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function execute(string $sql, array $params = []): void
{
    $command = $this->db->createCommand($sql)->bindValues($params);
    $sqlOutput = trim($command->getRawSql());
    if ($this->maxSqlOutputLength !== null && $this->maxSqlOutputLength < strlen($sqlOutput)) {
        $sqlOutput = ltrim(rtrim(substr($sqlOutput, 0, $this->maxSqlOutputLength)) . ' [... hidden]');
    }
    $time = $this->beginCommand("Execute SQL: $sqlOutput");
    $command->execute();
    $this->endCommand($time);
}

            
getDb() public method

public \Yiisoft\Db\Connection\ConnectionInterface getDb ( )

                public function getDb(): ConnectionInterface
{
    return $this->db;
}

            
insert() public method

Creates and executes an INSERT SQL statement.

The method will properly escape the column names and bind the values to be inserted.

public void insert ( string $table, array $columns )
$table string

The table that new rows will be inserted into.

$columns array

The column data (name => value) to be inserted into the table.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function insert(string $table, array $columns): void
{
    $time = $this->beginCommand("Insert into $table");
    $this->db->createCommand()->insert($table, $columns)->execute();
    $this->endCommand($time);
}

            
renameColumn() public method

Builds and executes an SQL statement for renaming a column.

public void renameColumn ( string $table, string $name, string $newName )
$table string

The table whose column is to be renamed. The name will be properly quoted by the method.

$name string

The old name of the column. The name will be properly quoted by the method.

$newName string

The new name of the column. The name will be properly quoted by the method.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function renameColumn(string $table, string $name, string $newName): void
{
    $time = $this->beginCommand("Rename column $name in table $table to $newName");
    $this->db->createCommand()->renameColumn($table, $name, $newName)->execute();
    $this->endCommand($time);
}

            
renameTable() public method

Builds and executes an SQL statement for renaming a DB table.

public void renameTable ( string $table, string $newName )
$table string

The table to be renamed. The name will be properly quoted by the method.

$newName string

The new table name. The name will be properly quoted by the method.

                public function renameTable(string $table, string $newName): void
{
    $time = $this->beginCommand("rename table $table to $newName");
    $this->db->createCommand()->renameTable($table, $newName)->execute();
    $this->endCommand($time);
}

            
truncateTable() public method

Builds and executes an SQL statement for truncating a DB table.

public void truncateTable ( string $table )
$table string

The table to be truncated. The name will be properly quoted by the method.

                public function truncateTable(string $table): void
{
    $time = $this->beginCommand("truncate table $table");
    $this->db->createCommand()->truncateTable($table)->execute();
    $this->endCommand($time);
}

            
update() public method

Creates and executes an UPDATE SQL statement.

The method will properly escape the column names and bind the values to be updated.

public void update ( string $table, array $columns, array|\Yiisoft\Db\Expression\ExpressionInterface|string $condition '', array|\Yiisoft\Db\Expression\ExpressionInterface|string|null $from null, array $params = [] )
$table string

The table to be updated.

$columns array

The column data (name => value) to be updated.

$condition array|\Yiisoft\Db\Expression\ExpressionInterface|string

The condition to put in the WHERE part. Please refer to {@see \Yiisoft\Db\Query\QueryInterface::where()} on how to specify condition.

$from array|\Yiisoft\Db\Expression\ExpressionInterface|string|null

The condition to put in the FROM part. Please refer to {@see \Yiisoft\Db\Query\QueryInterface::from()} on how to specify condition.

$params array

The parameters to be bound to the query.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function update(
    string $table,
    array $columns,
    array|ExpressionInterface|string $condition = '',
    array|ExpressionInterface|string|null $from = null,
    array $params = [],
): void {
    $time = $this->beginCommand("Update $table");
    $this->db->createCommand()->update($table, $columns, $condition, $from, $params)->execute();
    $this->endCommand($time);
}

            
upsert() public method

Creates and executes a command to insert rows into a database table if they do not already exist (matching unique constraints), or update them if they do.

The method will properly escape the column names and bind the values to be inserted.

public void upsert ( string $table, array|\Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns true )
$table string

The table that new rows will be inserted into/updated in.

$insertColumns array|\Yiisoft\Db\Query\QueryInterface

The column data (name => value) to insert into the table or an instance of {@see \Yiisoft\Db\Query\QueryInterface} to perform INSERT INTO ... SELECT SQL statement.

$updateColumns array|boolean

The column data (name => value) to be updated if they already exist. If true is passed, the column data will be updated to match the insert column data. If false is passed, no update will be performed if the column data already exists.

throws Exception
throws \Yiisoft\Db\Exception\InvalidConfigException
throws \Yiisoft\Db\Exception\NotSupportedException

                public function upsert(
    string $table,
    array|QueryInterface $insertColumns,
    array|bool $updateColumns = true,
): void {
    $time = $this->beginCommand("Upsert into $table");
    $this->db->createCommand()->upsert($table, $insertColumns, $updateColumns)->execute();
    $this->endCommand($time);
}