Skip to content

Commit cb5893f

Browse files
committed
Move the queries to the Grammar classes and show the driver name
1 parent c11ea92 commit cb5893f

12 files changed

+63
-79
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,24 +1347,6 @@ public function getDriverName()
13471347
return $this->getConfig('driver');
13481348
}
13491349

1350-
/**
1351-
* Get a human-readable name for the given connection.
1352-
*/
1353-
public function getConnectionName(): string
1354-
{
1355-
return $this->getName().'('.$this->getDriverName().')';
1356-
}
1357-
1358-
/**
1359-
* Get the number of open connections for a database.
1360-
*
1361-
* @return int|null
1362-
*/
1363-
public function getConnectionCount(): ?int
1364-
{
1365-
return null;
1366-
}
1367-
13681350
/**
13691351
* Get the query grammar used by the connection.
13701352
*

src/Illuminate/Database/Console/DatabaseInspectionCommand.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Database\ConnectionInterface;
7+
use Illuminate\Database\MariaDbConnection;
8+
use Illuminate\Database\MySqlConnection;
9+
use Illuminate\Database\PostgresConnection;
10+
use Illuminate\Database\SQLiteConnection;
11+
use Illuminate\Database\SqlServerConnection;
712
use Illuminate\Support\Arr;
813

914
abstract class DatabaseInspectionCommand extends Command
@@ -14,10 +19,20 @@ abstract class DatabaseInspectionCommand extends Command
1419
* @param \Illuminate\Database\ConnectionInterface $connection
1520
* @param string $database
1621
* @return string
22+
*
23+
* @deprecated Use $connection->getName() instead.
1724
*/
1825
protected function getConnectionName(ConnectionInterface $connection, $database)
1926
{
20-
return method_exists($connection, 'getConnectionName') ? $connection->getConnectionName() : $database;
27+
return match (true) {
28+
$connection instanceof MariaDbConnection => 'MariaDB',
29+
$connection instanceof MySqlConnection && $connection->isMaria() => 'MariaDB',
30+
$connection instanceof MySqlConnection => 'MySQL',
31+
$connection instanceof PostgresConnection => 'PostgreSQL',
32+
$connection instanceof SQLiteConnection => 'SQLite',
33+
$connection instanceof SqlServerConnection => 'SQL Server',
34+
default => $database,
35+
};
2136
}
2237

2338
/**
@@ -28,7 +43,7 @@ protected function getConnectionName(ConnectionInterface $connection, $database)
2843
*/
2944
protected function getConnectionCount(ConnectionInterface $connection)
3045
{
31-
return method_exists($connection, 'getConnectionCount') ? $connection->getConnectionCount() : null;
46+
return $connection->getQueryGrammar()->getConnectionCount();
3247
}
3348

