Skip to content

Commit 4b79aa0

Browse files
committed
Move getConnectionCount to Schema\Builder
1 parent a661fae commit 4b79aa0

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/Illuminate/Database/Console/DatabaseInspectionCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ protected function getConnectionName(ConnectionInterface $connection, $database)
2727
*
2828
* @param \Illuminate\Database\ConnectionInterface $connection
2929
* @return int|null
30+
*
31+
* @deprecated Use Schema\Builder::getConnectionCount() instead.
3032
*/
3133
protected function getConnectionCount(ConnectionInterface $connection)
3234
{
33-
$query = $connection->getSchemaGrammar()->compileConnectionCount();
34-
35-
return $query ? $connection->scalar($query) : null;
35+
return $connection->getSchemaBuilder()->getConnectionCount();
3636
}
3737

3838
/**

src/Illuminate/Database/Console/MonitorCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ protected function parseDatabases($databases)
8484
}
8585

8686
$maxConnections = $this->option('max');
87+
$connections = $this->connection->connection($database)->getSchemaBuilder()->getConnectionCount();
8788

8889
return [
8990
'database' => $database,
90-
'connections' => $connections = $this->getConnectionCount($this->connection->connection($database)),
91+
'connections' => $connections,
9192
'status' => $maxConnections && $connections >= $maxConnections ? '<fg=yellow;options=bold>ALERT</>' : '<fg=green;options=bold>OK</>',
9293
];
9394
});

src/Illuminate/Database/Console/ShowCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handle(ConnectionResolverInterface $connections)
4848
'name' => $connection->getDriverTitle(),
4949
'connection' => $connection->getName(),
5050
'version' => $connection->getServerVersion(),
51-
'open_connections' => $this->getConnectionCount($connection),
51+
'open_connections' => $schema->getConnectionCount(),
5252
],
5353
'tables' => $this->tables($connection, $schema),
5454
];

src/Illuminate/Database/Schema/Builder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,18 @@ public function setConnection(Connection $connection)
607607
return $this;
608608
}
609609

610+
/**
611+
* Get the number of open connections for a database.
612+
*
613+
* @return int|null
614+
*/
615+
public function getConnectionCount()
616+
{
617+
$query = $this->grammar->compileConnectionCount();
618+
619+
return $query ? $this->connection->scalar($query) : null;
620+
}
621+
610622
/**
611623
* Set the Schema Blueprint resolver callback.
612624
*

0 commit comments

Comments
 (0)