定制 koochik/queryhall 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

koochik/queryhall

Composer 安装命令:

composer require koochik/queryhall

包简介

A PHP package that allows you to sort, filter, and paginate Doctrine DBAL SQL database queries from Query parameters

README 文档

README

QueryHall is a PHP library that allows you to sort, filter, and paginate query builder instances of a database abstraction layer of your choice, such as Doctrine DBAL or Eloquent. It ships with a ready-to-use concrete class for DBAL that allows filtering, sorting, and paginating Doctrine DBAL queries based on a PSR request object (using the query parameters).

Features

  • Abstract Query Builder: Easily integrate with various database abstraction layers.
  • Sorting: Sort your queries based on multiple criteria.
  • Filtering: Apply complex filters to your queries.
  • Pagination: Efficiently paginate your query results.
  • PSR-7 Compatibility: Works seamlessly with PSR-7 request objects.
  • Flexible Query Parsing Algorithm: Easily parse query parameters with a customizable parser that can be swapped.
  • Built-in BasicValidator: Validate filter rules with the built-in BasicValidator.
  • Highly Customizable: Customize almost every aspect of this library, including

Installation

Install the library via Composer:

composer require koochik/queryhall

Using the built-in Dbal implementaion

$app->get('/users', function (Request $request) {
    $queryString = $request->getUri()->getQuery();
    parse_str($queryString, $queryParams);

    $connectionParams = [
        'dbname' => 'DataBase',
        'user' => 'root',
        'password' => '',
        'host' => 'localhost',
        'driver' => 'pdo_mysql',
    ];

    $conn = DriverManager::getConnection($connectionParams);
    $queryBuilder = $conn->createQueryBuilder();
    $queryBuilder->select('*')->from('users');

    $queryHall = new SortAndPaginate($queryBuilder, $queryParams);
    $response = new Response();
    $data = $queryHall->getPaginatedResult();
    
    $response->getBody()->write(json_encode($data));
    return $response->withHeader('Content-Type', 'application/json');
});

Then the request users?where=[id,>,2]&sort=[name,-1]&perPage=5&p=2 would Get users with id > 2, Sort by name in descending order, paginate with 5 items per page, and return the result from page 2. the result is somthing like


{
    "data": [
        {
            "id": 4,
            "name": "Emily",
            "lastName": "Brown",
            "age": 35,
            "isActive": 1,
            "height": 170.8
        },
        {
            "id": 5,
            "name": "Daniel",
            "lastName": "Williams",
            "age": 22,
            "isActive": 0,
            "height": 176.5
        },
        {
            "id": 9,
            "name": "Benjamin",
            "lastName": "Martinez",
            "age": 31,
            "isActive": 1,
            "height": 180.6
        }
    ],
    "meta": {
        "current_page": 2,
        "per_page": 5,
        "last_page": 2,
        "total": 8,
        "from": 6,
        "to": 8
    }
}

koochik/queryhall 适用场景与选型建议

koochik/queryhall 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 247 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 koochik/queryhall 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 koochik/queryhall 我们能提供哪些服务?
定制开发 / 二次开发

基于 koochik/queryhall 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 247
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-13