arekx/pql 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

arekx/pql

最新稳定版本:1.0.0

Composer 安装命令:

composer require arekx/pql

包简介

PHP Query Builder

README 文档

README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status Documentation Status

PHP Database Query Library

This library is a database abstraction layer which abstracts the query commands (Select, Delete, Update, etc.) out from the drivers (MySQL, Postgres, SQL Server, etc.). Queries are defined in an eloquent way allowing you to write almost all kinds of queries without having to rely on passing raw query data.

Installation

Installing this library is done via composer composer install arekxv/pql (still WIP)

Usage

First you need to decide on which driver you will use. Following drivers are supported:

After you decide on the driver, writing a query is as simple as:

use function \ArekX\PQL\Sql\{select, all, equal, column, value};

// ... driver and builder initialization left out for brevity.

/** @var \ArekX\PQL\Contracts\Driver $driver */
/** @var \ArekX\PQL\Contracts\QueryBuilder $builder */

$runner = QueryRunner::create($driver, $builder);

// Fetching all results

$query = select('*') // or Select::create()->columns('*') if you do not want to use functions.
    ->from('user')
    ->where(all(['is_active' => 1]));

// Built query equals to: SELECT * FROM `user` WHERE `is_active` = 1;
$runner->fetchAll($query); // Returns all data for user table


// Complex select query:
$query = select('*')
    ->from(['u' => 'user'])
    ->innerJoin(['r' => 'user_role'], 'u.role_id = r.id')
    ->where(['all', [
         'u.is_active' => 1,
         'r.id' => select('role_id')
                    ->from('application_roles')
                    ->where(equal(column('application_id'), value(2)))
      ]);
/* 
Built query equals to:
SELECT 
    * 
FROM `user` AS `u`
INNER JOIN `user_role` AS `r` ON u.role_id = r.id
WHERE
 `u`.`is_active` = 1
 AND `r`.`id` IN (
    SELECT `role_id` FROM `application_roles` WHERE `application_id` = 2
 )
*/
$runner->fetchAll($query); // Returns all data for this query

Documentation

Documentation is available in here (in docs folder).

HTML version of the docs is available at: https://pql.readthedocs.io/

Testing

Run composer install and then run composer test. This will run unit and integration tests.

For integration tests, database docker containers must be running otherwise those tests will fail.

To setup docker containers install docker and inside tests folder run docker-compose up -d.

To just run unit tests run composer test-unit.

For coverage report run composer coverage or you can take a look at it here.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an " AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-01