Trait luya\testsuite\traits\DatabaseTableTrait

Available since version1.0.21
Source Code https://github.com/luyadev/luya-testsuite/blob/master/src/traits/DatabaseTableTrait.php

Base Trait for Database Actions.

Method Details

Hide inherited methods

createTableIfNotExists() public method

Create a table if not exists

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

                public function createTableIfNotExists($table, array $columns)
{
    if ($this->getDatabaseComponent()->getTableSchema($table, true) === null) {
        $this->getDatabaseComponent()->createCommand()->createTable($table, $columns)->execute();
    }
}

            
deleteRow() public method

Delete row

public integer deleteRow ( $table, array $condition )
$table string
$condition array
return integer

Returns the number of rows deleted.

                public function deleteRow($table, array $condition)
{
    return $this->getDatabaseComponent()->createCommand()->delete($table, $condition)->execute();
}

            
dropTableIfExists() public method

Drop a table if not exists.

public void dropTableIfExists ( $table )
$table string

                public function dropTableIfExists($table)
{
    if ($this->getDatabaseComponent()->getTableSchema($table, true) !== null) {
        $this->getDatabaseComponent()->createCommand()->dropTable($table)->execute();
    }
}

            
getDatabaseComponent() public method

public yii\db\Connection getDatabaseComponent ( )

                public function getDatabaseComponent()
{
    return $this->app->db;
}

            
insertRow() public method

Insert row

public integer insertRow ( $table, array $values )
$table string
$values array
return integer

Returns the number of rows inserted.

                public function insertRow($table, array $values)
{
    return $this->getDatabaseComponent()->createCommand()->insert($table, $values)->execute();
}