campoint/postgrest-php
Composer 安装命令:
composer require campoint/postgrest-php
包简介
PostgREST client for PHP. This library provides a synchronous and asynchronous interface to PostgREST.
README 文档
README
PostgREST client for PHP. This library provides a synchronous and asynchronous interface to PostgREST.
Table of Contents
Installation
Requirements
- PHP >= 8.1
- react/http >= 1.5
- react/async >= 4.0
- PostgreSQL >= 12
- PostgREST >= 9
Instructions
composer require campoint/postgrest-php
Basic usage
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
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
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
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
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
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
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
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
Call any stored procedure with arbitrary arguments:
$response = $client->call( 'foobar', [ 'arg1' => 'foo', 'arg2' => 'bar' ], 'schema_name' );
Advanced usage
If you need further documentation on how to use this library, refer to the documentation located here.
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 & 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
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
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
campoint/postgrest-php 适用场景与选型建议
campoint/postgrest-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 292 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 07 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「http」 「rest」 「postgresql」 「async」 「reactphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 campoint/postgrest-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 campoint/postgrest-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 campoint/postgrest-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
repository php library
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
统计信息
- 总下载量: 292
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-07-26