PHPackages                             campoint/postgrest-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. campoint/postgrest-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

campoint/postgrest-php
======================

PostgREST client for PHP. This library provides a synchronous and asynchronous interface to PostgREST.

0.0.1(2y ago)32921[2 PRs](https://github.com/Campoint/postgrest-php/pulls)BSD-3-ClausePHPPHP ^8.1

Since Jul 24Pushed 2y ago3 watchersCompare

[ Source](https://github.com/Campoint/postgrest-php)[ Packagist](https://packagist.org/packages/campoint/postgrest-php)[ RSS](/packages/campoint-postgrest-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

postgrest-php
=============

[](#postgrest-php)

[![License](https://camo.githubusercontent.com/c8d0282984b0d0b2fa7d65dc68ee6692c3dbcab4c6de5be4ef7f321f82d0e9ea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f43616d706f696e742f706f737467726573742d706870)](https://opensource.org/license/bsd-3-clause/)[![PHP version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://www.php.net/)[![Code coverage](https://camo.githubusercontent.com/3b0723db4dfe8d5cfe5abbf7ee65bdd4ec86194cf3065a33ac152b19b7b15403/68747470733a2f2f636f6465636f762e696f2f67682f43616d706f696e742f706f737467726573742d7068702f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d3747504f4e4c35374e51)](https://codecov.io/gh/Campoint/postgrest-php)[![Release](https://camo.githubusercontent.com/c5c2494d74407fbaa1a7a45923b6d623c54b4561b05672135757e6a38fa48e92/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f43616d706f696e742f706f737467726573742d7068703f696e636c7564655f70726572656c6561736573)](https://github.com/Campoint/postgrest-php/releases)[![Commit activity](https://camo.githubusercontent.com/5b8792ddef7061530fcd8a3f6707b500357163162378cd7c50d7fa4cba451510/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d69742d61637469766974792f6d2f43616d706f696e742f706f737467726573742d706870)](https://github.com/Campoint/postgrest-php/commits/master)[![Documentation](https://camo.githubusercontent.com/8b72c0656cf68ff86b1e6869884d50cc872a6081cfe63f6d2cc0f68609167ad1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d6c61746573742d384132424532)](https://campoint.github.io/postgrest-php/latest)PostgREST client for PHP. This library provides a synchronous and asynchronous interface to PostgREST.

Table of Contents

- [Installation](#installation)
    - [Requirements](#requirements)
    - [Instructions](#instructions)
- [Basic usage](#basic-usage)
    - [Create a client](#create-a-client)
        - [Sync](#sync)
        - [Async](#async)
    - [Select](#select)
    - [Insert](#insert)
    - [Upsert](#upsert)
    - [Update](#update)
    - [Delete](#delete)
    - [Call stored procedure](#call-stored-procedure)
- [Advanced usage](#advanced-usage)
- [Creating an issue](#creating-an-issue)
- [Local development &amp; testing](#local-development-testing)
    - [Local development](#local-development)
    - [Testing](#testing)

[Installation](#id1)
--------------------

[](#installation)

### [Requirements](#id2)

[](#requirements)

- PHP &gt;= 8.1
- react/http &gt;= 1.5
- react/async &gt;= 4.0
- PostgreSQL &gt;= 12
- PostgREST &gt;= 9

### [Instructions](#id3)

[](#instructions)

```
composer require campoint/postgrest-php
```

[Basic usage](#id4)
-------------------

[](#basic-usage)

### [Create a client](#id5)

[](#create-a-client)

This library provides both an async and sync client. Under the hood we use ReactPHP to dispatch requests and the only difference between the sync and async client is, that the sync client calls `await()` on the `Promise` for you. You can optionally pass a configured `Browser`object to the client, but the `baseUrl` and `timeout` parameters will be overwritten.

#### [Sync](#id6)

[](#sync)

Create a client for synchronous environments:

```
$clientAuthConfig = new ClientAuthConfig(
    authArguments: [
        'email' => 'test@acme.dev',
        'pass' => 'password',
    ],
);
$client = new PostgrestSyncClient(
    'http://localhost:8080',
    5,
    clientAuthConfig: $clientAuthConfig
);
try {
    $client->auth();
} catch (FailedAuthException $e) {
   // do something
}
```

#### [Async](#id7)

[](#async)

Create a client for asynchronous environments:

```
$clientAuthConfig = new ClientAuthConfig(
    authArguments: [
        'email' => 'test@acme.dev',
        'pass' => 'password',
    ],
);
$client = new PostgrestAsyncClient(
    'http://localhost:8080',
    5,
    (new Browser(null, $loop)),
    $clientAuthConfig
);
$client->auth()->then(
    function () {
        // do something on success
    },
    function (FailedAuthException $e) {
        // do something on rejection
    }
);
```

### [Select](#id8)

[](#select)

Select data from any table, in any schema and apply arbitrary filters:

```
$response = $client->run(
    $client->from('schema_name', 'table_name')
        ->select('column_a', 'column_b')
        ->eq('column_c', 'foo')
        ->gt('column_d', 0.5)
        ->in('column_e', 1, 2, 3)
);
```

### [Insert](#id9)

[](#insert)

Insert data into any table, in any schema:

```
$response = $client->run(
    $client->from('schema_name', 'table_name')
        ->insert(
            [
                [
                    'column_a' => 'foo'
                ],
                [
                    'column_a' => 'bar'
                ]
            ]
        )
);
```

### [Upsert](#id10)

[](#upsert)

Upsert data into any table, in any schema:

```
$response = $client->run(
    $client->from('schema_name', 'table_name')
        ->upsert(
            [
                [
                    'column_a' => 'foo'
                ],
                [
                    'column_a' => 'bar'
                ]
            ],
            duplicateResolution: DuplicateResolution::MERGE
        )
);
```

### [Update](#id11)

[](#update)

Update any row in any table, in any schema with arbitrary filters:

```
$response = $client->run(
    $client->from('schema_name', 'table_name')
        ->update(['column_a' => 'foo'])
        ->eq('column_a', 'bar')
);
```

### [Delete](#id12)

[](#delete)

Delete any row in any table, in any schema with arbitrary filters:

```
$response = $client->run(
    $client->from('schema_name', 'table_name')
        ->delete()
        ->eq('column_a', 'bar')
);
```

### [Call stored procedure](#id13)

[](#call-stored-procedure)

Call any stored procedure with arbitrary arguments:

```
$response = $client->call(
    'foobar',
    [
        'arg1' => 'foo',
        'arg2' => 'bar'
    ],
    'schema_name'
);
```

[Advanced usage](#id14)
-----------------------

[](#advanced-usage)

If you need further documentation on how to use this library, refer to the documentation located [here](https://campoint.github.io/postgrest-php/latest).

[Creating an issue](#id15)
--------------------------

[](#creating-an-issue)

When encountering a bug with this library, feel free to open a new issue. To improve the understanding of your problem, you should fork this repository and append a new failing test case which represents the bug. If needed, create new testing databases in the `testing_db/initdb` path. Reference your new test in the issue. Issues which report bugs but have no test cases attached to it, will be probably ignored. Please also supply the used PostgREST and PostgreSQL versions to bug reports, to ease the task of reproducing your issue. Create feature request issues only if you have the intent to implement them yourself.

[Local development &amp; testing](#id16)
----------------------------------------

[](#local-development--testing)

When developing or testing the client, you can use the pre-configured `docker-compose` environment to run both PostgreSQL and PostgREST. The `docker-compose.yml` file contains the services to start PostgreSQL versions 12 to 15 and PostgREST at version 9 to 11. To start the local environment, simply run:

```
docker-compose up postgresql14 postgrest11
```

Once the environment started, you can access PostgREST at port `8080`and PostgreSQL at port `5432`.

### [Local development](#id17)

[](#local-development)

The repository provides a devcontainer which you can use for developing the client. Development happens only over PR's because we want to keep master stable and always usable for new, unreleased features. When opening a PR against master all necessary checks and tests are executed, to ensure nothing breaks. To ensure your PR does not fail due to linter or static analyzer checks, run the following commands before opening the PR:

```
composer ci-ready
```

### [Testing](#id18)

[](#testing)

This client is integration tested using `docker-compose` to run the needed dependencies. To run the tests locally, run these steps:

```
docker-compose up -d postgresql14 postgrest11
composer test
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1029d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ea65bd689aa8788e785d8888f2d7234dc36794eb1200e79cc3132686517ace7?d=identicon)[campoint](/maintainers/campoint)

---

Top Contributors

[![CptKirk](https://avatars.githubusercontent.com/u/11601419?v=4)](https://github.com/CptKirk "CptKirk (1 commits)")

---

Tags

asynchttpphppostgresqlpostgrestreactphpresthttpasyncrestdatabasepostgresqlreactphppostgrest

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/campoint-postgrest-php/health.svg)

```
[![Health](https://phpackages.com/badges/campoint-postgrest-php/health.svg)](https://phpackages.com/packages/campoint-postgrest-php)
```

###  Alternatives

[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)[amphp/http-client

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.

7286.8M137](/packages/amphp-http-client)[clue/framework-x

Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

936736.7k8](/packages/clue-framework-x)[clue/http-proxy-react

Async HTTP proxy connector, tunnel any TCP/IP-based protocol through an HTTP CONNECT proxy server, built on top of ReactPHP

472.3M33](/packages/clue-http-proxy-react)[for/http-middleware-psr15-adapter

PSR15 adapter for react/http middleware

2512.3k3](/packages/for-http-middleware-psr15-adapter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
