Skip to content

Commit

Permalink
Update examples and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Oct 15, 2018
1 parent 6306f4f commit 01f9b5c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ Prepared statements and parameterized queries support named placeholders, as wel
More examples can be found in the [`examples`](examples) directory.

```php
use Amp\Postgres;
use Amp\Postgres\ConnectionConfig;

Amp\Loop::run(function () {
/** @var \Amp\Postgres\Pool $pool */
$pool = Amp\Postgres\pool("host=localhost user=postgres dbname=test");
$config = ConnectionConfig::fromString("host=localhost user=postgres dbname=test");

/** @var Postgres\Pool $pool */
$pool = Postgres\pool($config);

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

/** @var \Amp\Postgres\ResultSet $result */
/** @var Postgres\ResultSet $result */
$result = yield $statement->execute(['id' => 1337]);
while (yield $result->advance()) {
$row = $result->getCurrent();
Expand Down
6 changes: 2 additions & 4 deletions examples/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
use Amp\Postgres;

Amp\Loop::run(function () {
$host = 'localhost';
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
$user = 'postgres';
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');

/** @var \Amp\Postgres\Connection $connection */
$connection = yield Postgres\connect(new Postgres\ConnectionConfig($host, $port, $user));
$connection = yield Postgres\connect($config);

/** @var \Amp\Postgres\ResultSet $result */
$result = yield $connection->query('SHOW ALL');
Expand Down
6 changes: 2 additions & 4 deletions examples/listen.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
use Amp\Postgres;

Loop::run(function () {
$host = 'localhost';
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
$user = 'postgres';
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');

$pool = Postgres\pool(new Postgres\ConnectionConfig($host, $port, $user));
$pool = Postgres\pool($config);

$channel = "test";

Expand Down
6 changes: 2 additions & 4 deletions examples/multi-listen.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use Amp\Postgres;

Loop::run(function () {
$host = 'localhost';
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
$user = 'postgres';
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');

$pool = Postgres\pool(new Postgres\ConnectionConfig($host, $port, $user));
$pool = Postgres\pool($config);

$channel1 = "test1";
$channel2 = "test2";
Expand Down
6 changes: 2 additions & 4 deletions examples/transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
use Amp\Postgres;

Amp\Loop::run(function () {
$host = 'localhost';
$port = Postgres\ConnectionConfig::DEFAULT_PORT;
$user = 'postgres';
$config = Postgres\ConnectionConfig::fromString('host=localhost user=postgres');

$pool = Postgres\pool(new Postgres\ConnectionConfig($host, $port, $user));
$pool = Postgres\pool($config);

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

Expand Down

0 comments on commit 01f9b5c

Please sign in to comment.