PHPackages                             compolomus/light-sql-query-builder - 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. compolomus/light-sql-query-builder

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

compolomus/light-sql-query-builder
==================================

Light simple query builder

0.9.3(8y ago)4271MITPHPPHP ^7.0

Since Jun 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Compolomus/SQLQueryBuilder)[ Packagist](https://packagist.org/packages/compolomus/light-sql-query-builder)[ RSS](/packages/compolomus-light-sql-query-builder/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (7)Used By (0)

Koenig LSQLQueryBuilder
=======================

[](#koenig-lsqlquerybuilder)

[![License](https://camo.githubusercontent.com/64415a2b3914021c1a8b761dd4c3546e375a0de6159bd48cd7ef3504f5cad5ac/68747470733a2f2f706f7365722e707567782e6f72672f636f6d706f6c6f6d75732f6c696768742d73716c2d71756572792d6275696c6465722f6c6963656e7365)](https://packagist.org/packages/compolomus/light-sql-query-builder)

[![Build Status](https://camo.githubusercontent.com/b2ff84a1a37f7dabffaf6f3e40890c94f67c10142fc31a11c1cc3c8afe0ca6f0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f436f6d706f6c6f6d75732f53514c51756572794275696c6465722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/70a8771ed398258a773b01a26e6ac225aeea1f4f1f4420c09a4641ca52122a30/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f436f6d706f6c6f6d75732f53514c51756572794275696c6465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/e66a7d200a14c98697a780df60eea0b112456f2c58d216e218060735190ef988/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f436f6d706f6c6f6d75732f53514c51756572794275696c6465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Compolomus/SQLQueryBuilder/?branch=master)[![Code Climate](https://camo.githubusercontent.com/4fd5547f85fa83e9682dd58813ce084d0fa765355cdd0f7563423a310ec94451/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f436f6d706f6c6f6d75732f53514c51756572794275696c6465722f6261646765732f6770612e737667)](https://codeclimate.com/github/Compolomus/SQLQueryBuilder)[![SensioLabsInsight](https://camo.githubusercontent.com/63918585eec42ca6bf591ae595fc00fbd67cf650e86f28508c7a3f9b8b26f93a/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f37383363363830622d636635652d343965632d626332312d6334643530663235373937342f6d696e692e706e67)](https://insight.sensiolabs.com/projects/783c680b-cf5e-49ec-bc21-c4d50f257974)[![Downloads](https://camo.githubusercontent.com/f59d705a0ba53e55857a3719dddf72a10c594434b6d2670fda99832d7e97d866/68747470733a2f2f706f7365722e707567782e6f72672f636f6d706f6c6f6d75732f6c696768742d73716c2d71756572792d6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/compolomus/light-sql-query-builder)

Установка:
----------

[](#установка)

composer require compolomus/light-sql-query-builder

Применение:
-----------

[](#применение)

```
use Compolomus\LSQLQueryBuilder\Builder;

require __DIR__ . '/vendor/autoload.php';

$builder = new Builder('users');

echo '---SELECT---';

echo $builder->select(['id' => 'user_id', 'name', 'email'])
    ->where([['id', '=', 15], ['firm_id', 'not in', [1, 2, 3]]])
    ->where([['age', '>', 17], ['friends', '>=', 177]], 'or')
    ->group(['age', 'friends'])
    ->order(['salary', 'experience'], 'desc')
        ->asc(['age', 'size'])
    ->limit(5, 10, 'page');

/*
    SELECT `user_id` AS `id`,`name`,`email`
        FROM `users`
        WHERE (`id` = :59ee533076W AND `firm_id` NOT IN :59ee571790W)
            AND (`age` > :592cd57379W OR `friends` >= :592cd61484W)
        GROUP BY `age`,`friends`
        ORDER BY `age`,`size` ASC,
                    `salary`,`experience` DESC
        LIMIT 45 OFFSET 5
*/

/*
    Support 89 MYSQL Field function[one argument] (count, min, max... etc)
*/

echo '---COUNT#1---';

echo $builder->select()
    ->setFunction('*', 'count')
    ->where()
        ->add('age', '=', 32)
    ->group(['position'])
    ->order(['name'], 'desc')
    ->limit(10, 20);

/*
    SELECT COUNT(*)
        FROM `users`
        WHERE (`age` = :598bf03980W)
        GROUP BY `position`
        ORDER BY `name` DESC
        LIMIT 20 OFFSET 10
*/

echo '---COUNT#2---';

echo $builder->select(['count' => '*|count']);

/*
    SELECT COUNT(*) AS `count`
        FROM `users`
*/

echo '---DELETE BY ID---';

echo $builder->delete(5);

/*
    DELETE FROM `users`
        WHERE (`id` = :593b785726W)
*/

echo '---DELETE BY FIELD---';

echo $builder->delete(15, 'userid');

/*
    DELETE FROM `users`
        WHERE (`userid` = :593b756573W)
*/

echo '---DELETE WITH WHERE---';

echo $builder->delete()
    ->where()
        ->add('rank', 'between', [12, 15]);

/*
    DELETE FROM `users`
        WHERE (`rank` BETWEEN :5979f19816W)
*/

echo '---INSERT FIELDS AND VALUES---';

echo $builder->insert()
    ->fields(['name', 'email', 'age'])
    ->values(['Vasya', 'vasya@gmail.com', 22])
    ->values(['Petya', 'petya@gmail.com', 24]);

/*
    INSERT INTO `users`
        (`name`,`email`,`age`)
        VALUES
            (:59b8773308I,:59b8798017I,:59b8791062I),
            (:59b8754434I,:59b8727155I,:59b8728332I)
*/

echo '---INSERT ARRAY(FIELDS => VALUES)---';

echo $builder->insert([
    'name' => 'Oleg',
    'email' => 'oleg@gmail.com',
    'age' => 33
]);

/*
    INSERT INTO `users`
        (`name`,`email`,`age`)
        VALUES
            (:59b8702032I,:59b8702274I,:59b8735242I)
*/

echo '---INSERT PREPARE WITH FIELDS---';

echo $builder->insert()
    ->fields(['name', 'email', 'age']);

/*
    INSERT INTO `users`
        (`name`,`email`,`age`)
        VALUES (?,?,?)
*/

echo '---UPDATE#1---';

echo $builder->update([
    'user' => 11,
    'post' => 345,
    'text' => 'Text'
])
    ->where()
        ->add('test', 'regexp', '^.....$');

/*
    UPDATE `users`
        SET
            `user` = :5923849640U,
            `post` = :5923828461U,
            `text` = :5923846245U
        WHERE (`test` REGEXP :5923827411W)
*/

echo '---UPDATE#2---';

echo $builder->update()
    ->fields(['name', 'subname'])
    ->values(['test', 'testus'])
    ->where([], 'or')
        ->add('growth', '', 140)
    ->order(['name'], 'desc')
    ->limit(10, 20, 'offset');

/*
    UPDATE `users`
        SET
            `name` = :5923864911U,
            `subname` = :5923845311U
        WHERE (`growth` < :5923863542W OR `growth` > :5923879798W)
        ORDER BY `name` DESC
        LIMIT 10 OFFSET 20
*/

echo '---UPDATE#3---';

echo $builder->update()
    ->fields(['name', 'email', 'age']);

/*
    UPDATE `users` SET `name` = ?,`email` = ?,`age` = ?
*/

echo '---JOIN#1---';

echo $builder->select()
    ->join('test', 't', [['id', 'tid'], ['did', 'mid']], 'cross');

/*
    SELECT * FROM `users`
        CROSS JOIN `test` AS `t`
            ON
                `users`.`id` = `test`.`tid`
            AND `users`.`did` = `test`.`mid`
*/

echo '---JOIN#2---';

echo $builder->select()
    ->join('test2')
    ->addOn([['fid', 'gid']])
    ->setType('right');

/*
    SELECT * FROM `users`
        RIGHT JOIN `test2`
        ON `users`.`fid` = `test2`.`gid`
*/

echo '---JOIN#3---';

echo $builder->select()
    ->join('test3')
    ->using('qwerty');

/*
    SELECT * FROM `users` LEFT JOIN `test3` USING(`qwerty`)
*/

echo '---JOIN#4---';

echo $builder->select()
    ->join('test4')
        ->addOn([['rid', 'vid']])
        ->setAlias('t4')
        ->setType('cross')
    ->join('test5', 't5', [['aid', 'mid'], ['bid', 'cid']], 'inner');

/*
    SELECT * FROM `users`
        CROSS JOIN `test4` AS `t4`
        INNER JOIN `test5` AS `t5`
            ON `users`.`rid` = `test4`.`vid`
            AND `users`.`aid` = `test5`.`mid`
            AND `users`.`bid` = `test5`.`cid`
*/

echo '---JOIN#5---';
echo $builder->select()
    ->join('testus', 'ts')
        ->setType('right')
    ->join('testus2', 'ts2')
        ->using('user');

/*
    SELECT * FROM `users`
        RIGHT JOIN `testus` AS `ts`
        LEFT JOIN `testus2` AS `ts2`
    USING(`user`)
*/

echo '---PLACEHOLDERS---';

echo '' . print_r($builder->placeholders(), true) . '';

/*
Array
(
    [:59ee533076W] => 15
    [:59ee571790W] => (1,2,3)
    [:592cd57379W] => 17
    [:592cd61484W] => 177
    [:598bf03980W] => 32
    [:593b785726W] => 5
    [:593b756573W] => 15
    [:5979f19816W] => 12 AND 15
    [:59b8773308I] => Vasya
    [:59b8798017I] => vasya@gmail.com
    [:59b8791062I] => 22
    [:59b8754434I] => Petya
    [:59b8727155I] => petya@gmail.com
    [:59b8728332I] => 24
    [:59b8702032I] => Oleg
    [:59b8702274I] => oleg@gmail.com
    [:59b8735242I] => 33
    [:5923849640U] => 11
    [:5923828461U] => 345
    [:5923846245U] => Text
    [:5923827411W] => ^.....$
    [:5923864911U] => test
    [:5923845311U] => testus
    [:5923863542W] => 180
    [:5923879798W] => 140
)
*/
```

###  Health Score

25

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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

Total

5

Last Release

2977d ago

### Community

Maintainers

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

---

Top Contributors

[![Compolomus](https://avatars.githubusercontent.com/u/10777258?v=4)](https://github.com/Compolomus "Compolomus (67 commits)")

---

Tags

buildermysqlpdo-mysqlphp7querybuildersqlsqlbuildermysqlsqlpdoquery builderSQL Builder

### Embed Badge

![Health badge](/badges/compolomus-light-sql-query-builder/health.svg)

```
[![Health](https://phpackages.com/badges/compolomus-light-sql-query-builder/health.svg)](https://phpackages.com/packages/compolomus-light-sql-query-builder)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k570.0M4.9k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.4M58](/packages/ifsnop-mysqldump-php)[cycle/orm

PHP DataMapper ORM and Data Modelling Engine

1.3k811.9k58](/packages/cycle-orm)[usmanhalalit/pixie

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

6772.2M15](/packages/usmanhalalit-pixie)[aura/sqlquery

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

4572.9M31](/packages/aura-sqlquery)[cycle/database

DBAL, schema introspection, migration and pagination

64665.8k22](/packages/cycle-database)

PHPackages © 2026

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