Skip to content

Commit

Permalink
feat: Add column count to tables comment (#6) (#8)
Browse files Browse the repository at this point in the history
* added column count to tables command

Co-authored-by: innoflash <[email protected]>
  • Loading branch information
owenconti and innoflash authored May 2, 2020
1 parent 0cdea4c commit 152ab62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/Commands/ListTablesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ class ListTablesCommand extends Command

public function handle(SchemaContract $schema)
{
$headers = ['Tables'];
$headers = ['Tables', 'Columns'];
$rows = $schema->getTables();

$rows = collect($rows)
->map(function ($row) use ($schema) {
return array_merge($row, [count($schema->getColumns($row[0]))]);
})->toArray();

$this->table($headers, $rows);
}
}
17 changes: 9 additions & 8 deletions src/LaravelSchemaListServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

class LaravelSchemaListServiceProvider extends ServiceProvider
{
private $connections = [
MySqlConnection::class => MySQLSchema::class,
PostgresConnection::class => PostgresSchema::class,
];

/**
* Bootstrap the application services.
*/
Expand All @@ -29,14 +34,10 @@ public function boot()

$this->app->bind(SchemaContract::class, function () {
$connection = resolve(ConnectionInterface::class);

if ($connection instanceof MySqlConnection) {
return new MySQLSchema($connection);
} elseif ($connection instanceof PostgresConnection) {
return new PostgresSchema($connection);
}

return new UnsupportedSchema($connection);
$connectionClass = get_class($connection);
$schema = $this->connections[$connectionClass] ?? UnsupportedSchema::class;

return new $schema($connection);
});
}
}
Expand Down

0 comments on commit 152ab62

Please sign in to comment.