mirror of
https://github.com/danog/postgres.git
synced 2024-11-30 04:29:12 +01:00
Update readme
This commit is contained in:
parent
02265884d3
commit
2d9e97aabc
74
README.md
74
README.md
@ -1,62 +1,58 @@
|
|||||||
# PostgreSQL Client for Amp
|
<p align="center">
|
||||||
|
<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>
|
||||||
|
</p>
|
||||||
|
|
||||||
This library is a component for [Amp](https://github.com/amphp/amp) that provides an asynchronous client for PostgreSQL.
|
<p align="center">
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
</p>
|
||||||
|
|
||||||
[![Build Status](https://img.shields.io/travis/amphp/postgres/master.svg?style=flat-square)](https://travis-ci.org/amphp/postgres)
|
<p align="center"><strong>Async PostgreSQL client built with <a href="https://amphp.org/">Amp</a>.</strong></p>
|
||||||
[![Coverage Status](https://img.shields.io/coveralls/amphp/postgres/master.svg?style=flat-square)](https://coveralls.io/r/amphp/postgres)
|
|
||||||
[![Semantic Version](https://img.shields.io/github/release/amphp/postgres.svg?style=flat-square)](http://semver.org)
|
|
||||||
[![MIT License](https://img.shields.io/packagist/l/amphp/postgres.svg?style=flat-square)](LICENSE)
|
|
||||||
[![@amphp on Twitter](https://img.shields.io/badge/twitter-%40asyncphp-5189c7.svg?style=flat-square)](https://twitter.com/asyncphp)
|
|
||||||
|
|
||||||
##### Requirements
|
## Installation
|
||||||
|
|
||||||
- PHP 7+
|
This package can be installed as a [Composer](https://getcomposer.org/) dependency.
|
||||||
- [ext-pgsql](https://secure.php.net/pgsql) or [pecl-pq](https://pecl.php.net/package/pq)
|
|
||||||
|
|
||||||
##### Installation
|
|
||||||
|
|
||||||
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.)
|
|
||||||
|
|
||||||
Run the following command to use this library in your project:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require amphp/postgres
|
composer require amphp/postgres
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also manually edit `composer.json` to add this library as a project requirement.
|
## Requirements
|
||||||
|
|
||||||
```json
|
- PHP 7.0+
|
||||||
// composer.json
|
- [ext-pgsql](https://secure.php.net/pgsql) or [pecl-pq](https://pecl.php.net/package/pq)
|
||||||
{
|
|
||||||
"require": {
|
|
||||||
"amphp/postgres": "^0.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Example
|
## Documentation & Examples
|
||||||
|
|
||||||
|
More examples can be found in the [`examples`](examples) directory.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
|
||||||
|
|
||||||
use Amp\Postgres;
|
|
||||||
|
|
||||||
Amp\Loop::run(function () {
|
Amp\Loop::run(function () {
|
||||||
/** @var \Amp\Postgres\Connection $connection */
|
/** @var \Amp\Postgres\Pool $pool */
|
||||||
$connection = yield Postgres\connect('host=localhost user=postgres dbname=test');
|
$pool = Amp\Postgres\pool("host=localhost user=postgres dbname=test");
|
||||||
|
|
||||||
/** @var \Amp\Postgres\Statement $statement */
|
/** @var \Amp\Postgres\Statement $statement */
|
||||||
$statement = yield $connection->prepare('SELECT * FROM test WHERE id=$1');
|
$statement = yield $pool->prepare("SELECT * FROM test WHERE id=$1");
|
||||||
|
|
||||||
/** @var \Amp\Postgres\TupleResult $result */
|
|
||||||
$result = yield $statement->execute(1337);
|
|
||||||
|
|
||||||
|
/** @var \Amp\Postgres\ResultSet $result */
|
||||||
|
$result = yield $statement->execute([1337]);
|
||||||
while (yield $result->advance()) {
|
while (yield $result->advance()) {
|
||||||
$row = $result->getCurrent();
|
$row = $result->getCurrent();
|
||||||
// $row is an array (map) of column values. e.g.: $row['column_name']
|
// $row is an array (map) of column values. e.g.: $row['column_name']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
`amphp/postgres` follows the [semver](http://semver.org/) semantic versioning specification like all other `amphp` packages.
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
If you discover any security related issues, please email [`contact@amphp.org`](mailto:contact@amphp.org) instead of using the issue tracker.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.
|
||||||
|
Loading…
Reference in New Issue
Block a user