1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-13 09:57:32 +01:00
postgres/lib/functions.php
Aaron Piotrowski a77e0ec22c
Drop Connection and Pool interfaces
Connection is now an abstract class and Pool is a concrete class. Removed AggregatePool as well.
2018-01-02 21:55:59 -06:00

40 lines
1019 B
PHP

<?php
namespace Amp\Postgres;
use Amp\CancellationToken;
use Amp\Promise;
/**
* @param string $connectionString
* @param \Amp\CancellationToken $token
*
* @return \Amp\Promise<\Amp\Postgres\Connection>
*
* @throws \Amp\Postgres\FailureException If connecting fails.
* @throws \Error If neither ext-pgsql or pecl-pq is loaded.
*
* @codeCoverageIgnore
*/
function connect(string $connectionString, CancellationToken $token = null): Promise {
if (\extension_loaded("pq")) {
return PqConnection::connect($connectionString, $token);
}
if (\extension_loaded("pgsql")) {
return PgSqlConnection::connect($connectionString, $token);
}
throw new \Error("amphp/postgres requires either pecl-pq or ext-pgsql");
}
/**
* @param string $connectionString
* @param int $maxConnections
*
* @return \Amp\Postgres\Pool
*/
function pool(string $connectionString, int $maxConnections = Pool::DEFAULT_MAX_CONNECTIONS): Pool {
return new Pool($connectionString, $maxConnections);
}