isMaria() => 'MariaDB', $connection instanceof MySqlConnection => 'MySQL', $connection instanceof MariaDbConnection => 'MariaDB', $connection instanceof PostgresConnection => 'PostgreSQL', $connection instanceof SQLiteConnection => 'SQLite', $connection instanceof SqlServerConnection => 'SQL Server', default => $database, }; } /** * Get the number of open connections for a database. * * @param \Illuminate\Database\ConnectionInterface $connection * @return int|null */ protected function getConnectionCount(ConnectionInterface $connection) { $result = match (true) { $connection instanceof MySqlConnection => $connection->selectOne('show status where variable_name = "threads_connected"'), $connection instanceof PostgresConnection => $connection->selectOne('select count(*) as "Value" from pg_stat_activity'), $connection instanceof SqlServerConnection => $connection->selectOne('select count(*) Value from sys.dm_exec_sessions where status = ?', ['running']), default => null, }; if (! $result) { return null; } return Arr::wrap((array) $result)['Value']; } /** * Get the connection configuration details for the given connection. * * @param string $database * @return array */ protected function getConfigFromDatabase($database) { $database ??= config('database.default'); return Arr::except(config('database.connections.'.$database), ['password']); } /** * Remove the table prefix from a table name, if it exists. * * @param \Illuminate\Database\ConnectionInterface $connection * @param string $table * @return string */ protected function withoutTablePrefix(ConnectionInterface $connection, string $table) { $prefix = $connection->getTablePrefix(); return str_starts_with($table, $prefix) ? substr($table, strlen($prefix)) : $table; } }