swouters/postgresql-tools
Composer 安装命令:
composer require swouters/postgresql-tools
包简介
PHP package containing a set of tools to build SQL queries
README 文档
README
A PHP library to help you to build complexes SQL queries for PostgreSQL.
Usage
Requirements
- PHP 8.4 or higher
- PostgreSQL database, any abstract layer (like Doctrine DBAL) or raw SQL queries.
Installation
composer require swouters/postgresql-tools
Condition Builder
A tool to build easily complex conditions for SQL queries.
Signature
// Array example $array = [ 'age' => 30, 'name' => ['John', 'Doe'], ]; // Signature public function build( array $array, // The array of conditions string $firstLevelOperator = 'AND', // The operator used between 1st level values (age=30 and ...) string $secondLevelOperator = 'OR', // The operator used if a value is an array (name=John OR name=Doe) array $comparisonOperators = [], // Default is '='. You can set a specific operator for a key array $replaces = [] // Replace the key used for the SQL column ): array
Build condition exemple
use SWouters\PostgresqlTools\ConditionBuilder; // name = "John Doe" PostgreSQLConditionBuilder::buildCondition([ 'name' => 'John Doe', ]); // Firstname=John AND Lastname=Doe PostgreSQLConditionBuilder::buildCondition([ 'firstname' => 'John', 'lastname' => 'Doe', ]); // Firstname=John OR Lastname=Doe PostgreSQLConditionBuilder::buildCondition([ 'firstname' => 'John', 'lastname' => 'Doe', ], 'OR'); // Name=John OR Name=Doe PostgreSQLConditionBuilder::buildCondition([ 'name' => ['John', 'Doe'], ]); // (Name=John OR Name=Doe) AND Age=30 PostgreSQLConditionBuilder::buildCondition([ 'name' => ['John', 'Doe'], 'age' => 30, ]); // status != 'deleted' PostgreSQLConditionBuilder::buildCondition([ 'status' => 'deleted', ], 'AND', 'OR', [ 'status' => '!=' ]); // age=30 AND (name!=John AND name!=Doe) PostgreSQLConditionBuilder::buildCondition([ 'age' => 30, 'name' => ['John', 'Doe'], ], 'AND', 'AND', [ 'name' => '!=' ]); // user.name=John PostgreSQLConditionBuilder::buildCondition([ 'name' => 'John', ], 'AND', 'OR', [], [ 'name' => 'user.name' ]); // created_at > '2024-03-01' AND created_at < '2024-03-02' PostgreSQLConditionBuilder::buildCondition([ 'date_min' => '2024-03-01', 'date_max' => '2024-03-02', ], 'AND', 'OR', [ 'date_min' => '>', 'date_max' => '<', ], [ 'date_min' => 'created_at', 'date_max' => 'created_at', ]); // id_country = ANY (countries_array) PostgreSQLConditionBuilder::buildCondition([ 'id_country' => 'FR', ], 'AND', 'OR', [ 'id_country' => 'ANY' ]);
Execute query (example with Doctrine DBAL)
[$cond, $params] = PostgreSQLConditionBuilder::buildCondition([ 'name' => 'John Doe', ]); $connexion->executeQuery("select * from users WHERE $cond", $params);
Development
Install :
composer install
Run tests
./vendor/bin/phpunit
Check lint
composer check
swouters/postgresql-tools 适用场景与选型建议
swouters/postgresql-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 719 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 swouters/postgresql-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 swouters/postgresql-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 719
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-11