PHPackages                             finesse/query-scribe - 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. finesse/query-scribe

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

finesse/query-scribe
====================

Light SQL query builder designed for extensibility and flexibility

v0.9.3(7y ago)11.8k11MITPHPPHP &gt;=7.0CI failing

Since Oct 31Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Finesse/QueryScribe)[ Packagist](https://packagist.org/packages/finesse/query-scribe)[ Docs](https://github.com/Finesse/QueryScribe)[ RSS](/packages/finesse-query-scribe/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (1)Versions (16)Used By (1)

Query Scribe
============

[](#query-scribe)

[![Latest Stable Version](https://camo.githubusercontent.com/29132a5ae913f41d70a3dcfa176b919a27765c637a58c5b8489e5d15cd7d60cf/68747470733a2f2f706f7365722e707567782e6f72672f66696e657373652f71756572792d7363726962652f762f737461626c65)](https://packagist.org/packages/finesse/query-scribe)[![Total Downloads](https://camo.githubusercontent.com/f1b67e7aed5f9119a9279bce78c29bb9ddb04f1856177afd31100b03f467101f/68747470733a2f2f706f7365722e707567782e6f72672f66696e657373652f71756572792d7363726962652f646f776e6c6f616473)](https://packagist.org/packages/finesse/query-scribe)[![PHP from Packagist](https://camo.githubusercontent.com/dc4f6eb452abdf89eeb81d53df9fc08bfe5061648a9bf8780f5f724fca2266da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f66696e657373652f71756572792d7363726962652e737667)](https://camo.githubusercontent.com/dc4f6eb452abdf89eeb81d53df9fc08bfe5061648a9bf8780f5f724fca2266da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f66696e657373652f71756572792d7363726962652e737667)[![Test Status](https://github.com/finesse/QueryScribe/workflows/Test/badge.svg)](https://github.com/Finesse/QueryScribe/actions?workflow=Test)[![Maintainability](https://camo.githubusercontent.com/251b02898863eb34ad18bf9ff66ddca8893b26d250255282d025729887831ede/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35323564623133643339643762336365633336372f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Finesse/QueryScribe/maintainability)[![Test Coverage](https://camo.githubusercontent.com/06c6f7e3cc44c1bf49d08041525da99c362b6972a2fe8c0f4c4ee065ff54bd81/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f35323564623133643339643762336365633336372f746573745f636f766572616765)](https://codeclimate.com/github/Finesse/QueryScribe/test_coverage)

Provides a convenient object syntax to build SQL queries. Compiles the queries to an SQL text with values for binding. Doesn't perform queries to database.

```
$query = (new Query)
    ->from('posts')
    ->where('level', '>', 3)
    ->whereIn('category_id', function ($query) {
        $query
            ->addSelect('id')
            ->from('categories')
            ->where('categories.name', 'Interesting');
    })
    ->where(new Raw('MONTH(date)'), 4)
    ->orderBy('date', 'desc')
    ->limit(10);

$prefixer = new TablePrefixer('demo_');
$grammar = new MySQLGrammar();
$compiled = $grammar->compile($query->apply($prefixer));

echo $compiled->getSQL();
/*
    SELECT *
    FROM `demo_posts`
    WHERE
        `level` > ? AND
        `category_id` IN (
            SELECT `id`
            FROM `demo_categories`
            WHERE `demo_categories`.`name` = ?
        ) AND
        (MONTH(date)) = ?
    ORDER BY `date` DESC
    LIMIT ?
 */

echo $compiled->getBindings();
/*
    [3, 'Interesting', 4, 10]
 */
```

To perform compiled queries to a database, use a database connector like [PDO](http://php.net/manual/en/book.pdo.php), [MicroDB](https://github.com/Finesse/MicroDB) or [DBAL](http://www.doctrine-project.org/projects/dbal.html) or use a ready database abstraction like [MiniDB](https://github.com/Finesse/MiniDB) or [Wired](https://github.com/Finesse/Wired).

Key features:

- The builder has a single responsibility: build SQL.
- Designed for further extension. You may build a database tool or an ORM on top of it without major problems. Examples will come soon.
- Very flexible. You can pass a [raw SQL or a subquery](#raw-sql-and-subqueries) almost everywhere (see the PHPDoc comments in the code to know where you can pass them).
- Smart table prefixes which consider table aliases (don't work in raw expressions).
- All the values go to bindings, even from subqueries.
- No dependencies. Requires only PHP ≥ 7.

Supported SQL dialects:

- MySQL
- SQLite
- SQL Server (not fully supported)
- Maybe any other, didn't test it

If you need a dialect support please extend the `CommonGrammar` class and make a pull request.

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

[](#documentation)

The documentation is available at [queryscribe.readthedocs.io](http://queryscribe.readthedocs.io).

Also all the classes, methods and properties has a PHPDoc comment in the code.

Versions compatibility
----------------------

[](#versions-compatibility)

The project follows the [Semantic Versioning](http://semver.org).

License
-------

[](#license)

MIT. See [the LICENSE](LICENSE) file for details.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~34 days

Recently: every ~78 days

Total

14

Last Release

2765d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9006227?v=4)[Sergey M.](/maintainers/Finesse)[@Finesse](https://github.com/Finesse)

---

Top Contributors

[![Finesse](https://avatars.githubusercontent.com/u/9006227?v=4)](https://github.com/Finesse "Finesse (110 commits)")

---

Tags

databaselibrarymysqlquery-buildersqlsqlitedatabasemysqlsqlitesqlquery builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/finesse-query-scribe/health.svg)

```
[![Health](https://phpackages.com/badges/finesse-query-scribe/health.svg)](https://phpackages.com/packages/finesse-query-scribe)
```

###  Alternatives

[usmanhalalit/pixie

A lightweight, expressive, framework agnostic query builder for PHP.

6762.3M16](/packages/usmanhalalit-pixie)[cycle/database

DBAL, schema introspection, migration and pagination

71811.3k67](/packages/cycle-database)[opis/database

A database abstraction layer over PDO, that provides a powerful and intuitive query builder, bundled with an easy to use schema builder

10285.8k3](/packages/opis-database)[pecee/pixie

Lightweight, fast query-builder for PHP based on Laravel Eloquent but with less overhead.

4230.6k9](/packages/pecee-pixie)

PHPackages © 2026

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