From 152ab6278b479f637b309945acfe919a44c84204 Mon Sep 17 00:00:00 2001 From: Owen Conti Date: Sat, 2 May 2020 10:14:56 -0600 Subject: [PATCH] feat: Add column count to tables comment (#6) (#8) * added column count to tables command Co-authored-by: innoflash --- src/Commands/ListTablesCommand.php | 7 ++++++- src/LaravelSchemaListServiceProvider.php | 17 +++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Commands/ListTablesCommand.php b/src/Commands/ListTablesCommand.php index 88181ef..0bd1e63 100644 --- a/src/Commands/ListTablesCommand.php +++ b/src/Commands/ListTablesCommand.php @@ -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); } } diff --git a/src/LaravelSchemaListServiceProvider.php b/src/LaravelSchemaListServiceProvider.php index b34a287..4858621 100644 --- a/src/LaravelSchemaListServiceProvider.php +++ b/src/LaravelSchemaListServiceProvider.php @@ -16,6 +16,11 @@ class LaravelSchemaListServiceProvider extends ServiceProvider { + private $connections = [ + MySqlConnection::class => MySQLSchema::class, + PostgresConnection::class => PostgresSchema::class, + ]; + /** * Bootstrap the application services. */ @@ -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); }); } }