Class Yiisoft\Yii\Debug\Api\Inspector\Database\Db\DbSchemaProvider
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Public Methods
Method Details
| public mixed __construct ( \ | ||
| $db | \ |
|
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;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.