1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-30 04:29:12 +01:00

Remove resetConnections

Moved to constructor argument.
This commit is contained in:
Aaron Piotrowski 2018-07-10 18:50:11 -05:00
parent 667a94531c
commit 53d3f8b074
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
4 changed files with 31 additions and 15 deletions

View File

@ -5,6 +5,7 @@ namespace Amp\Postgres;
use Amp\Coroutine;
use Amp\Promise;
use Amp\Sql\AbstractPool;
use Amp\Sql\ConnectionConfig;
use Amp\Sql\Connector;
use Amp\Sql\Pool as SqlPool;
use Amp\Sql\ResultSet as SqlResultSet;
@ -24,6 +25,23 @@ final class Pool extends AbstractPool implements Link
/** @var bool */
private $resetConnections = true;
/**
* @param ConnectionConfig $config
* @param int $maxConnections
* @param int $idleTimeout
* @param bool $resetConnections True to automatically execute RESET ALL on a connection before use.
* @param Connector|null $connector
*/
public function __construct(
ConnectionConfig $config,
int $maxConnections = SqlPool::DEFAULT_MAX_CONNECTIONS,
int $idleTimeout = SqlPool::DEFAULT_IDLE_TIMEOUT,
bool $resetConnections = true,
Connector $connector = null
) {
parent::__construct($config, $maxConnections, $idleTimeout, $connector);
}
/**
* @return Connector The Connector instance defined by the connector() function.
*/
@ -54,14 +72,6 @@ final class Pool extends AbstractPool implements Link
return new PooledResultSet($resultSet, $release);
}
/**
* @param bool $reset True to automatically execute RESET ALL on a connection before it is used by the pool.
*/
public function resetConnections(bool $reset)
{
$this->resetConnections = $reset;
}
protected function pop(): \Generator
{
$connection = yield from parent::pop();

View File

@ -47,13 +47,19 @@ function connect(SqlConnectionConfig $config): Promise
* Create a pool using the global Connector instance.
*
* @param SqlConnectionConfig $config
* @param int $maxConnections
* @param int $maxConnections
* @param int $idleTimeout
* @param bool $resetConnections
*
* @return Pool
*/
function pool(SqlConnectionConfig $config, int $maxConnections = SqlPool::DEFAULT_MAX_CONNECTIONS): Pool
{
return new Pool($config, $maxConnections, connector());
function pool(
SqlConnectionConfig $config,
int $maxConnections = SqlPool::DEFAULT_MAX_CONNECTIONS,
int $idleTimeout = SqlPool::DEFAULT_IDLE_TIMEOUT,
bool $resetConnections = true
): Pool {
return new Pool($config, $maxConnections, $idleTimeout, $resetConnections, connector());
}
/**
@ -114,7 +120,7 @@ function encode(array $array): string
}
$value = (string) $value;
// no break
// no break
case "string":
return '"' . \str_replace(['\\', '"'], ['\\\\', '\\"'], $value) . '"';

View File

@ -38,7 +38,7 @@ class PgSqlPoolTest extends AbstractLinkTest
return new Success(new PgSqlConnection($handle, \pg_socket($handle)));
}));
$pool = new Pool(new ConnectionConfig('connection string'), \count($this->handles), $connector);
$pool = new Pool(new ConnectionConfig('connection string'), \count($this->handles), Pool::DEFAULT_IDLE_TIMEOUT, true, $connector);
$handle = \reset($this->handles);

View File

@ -40,7 +40,7 @@ class PqPoolTest extends AbstractLinkTest
return new Success(new PqConnection($handle));
}));
$pool = new Pool(new ConnectionConfig('connection string'), \count($this->handles), $connector);
$pool = new Pool(new ConnectionConfig('connection string'), \count($this->handles), Pool::DEFAULT_IDLE_TIMEOUT, true, $connector);
$handle = \reset($this->handles);