|
1 | | -# PostgreSQL Client for Amp |
| 1 | +<p align="center"> |
| 2 | +<a href="https://amphp.org/postgres"><img src="https://raw.githubusercontent.com/amphp/logo/master/repos/postgres.png?v=12-07-2017" alt="postgres"/></a> |
| 3 | +</p> |
2 | 4 |
|
3 | | -This library is a component for [Amp](https://github.com/amphp/amp) that provides an asynchronous client for PostgreSQL. |
| 5 | +<p align="center"> |
| 6 | +<a href="https://travis-ci.org/amphp/postgres"><img src="https://img.shields.io/travis/amphp/postgres/master.svg?style=flat-square" alt="Build Status"/></a> |
| 7 | +<a href="https://coveralls.io/github/amphp/postgres?branch=master"><img src="https://img.shields.io/coveralls/amphp/postgres/master.svg?style=flat-square" alt="Code Coverage"/></a> |
| 8 | +<a href="https://github.com/amphp/postgres/releases"><img src="https://img.shields.io/github/release/amphp/postgres.svg?style=flat-square" alt="Release"/></a> |
| 9 | +<a href="https://github.com/amphp/postgres/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="License"/></a> |
| 10 | +</p> |
4 | 11 |
|
5 | | -[](https://travis-ci.org/amphp/postgres) |
6 | | -[](https://coveralls.io/r/amphp/postgres) |
7 | | -[](http://semver.org) |
8 | | -[](LICENSE) |
9 | | -[](https://twitter.com/asyncphp) |
| 12 | +<p align="center"><strong>Async PostgreSQL client built with <a href="https://amphp.org/">Amp</a>.</strong></p> |
10 | 13 |
|
11 | | -##### Requirements |
| 14 | +## Installation |
12 | 15 |
|
13 | | -- PHP 7+ |
14 | | -- [ext-pgsql](https://secure.php.net/pgsql) or [pecl-pq](https://pecl.php.net/package/pq) |
15 | | - |
16 | | -##### Installation |
17 | | - |
18 | | -The recommended way to install is with the [Composer](http://getcomposer.org/) package manager. (See the [Composer installation guide](https://getcomposer.org/doc/00-intro.md) for information on installing and using Composer.) |
19 | | - |
20 | | -Run the following command to use this library in your project: |
| 16 | +This package can be installed as a [Composer](https://getcomposer.org/) dependency. |
21 | 17 |
|
22 | 18 | ```bash |
23 | 19 | composer require amphp/postgres |
24 | 20 | ``` |
25 | 21 |
|
26 | | -You can also manually edit `composer.json` to add this library as a project requirement. |
| 22 | +## Requirements |
27 | 23 |
|
28 | | -```json |
29 | | -// composer.json |
30 | | -{ |
31 | | - "require": { |
32 | | - "amphp/postgres": "^0.2" |
33 | | - } |
34 | | -} |
35 | | -``` |
36 | | - |
37 | | -#### Example |
38 | | - |
39 | | -```php |
40 | | -#!/usr/bin/env php |
41 | | -<?php |
| 24 | +- PHP 7.0+ |
| 25 | +- [ext-pgsql](https://secure.php.net/pgsql) or [pecl-pq](https://pecl.php.net/package/pq) |
42 | 26 |
|
43 | | -require __DIR__ . '/vendor/autoload.php'; |
| 27 | +## Documentation & Examples |
44 | 28 |
|
45 | | -use Amp\Postgres; |
| 29 | +More examples can be found in the [`examples`](examples) directory. |
46 | 30 |
|
| 31 | +```php |
47 | 32 | Amp\Loop::run(function () { |
48 | | - /** @var \Amp\Postgres\Connection $connection */ |
49 | | - $connection = yield Postgres\connect('host=localhost user=postgres dbname=test'); |
| 33 | + /** @var \Amp\Postgres\Pool $pool */ |
| 34 | + $pool = Amp\Postgres\pool("host=localhost user=postgres dbname=test"); |
50 | 35 |
|
51 | 36 | /** @var \Amp\Postgres\Statement $statement */ |
52 | | - $statement = yield $connection->prepare('SELECT * FROM test WHERE id=$1'); |
53 | | - |
54 | | - /** @var \Amp\Postgres\TupleResult $result */ |
55 | | - $result = yield $statement->execute(1337); |
| 37 | + $statement = yield $pool->prepare("SELECT * FROM test WHERE id=$1"); |
56 | 38 |
|
| 39 | + /** @var \Amp\Postgres\ResultSet $result */ |
| 40 | + $result = yield $statement->execute([1337]); |
57 | 41 | while (yield $result->advance()) { |
58 | 42 | $row = $result->getCurrent(); |
59 | 43 | // $row is an array (map) of column values. e.g.: $row['column_name'] |
60 | 44 | } |
61 | 45 | }); |
62 | 46 | ``` |
| 47 | + |
| 48 | +## Versioning |
| 49 | + |
| 50 | +`amphp/postgres` follows the [semver](http://semver.org/) semantic versioning specification like all other `amphp` packages. |
| 51 | + |
| 52 | +## Security |
| 53 | + |
| 54 | +If you discover any security related issues, please email [`[email protected]`](mailto:[email protected]) instead of using the issue tracker. |
| 55 | + |
| 56 | +## License |
| 57 | + |
| 58 | +The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. |
0 commit comments