3449
/**

src/Illuminate/Database/Console/ShowCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public function handle(ConnectionResolverInterface $connections)
4545
$data = [
4646
'platform' => [
4747
'config' => $this->getConfigFromDatabase($database),
48-
'name' => $this->getConnectionName($connection, $database),
48+
'name' => $connection->getName(),
49+
'driver' => method_exists($connection, 'getDriverName') ? $connection->getDriverName() : $connection::class,
4950
'version' => $connection->getServerVersion(),
5051
'open_connections' => $this->getConnectionCount($connection),
5152
],
@@ -159,6 +160,7 @@ protected function displayForCli(array $data)
159160
$this->newLine();
160161

161162
$this->components->twoColumnDetail('<fg=green;options=bold>'.$platform['name'].'</>', $platform['version']);
163+
$this->components->twoColumnDetail('Driver', Arr::get($platform['config'], 'driver'));
162164
$this->components->twoColumnDetail('Database', Arr::get($platform['config'], 'database'));
163165
$this->components->twoColumnDetail('Host', Arr::get($platform['config'], 'host'));
164166
$this->components->twoColumnDetail('Port', Arr::get($platform['config'], 'port'));

src/Illuminate/Database/MariaDbConnection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public function getServerVersion(): string
3232
return Str::between(parent::getServerVersion(), '5.5.5-', '-MariaDB');
3333
}
3434

35-
public function getConnectionName(): string
36-
{
37-
return $this->getName().' (MariaDB)';
38-
}
39-
4035
/**
4136
* Get the default query grammar instance.
4237
*

src/Illuminate/Database/MySqlConnection.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,6 @@ public function isMaria()
4848
return str_contains($this->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), 'MariaDB');
4949
}
5050

51-
public function getConnectionName(): string
52-
{
53-
return $this->getName().' ('.($this->isMaria() ? 'MariaDB' : 'MySQL').')';
54-
}
55-
56-
public function getConnectionCount(): ?int
57-
{
58-
$result = $this->selectOne('show status where variable_name = "threads_connected"');
59-
60-
if (! $result) {
61-
return null;
62-
}
63-
64-
return (int) $result['Value'];
65-
}
66-
6751
/**
6852
* Get the server version for the connection.
6953
*

src/Illuminate/Database/PostgresConnection.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@
1212

1313
class PostgresConnection extends Connection
1414
{
15-
public function getConnectionName(): string
16-
{
17-
return $this->getName().' (PostgreSQL)';
18-
}
19-
20-
public function getConnectionCount(): ?int
21-
{
22-
$result = $this->selectOne('select count(*) as "Value" from pg_stat_activity');
23-
24-
if (! $result) {
25-
return null;
26-
}
27-
28-
return (int) $result['Value'];
29-
}
30-
3115
/**
3216
* Escape a binary value for safe SQL embedding.
3317
*

src/Illuminate/Database/Query/Grammars/Grammar.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,4 +1564,14 @@ public function getBitwiseOperators()
15641564
{
15651565
return $this->bitwiseOperators;
15661566
}
1567+
1568+
/**
1569+
* Get the number of open connections for a database.
1570+
*
1571+
* @return int|null
1572+
*/
1573+
public function getConnectionCount(): ?int
1574+
{
1575+
return null;
1576+
}
15671577
}

src/Illuminate/Database/Query/Grammars/MySqlGrammar.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,15 @@ protected function wrapJsonBooleanSelector($value)
514514

515515
return 'json_extract('.$field.$path.')';
516516
}
517+
518+
public function getConnectionCount(): ?int
519+
{
520+
$result = $this->connection->selectOne('show status where variable_name = "threads_connected"');
521+
522+
if (! $result) {
523+
return null;
524+
}
525+
526+
return (int) $result['Value'];
527+
}
517528
}

src/Illuminate/Database/Query/Grammars/PostgresGrammar.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,4 +762,15 @@ public function substituteBindingsIntoRawSql($sql, $bindings)
762762

763763
return $query;
764764
}
765+
766+
public function getConnectionCount(): ?int
767+
{
768+
$result = $this->connection->selectOne('select count(*) as "Value" from pg_stat_activity');
769+
770+
if (! $result) {
771+
return null;
772+
}
773+
774+
return (int) $result['Value'];
775+
}
765776
}

src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,4 +571,15 @@ protected function wrapTableValuedFunction($table)
571571

572572
return $table;
573573
}
574+
575+
public function getConnectionCount(): ?int
576+
{
577+
$result = $this->connection->selectOne('select count(*) Value from sys.dm_exec_sessions where status = ?', ['running']);
578+
579+
if (! $result) {
580+
return null;
581+
}
582+
583+
return (int) $result['Value'];
584+
}
574585
}

src/Illuminate/Database/SQLiteConnection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public function __construct($pdo, $database = '', $tablePrefix = '', array $conf
3131
$this->configureSynchronous();
3232
}
3333

34-
public function getConnectionName(): string
35-
{
36-
return $this->getName().' (SQLite)';
37-
}
38-
3934
/**
4035
* Enable or disable foreign key constraints if configured.
4136
*

src/Illuminate/Database/SqlServerConnection.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,6 @@ protected function getDefaultQueryGrammar()
9090
return $this->withTablePrefix($grammar);
9191
}
9292

93-
public function getConnectionName(): string
94-
{
95-
return $this->getName().' (SQL Server)';
96-
}
97-
98-
public function getConnectionCount(): ?int
99-
{
100-
$result = $this->selectOne('select count(*) Value from sys.dm_exec_sessions where status = ?', ['running']);
101-
102-
if (! $result) {
103-
return null;
104-
}
105-
106-
return (int) $result['Value'];
107-
}
108-
10993
/**
11094
* Get a schema builder instance for the connection.
11195
*

0 commit comments

Comments
 (0)