PHPackages                             sirprize/queried - 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. sirprize/queried

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

sirprize/queried
================

Database/ORM-agnostic query construction helper

2.0.0(3y ago)11.8kMITPHPPHP ^7.2 || ^8.0CI failing

Since Mar 1Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/sirprize/queried)[ Packagist](https://packagist.org/packages/sirprize/queried)[ Docs](https://github.com/sirprize/queried)[ RSS](/packages/sirprize-queried/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Queried
=======

[](#queried)

Database/ORM-agnostic query construction helper

Description
-----------

[](#description)

Parsing input, setting defaults and constructing `SELECT` queries can quickly become a mess. Queried helps organizing clauses for `WHERE`, `HAVING` and `ORDER BY`, making it easy to apply input as well as defaults when executing the query.

Usage
-----

[](#usage)

### Creating and activating simple WHERE conditions

[](#creating-and-activating-simple-where-conditions)

First we'll take a look at organizing conditions for the `WHERE` and `HAVING` parts of a query statement. The basic idea is to prepare clauses describing specific conditions, register them with a query object and then activate them individually based on application requirements and user input. Each clause is wrapped in a `BaseCondition` object. Those objects are then registered with a `BaseQueryConfigurator` object:

```
use Sirprize\Queried\BaseQueryConfigurator;
use Sirprize\Queried\Condition\BaseCondition;

$publishedCondition = new BaseCondition();
$publishedCondition->setClause("(release.date releaseAlias}.date releaseAlias}.published = 1)");
        $this->getConditionRegistry()->registerCondition('published', $pc);

        // define some sorting rules
        $this->getSorting()->getRules()->newRule('title')
            ->addAscColumn($this->releaseAlias.'.title', 'asc')
            ->addDescColumn($this->releaseAlias.'.title', 'desc')
            ->setDefaultDirection('asc')
        ;

        $this->getSorting()->getRules()->newRule('artist')
            ->addAscColumn($this->releaseAlias.'.artist', 'asc')
            ->addDescColumn($this->releaseAlias.'.artist', 'desc')
            ->setDefaultDirection('asc')
        ;
    }

    public function getCountQuery()
    {
        $this->reset();
        $this->applyFrom();
        $this->applyConditions();

        return $this->queryBuilder
            ->select("COUNT({$this->releaseAlias}.id)")
            ->getQuery()
        ;
    }

    public function getQuery()
    {
        $this->reset();
        $this->applyFrom();
        $this->applyConditions();
        $this->applySorting();

        return $this->queryBuilder
            ->select($this->releaseAlias)
            ->getQuery()
        ;
    }

    protected function applyFrom()
    {
        $this->queryBuilder
            ->from('My\Model\Entity\Product', $this->releaseAlias)
        ;
    }

    public function reset()
    {
        $this->queryBuilder
            ->resetDQLParts()
            ->setParameters(new ArrayCollection())
        ;
    }

    public function applySorting()
    {
        foreach ($this->getSorting()->getColumns() as $column => $order)
        {
            $this->queryBuilder->addOrderBy($column, $order);
        }
    }

    protected function applyConditions()
    {
        foreach ($this->getConditionRegistry()->getActiveConditions() as $condition)
        {
            $condition->build($this->getTokenizer());

            if (!$condition->getClause())
            {
                continue;
            }

            $this->queryBuilder->andWhere($condition->getClause());

            foreach ($condition->getParams() as $name => $value)
            {
                $this->queryBuilder->setParameter($name, $value, $condition->getType($name));
            }
        }
    }
}

```

### Running the query

[](#running-the-query)

```
use Sirprize\Queried\Sorting\Params as SortingParams;

// input
$sort = (array_key_exists('sort', $_GET)) ? $_GET['sort'] : null;
$order = (array_key_exists('order', $_GET)) ? $_GET['order'] : null;
$label = (array_key_exists('label', $_GET)) ? $_GET['label'] : null;
$artist = (array_key_exists('artist', $_GET)) ? $_GET['artist'] : null;

// sorting
$sortingParams = new SortingParams($sort, $order);
$sortingDefaults = new SortingParams('title', 'asc');

// the query
$queryConfigurator = new ReleaseQueryConfigurator($em);

$queryConfigurator->getConditionRegistry()
    ->activateCondition('published')
    ->activateCondition('artist', array('artist' => $artist))
;

$queryConfigurator->getSorting()->setParams($sortingParams);
$queryConfigurator->getSorting()->setDefaults($sortingDefaults);

$count = $queryConfigurator->getCountQuery()->getSingleResult();
$releases = $queryConfigurator->getQuery()->getResult();

```

License
-------

[](#license)

See LICENSE.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance58

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~1455 days

Total

3

Last Release

1182d ago

Major Versions

v0.1.0 → 1.0.02018-09-02

1.0.0 → 2.0.02023-02-18

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.2

2.0.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2aa6b6ece804d8a151ee35b0be09d68fda456edea22a53986bb49ece0a86782?d=identicon)[sirprize](/maintainers/sirprize)

---

Top Contributors

[![sirprize](https://avatars.githubusercontent.com/u/81617?v=4)](https://github.com/sirprize "sirprize (35 commits)")

---

Tags

dqlsqlquery

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sirprize-queried/health.svg)

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

###  Alternatives

[rennokki/laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.

1.1k4.0M14](/packages/rennokki-laravel-eloquent-query-cache)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[nilportugues/sql-query-builder

An elegant lightweight and efficient SQL QueryInterface BuilderInterface supporting bindings and complicated query generation.

425239.4k6](/packages/nilportugues-sql-query-builder)[supliu/laravel-query-monitor

Laravel Query Monitor

287111.9k](/packages/supliu-laravel-query-monitor)[illuminated/db-profiler

Database Profiler for Laravel Web and Console Applications.

168237.4k](/packages/illuminated-db-profiler)[nilportugues/sql-query-formatter

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

401.1M24](/packages/nilportugues-sql-query-formatter)

PHPackages © 2026

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