1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-15 19:07:26 +01:00
postgres/lib/ConnectionPool.php

47 lines
1.0 KiB
PHP
Raw Normal View History

2016-12-30 06:21:17 +01:00
<?php
2016-09-14 16:27:39 +02:00
namespace Amp\Postgres;
use Amp\Promise;
2016-09-14 16:27:39 +02:00
class ConnectionPool extends AbstractPool {
const DEFAULT_MAX_CONNECTIONS = 100;
/** @var string */
private $connectionString;
/** @var int */
private $maxConnections;
/**
* @param string $connectionString
* @param int $maxConnections
*
* @throws \Error If $maxConnections is less than 1.
2016-09-14 16:27:39 +02:00
*/
2017-06-05 06:42:18 +02:00
public function __construct(string $connectionString, int $maxConnections = self::DEFAULT_MAX_CONNECTIONS) {
2016-09-14 16:27:39 +02:00
parent::__construct();
$this->connectionString = $connectionString;
$this->maxConnections = $maxConnections;
if ($this->maxConnections < 1) {
throw new \Error("Pool must contain at least one connection");
2016-09-14 16:27:39 +02:00
}
}
/**
* {@inheritdoc}
*/
2016-11-15 18:06:21 +01:00
protected function createConnection(): Promise {
2017-06-05 06:42:18 +02:00
return connect($this->connectionString);
2016-09-14 16:27:39 +02:00
}
/**
* {@inheritdoc}
*/
public function getMaxConnections(): int {
return $this->maxConnections;
}
}