1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-14 10:28:01 +01:00
postgres/lib/functions.php
Aaron Piotrowski fac9041cac
Update and fix code styles
Changed to match code styles used in other Amp packages.
2017-06-20 22:59:42 -05:00

38 lines
1013 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.
*/
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 = ConnectionPool::DEFAULT_MAX_CONNECTIONS): Pool {
return new ConnectionPool($connectionString, $maxConnections);
}