Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Query/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ protected function processColumn(mixed $value): mixed
return $value;
}

/**
* {@inheritDoc}
* @param list<array<string, mixed>> $results
* @return list<array{name: string, schema: string|null, size: int|null, comment: string|null, collation: string|null, engine: string|null, parent: string|null}>
*/
public function processTables($results)
{
return array_map(function ($result) {
$result = (object) $result;

return [
'name' => $result->name,
'schema' => $result->schema !== '' ? $result->schema : null,
'parent' => $result->parent,
'size' => null,
'comment' => null,
'collation' => null,
'engine' => null,
];
}, $results);
}

/**
* Process the results of a columns query.
*
Expand Down
13 changes: 0 additions & 13 deletions src/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ class Builder extends BaseBuilder
*/
public static $defaultMorphKeyType = 'uuid';

/**
* @inheritDoc Adds a parent key, for tracking interleaving
*
* @return list<array{ name: string, type: string, parent: string }>
*/
public function getTables()
{
/** @var list<array{ name: string, type: string, parent: string }> */
return $this->connection->select(
$this->grammar->compileTables(),
);
}

Comment on lines -43 to -55
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parent does exactly the same thing and PhpDoc is not that helpful.

/**
* @param string $table
* @param string $name
Expand Down
12 changes: 11 additions & 1 deletion src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ class Grammar extends BaseGrammar
*/
public function compileTables()
{
return 'select `table_name` as name, `table_type` as type, `parent_table_name` as parent from information_schema.tables where table_schema = \'\' and table_type = \'BASE TABLE\'';
return implode(' ', [
'select',
implode(', ', [
'table_name as name',
'table_schema as `schema`',
'parent_table_name as parent',
]),
'from information_schema.tables',
'where table_type = \'BASE TABLE\'',
'and table_schema = \'\'',
]);
}

/**
Expand Down
16 changes: 10 additions & 6 deletions tests/Schema/BuilderTestLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,17 @@ public function test_getTables(): void
$table->primary('id');
});

/** @var array{ name: string, type: string } $row */
$row = Arr::first(
$sb->getTables(),
static fn(array $row): bool => $row['name'] === $table,
);
$row = Arr::first($sb->getTables(), fn ($row) => $row['name'] === $table);

$this->assertSame($table, $row['name']);
$this->assertSame([
'name' => $table,
'schema' => null,
'parent' => null,
'size' => null,
'comment' => null,
'collation' => null,
'engine' => null,
], $row);
}

public function test_getColumns(): void
Expand Down