Class Yiisoft\Yii\Debug\Api\Inspector\Database\Db\DbSchemaProvider
| Inheritance | Yiisoft\Yii\Debug\Api\Inspector\Database\Db\DbSchemaProvider |
|---|---|
| Implements | Yiisoft\Yii\Debug\Api\Inspector\Database\SchemaProviderInterface |
Public Methods
Method Details
| public mixed __construct ( \Yiisoft\Db\Connection\ConnectionInterface $db ) | ||
| $db | \Yiisoft\Db\Connection\ConnectionInterface | |
public function __construct(private ConnectionInterface $db)
{
}
| public array getTable ( string $tableName ) | ||
| $tableName | string | |
public function getTable(string $tableName): array
{
/** @var TableSchemaInterface[] $tableSchemas */
$schema = $this->db->getSchema()->getTableSchema($tableName);
$records = (new Query($this->db))->from($schema->getName())->all();
$data = [];
// TODO: add pagination
foreach ($records as $r => $record) {
foreach ($record as $n => $attribute) {
$data[$r][$n] = $attribute;
}
}
return [
'table' => $schema->getName(),
'primaryKeys' => $schema->getPrimaryKey(),
'columns' => $this->serializeARColumnsSchemas($schema->getColumns()),
'records' => $data,
];
}
| public array getTables ( ) |
public function getTables(): array
{
$quoter = $this->db->getQuoter();
/** @var TableSchemaInterface[] $tableSchemas */
$tableSchemas = $this->db->getSchema()->getTableSchemas();
$tables = [];
foreach ($tableSchemas as $schema) {
$tables[] = [
'table' => $quoter->unquoteSimpleTableName($schema->getName()),
'primaryKeys' => $schema->getPrimaryKey(),
'columns' => $this->serializeARColumnsSchemas($schema->getColumns()),
'records' => (new Query($this->db))->from($schema->getName())->count(),
];
}
return $tables;
}
Signup or Login in order to comment.