PHPackages                             arekx/pql - 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. [Database &amp; ORM](/categories/database)
4. /
5. arekx/pql

ActiveLibrary[Database &amp; ORM](/categories/database)

arekx/pql
=========

A simple and highly extensible query Builder for easily building queries of any kind.

1.2.0(1w ago)23Apache-2.0PHPPHP &gt;=8.2CI passing

Since Sep 1Pushed 1w ago1 watchersCompare

[ Source](https://github.com/ArekX/PQL)[ Packagist](https://packagist.org/packages/arekx/pql)[ RSS](/packages/arekx-pql/feed)WikiDiscussions master Synced yesterday

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

PQL
===

[](#pql)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/99be7ac7618842a62b95d7de6f22bb4ce5fde9034a7367b5c64e943ed01729c1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4172656b582f50514c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ArekX/PQL/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/aafc825e861afa9070ee7aa23f230b62d40d759a25373ea2d301eb00889cbbb2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4172656b582f50514c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ArekX/PQL/?branch=master)[![Build Status](https://camo.githubusercontent.com/cad64919e6db3598dfe9ff7fce5ed930c2d9612b1338b4b393e8ffaeb19aee35/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4172656b582f50514c2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ArekX/PQL/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/5d387ad89d3d53028466d7c5f9aadf6f09ea8d05d33292571a9e2885c509fb0e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4172656b582f50514c2f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![Documentation Status](https://camo.githubusercontent.com/b6842903717e4d9fcb21d2cc2a966f8c587d3837c1fa82de4d2adb505f64979c/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f70716c2f62616467652f3f76657273696f6e3d6c6174657374)](https://pql.readthedocs.io/en/latest/?badge=latest)

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, Microsoft 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
------------

[](#installation)

Installing this library is done via composer `composer install arekxv/pql`

Usage
-----

[](#usage)

Create a runner with `PdoDatabase::resolve()`. It picks the driver and query builder automatically from the DSN scheme (`mysql:`, `pgsql:`, `sqlite:`, `sqlsrv:`):

```
use ArekX\PQL\Drivers\Pdo\PdoDatabase;

$runner = PdoDatabase::resolve([
    'dsn' => 'mysql:host=127.0.0.1;dbname=your_database',
    'username' => 'username',
    'password' => 'password',
]);
```

See the driver pages for the supported DSNs and driver specific options: [MySQL](docs/drivers/mysql.md) · [PostgreSQL](docs/drivers/pgsql.md) · [SQLite](docs/drivers/sqlite.md) · [Microsoft SQL Server](docs/drivers/sqlsrv.md). You can also wire the driver and builder up by hand if you prefer (each driver page shows how).

Then write and run queries:

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

// Simple select
$query = select('*')
    ->from('user')
    ->where(all(['is_active' => 1]));

// SELECT * FROM `user` WHERE `is_active` = 1
$runner->fetchAll($query);

// Complex select with a sub-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)))
    ]]);
/*
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);
```

Documentation
-------------

[](#documentation)

Documentation is available in [here](docs/index.md) (in docs folder).

HTML version of the docs is available at:

Testing
-------

[](#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](https://scrutinizer-ci.com/g/ArekX/PQL/?branch=master).

License
-------

[](#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

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.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance98

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.2% 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

Every ~329 days

Total

3

Last Release

11d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c16806a6fc4805b54005c72ea7aa0b6bc33f889a4a657a3071953f6b4e4a23c?d=identicon)[ArekXV](/maintainers/ArekXV)

---

Top Contributors

[![ArekX](https://avatars.githubusercontent.com/u/4344776?v=4)](https://github.com/ArekX "ArekX (118 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

agnosticdatabasedrivermysqlphppostgressqlsqlitesqlserver

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/arekx-pql/health.svg)

```
[![Health](https://phpackages.com/badges/arekx-pql/health.svg)](https://phpackages.com/packages/arekx-pql)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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