Skip to content

Commit 01f9b5c

Browse files
committed
Update examples and readme
1 parent 6306f4f commit 01f9b5c

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ Prepared statements and parameterized queries support named placeholders, as wel
3333
More examples can be found in the [`examples`](examples) directory.
3434

3535
```php
36+
use Amp\Postgres;
37+
use Amp\Postgres\ConnectionConfig;
38+
3639
Amp\Loop::run(function () {
37-
/** @var \Amp\Postgres\Pool $pool */
38-
$pool = Amp\Postgres\pool("host=localhost user=postgres dbname=test");
40+
$config = ConnectionConfig::fromString("host=localhost user=postgres dbname=test");
41+
42+
/** @var Postgres\Pool $pool */
43+
$pool = Postgres\pool($config);
3944

40-
/** @var \Amp\Postgres\Statement $statement */
45+
/** @var Postgres\Statement $statement */
4146
$statement = yield $pool->prepare("SELECT * FROM test WHERE id = :id");
4247

43-
/** @var \Amp\Postgres\ResultSet $result */
48+
/** @var Postgres\ResultSet $result */
4449
$result = yield $statement->execute(['id' => 1337]);
4550
while (yield $result->advance()) {
4651
$row = $result->getCurrent();

examples/basic.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
use Amp\Postgres;
77

88
Amp\Loop::run(function () {
9-
$host = 'localhost';
10-
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
11-
$user = 'postgres';
9+
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');
1210

1311
/** @var \Amp\Postgres\Connection $connection */
14-
$connection = yield Postgres\connect(new Postgres\ConnectionConfig($host, $port, $user));
12+
$connection = yield Postgres\connect($config);
1513

1614
/** @var \Amp\Postgres\ResultSet $result */
1715
$result = yield $connection->query('SHOW ALL');

examples/listen.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
use Amp\Postgres;
88

99
Loop::run(function () {
10-
$host = 'localhost';
11-
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
12-
$user = 'postgres';
10+
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');
1311

14-
$pool = Postgres\pool(new Postgres\ConnectionConfig($host, $port, $user));
12+
$pool = Postgres\pool($config);
1513

1614
$channel = "test";
1715

examples/multi-listen.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
use Amp\Postgres;
99

1010
Loop::run(function () {
11-
$host = 'localhost';
12-
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
13-
$user = 'postgres';
11+
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');
1412

15-
$pool = Postgres\pool(new Postgres\ConnectionConfig($host, $port, $user));
13+
$pool = Postgres\pool($config);
1614

1715
$channel1 = "test1";
1816
$channel2 = "test2";

examples/transaction.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
use Amp\Postgres;
77

88
Amp\Loop::run(function () {
9-
$host = 'localhost';
10-
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
11-
$user = 'postgres';
9+
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');
1210

13-
$pool = Postgres\pool(new Postgres\ConnectionConfig($host, $port, $user));
11+
$pool = Postgres\pool($config);
1412

1513
yield $pool->query('DROP TABLE IF EXISTS test');
1614

0 commit comments

Comments
 (0)