vendor/friendsofdoctrine/dbal-clickhouse/src/Driver.php line 53

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
  5.  * for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
  6.  *
  7.  * (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace FOD\DBALClickHouse;
  13. use Doctrine\DBAL\Connection;
  14. /**
  15.  * ClickHouse Driver
  16.  */
  17. class Driver implements \Doctrine\DBAL\Driver
  18. {
  19.     /**
  20.      * {@inheritDoc}
  21.      */
  22.     public function connect(array $params$username null$password null, array $driverOptions = []) : ClickHouseConnection
  23.     {
  24.         if ($username === null) {
  25.             if (! isset($params['user'])) {
  26.                 throw new ClickHouseException('Connection parameter `user` is required');
  27.             }
  28.             $username $params['user'];
  29.         }
  30.         if ($password === null) {
  31.             if (! isset($params['password'])) {
  32.                 throw new ClickHouseException('Connection parameter `password` is required');
  33.             }
  34.             $password $params['password'];
  35.         }
  36.         if (! isset($params['host'])) {
  37.             throw new ClickHouseException('Connection parameter `host` is required');
  38.         }
  39.         if (! isset($params['port'])) {
  40.             throw new ClickHouseException('Connection parameter `port` is required');
  41.         }
  42.         return new ClickHouseConnection($params, (string) $username, (string) $password$this->getDatabasePlatform());
  43.     }
  44.     /**
  45.      * {@inheritDoc}
  46.      */
  47.     public function getDatabasePlatform() : ClickHousePlatform
  48.     {
  49.         return new ClickHousePlatform();
  50.     }
  51.     /**
  52.      * {@inheritDoc}
  53.      */
  54.     public function getSchemaManager(Connection $conn) : ClickHouseSchemaManager
  55.     {
  56.         return new ClickHouseSchemaManager($conn);
  57.     }
  58.     /**
  59.      * {@inheritDoc}
  60.      */
  61.     public function getName() : string
  62.     {
  63.         return 'clickhouse';
  64.     }
  65.     /**
  66.      * {@inheritDoc}
  67.      */
  68.     public function getDatabase(Connection $conn) : string
  69.     {
  70.         $params $conn->getParams();
  71.         return $params['dbname'] ?? $conn->fetchOne('SELECT currentDatabase() as dbname');
  72.     }
  73. }