PHPackages                             hindbiswas/quebee - 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. hindbiswas/quebee

ActiveLibrary

hindbiswas/quebee
=================

Qb - a lightweight Query Builder for SQL

v2.0.2(2y ago)478MITPHPPHP &gt;=8.1

Since Sep 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hind-sagar-biswas/quebee)[ Packagist](https://packagist.org/packages/hindbiswas/quebee)[ RSS](/packages/hindbiswas-quebee/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (15)Used By (0)

QueBee: A PHP SQL Query Builder
===============================

[](#quebee-a-php-sql-query-builder)

```
            ███████╗ ██╗   ██╗███████╗                               ...vvvv)))))).
            ██╔═══██╗██║   ██║██╔════╝    /~~\               ,,,c(((((((((((((((((/
            ██║██╗██║██║   ██║█████╗     /~~c \.         .vv)))))))))))))))))))\``
            ███████╔╝██║   ██║██╔══╝         G_G__   ,,(((KKKK//////////////'
             ╚═██╔═╝ ╚██████╔╝███████╗     ,Z~__ '@,gW@@AKXX~MW,gmmmz==m_.
               ╚═╝    ╚═════╝ ╚══════╝    iP,dW@!,A@@@@@@@@@@@@@@@A` ,W@@A\c
            ██████╗ ███████╗███████╗       ]b_.__zf !P~@@@@@*P~b.~+=m@@@*~ g@Ws.
            ██╔══██╗██╔════╝██╔════╝          ~`    ,2W2m. '\[ ['~~c'M7 _gW@@A`'s
            ██████╦╝█████╗  █████╗              v=XX)====Y-  [ [    \c/*@@@*~ g@@i
            ██╔══██╗██╔══╝  ██╔══╝             /v~           !.!.     '\c7+sg@@@@@s.
            ██████╦╝███████╗███████╗          //              'c'c       '\c7*X7~~~~
            ╚═════╝ ╚══════╝╚══════╝         ]/                 ~=Xm_       '~=(Gm_.

```

[![Project Language](https://camo.githubusercontent.com/7c53f47317cd57a4bcfc343b4ba0e05f5e9623fba0aadd4766e3960d4884036d/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c616e6775616765266d6573736167653d70687026636f6c6f723d707572706c65)](https://camo.githubusercontent.com/7c53f47317cd57a4bcfc343b4ba0e05f5e9623fba0aadd4766e3960d4884036d/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c616e6775616765266d6573736167653d70687026636f6c6f723d707572706c65)[![Project Type](https://camo.githubusercontent.com/711fe6a9df043993dd2110b759d9db3e393d9f3e5547d149b291688da17895b7/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d74797065266d6573736167653d6c69627261727926636f6c6f723d726564)](https://camo.githubusercontent.com/711fe6a9df043993dd2110b759d9db3e393d9f3e5547d149b291688da17895b7/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d74797065266d6573736167653d6c69627261727926636f6c6f723d726564)[![Stable Version](https://camo.githubusercontent.com/0fb89a618e2fa638facd7b383c898cf3ddd2252921ba9a7cba9aae0ea7c22704/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d737461626c652d76657273696f6e266d6573736167653d76322e302e3026636f6c6f723d627269676874677265656e)](https://camo.githubusercontent.com/0fb89a618e2fa638facd7b383c898cf3ddd2252921ba9a7cba9aae0ea7c22704/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d737461626c652d76657273696f6e266d6573736167653d76322e302e3026636f6c6f723d627269676874677265656e)[![Latest Version](https://camo.githubusercontent.com/514affc13b1c7a4c1e4ca50c3b69b4a92912b49d8ed0eb4990bdce8d59fbe44b/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c61746573742d76657273696f6e266d6573736167653d76322e302e3026636f6c6f723d79656c6c6f77)](https://camo.githubusercontent.com/514affc13b1c7a4c1e4ca50c3b69b4a92912b49d8ed0eb4990bdce8d59fbe44b/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c61746573742d76657273696f6e266d6573736167653d76322e302e3026636f6c6f723d79656c6c6f77)[![Maintained](https://camo.githubusercontent.com/f9e759694715489b9efd00ef254cc353be2e1250eb4797925753531129f934d4/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6d61696e7461696e6564266d6573736167653d79657326636f6c6f723d726564)](https://camo.githubusercontent.com/f9e759694715489b9efd00ef254cc353be2e1250eb4797925753531129f934d4/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6d61696e7461696e6564266d6573736167653d79657326636f6c6f723d726564)[![License](https://camo.githubusercontent.com/1fa62ecf6c53dfa1edefe66fa5ff3ad07a2db9166528b34ce1046b7c16e966a4/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c6963656e7365266d6573736167653d4d495426636f6c6f723d6f72616e6765)](https://camo.githubusercontent.com/1fa62ecf6c53dfa1edefe66fa5ff3ad07a2db9166528b34ce1046b7c16e966a4/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c6963656e7365266d6573736167653d4d495426636f6c6f723d6f72616e6765)[![PRs Welcome](https://camo.githubusercontent.com/dd0b24c1e6776719edb2c273548a510d6490d8d25269a043dfabbd38419905da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e737667)](https://github.com/hind-sagar-biswas/quebee/pulls)

Introduction
------------

[](#introduction)

The QᴜᴇᴇBᴇᴇ (QB) or Query Builder package is a lightweight package for Building MySQL Queries. It is a PHP package that simplifies the construction of SQL queries. It provides an object-oriented approach to building SQL queries, making it easier to create, modify, and execute SQL statements in your PHP applications.

Installation
------------

[](#installation)

### 1. Composer

[](#1-composer)

QueBee can be installed via Composer, a PHP dependency manager. If you haven't installed Composer yet, visit [composer's website](https://getcomposer.org) for instructions.

Run the following command to install QueBee:

```
composer require hindbiswas/quebee
```

### 2. Autoloading

[](#2-autoloading)

Ensure that Composer's autoloader is included in your project's PHP files. Use your path in place of `path/to/`:

```
require_once __DIR__ . DIRECTORY_SEPARATOR . 'path/to' . '/vendor/autoload.php';
```

Features
--------

[](#features)

QueBee provides following features to work with MySQL:

1. **Queries:** `Query` class for `SELECT`, `INSERT`, `UPDATE`, and `DELETE` queries.
2. **Table:** `Table` class for `CREATE TABLE` along with `Col` class for columns.
3. **Columns:** `Col` class has a bunch of datatypes like `INT`, `VARCHAR`, `DATETIME` and many more for creating columns as per your requirements.
4. **Statements:** `Stmt` class for `UNION`, `UNION ALL`, `CUBE`, `SET`, and `GROUPING SETS` statements.

It also includes foreign key constraints, unique, primary key and indexing as well as grouping. See the `/tests/` directory for all possible ways of using the `QueBee`;

Usage
-----

[](#usage)

Below are examples of how to use each query builder.

### 1. SELECT Query

[](#1-select-query)

To create a `SELECT` query, use the `Query::select()` method:

```
use Hindbiswas\QueBee\Query;

$aliased_cols = ['alias1' => 'column1', 'alias2' => 'column2', 'column3' => 'column3'];
$query = Query::select($aliased_cols)->from('table')->build();

// Resulting SQL query
// SELECT column1 AS alias1, column2 AS alias2, column3 AS column3 FROM table;
```

Or,

```
use Hindbiswas\QueBee\Query;

$query = Query::select(['column1', 'column2'])
    ->from('table')
    ->where('column1', 'value')
    ->orderBy('column2', 'desc')
    ->limit(10)
    ->build();

// Resulting SQL query
// SELECT column1, column2 FROM table WHERE column1 = 'value' ORDER BY column2 DESC LIMIT 0, 10;
```

#### condition aliases for conditional statements

[](#condition-aliases-for-conditional-statements)

SQLLiteralSymbolic`>``gt``>``>=``gte``>=`` 'value2'];

$query = Query::insert($data)
    ->into('table')
    ->build();

// Resulting SQL query
// INSERT INTO table (column1, column2) VALUES ('value1', 'value2');
```

### 3. UPDATE Queries

[](#3-update-queries)

To create an `UPDATE` query, use the `Query::update()` method:

```
use Hindbiswas\QueBee\Query;

$data = ['column1' => 'new_value1', 'column2' => 'new_value2'];

$query = Query::update('table')
    ->set($data)
    ->where('column1', 'value1')
    ->build();

// Resulting SQL query
// UPDATE table SET column1 = 'new_value1', column2 = 'new_value2' WHERE column1 = 'value1';
```

### 4. DELETE Queries

[](#4-delete-queries)

To create a `DELETE` query, use the `Query::delete()` method:

```
$query = Query::delete('table')->where('column1', 1, 'gt')->build() // Here `gt` is alias for `>`

// Resulting SQL query
// DELETE FROM table WHERE column1 > '1';
```

### 5. CREATE TABLE Queries

[](#5-create-table-queries)

To create a `CREATE TABLE` query, use the `Table::create()` method:

#### Without Any Foreign Keys

[](#without-any-foreign-keys)

```
use Hindbiswas\QueBee\Col;
use Hindbiswas\QueBee\Table;
use Hindbiswas\QueBee\Table\Values\DefaultVal;

$usersTable = Table::create('users')->columns([
    'id' => Col::integer(11)->unsigned()->pk()->ai(),
    'username' => Col::varchar()->unique(),
    'email' => Col::varchar()->unique(),
    'password' => Col::varchar(),
    'is_superadmin' => Col::integer(2)->default('0'),
    'create_time' => Col::dateTime()->default(DefaultVal::CURRENT_TIME),
    'update_time' => Col::dateTime()->setOnUpdate()->default(DefaultVal::CURRENT_TIME),
]);

$query = $usersTable->build();

// Resulting SQL query
// CREATE TABLE IF NOT EXISTS users (`id` INT(11) UNSIGNED NULL AUTO_INCREMENT, `username` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, `is_superadmin` INT(2) NOT NULL DEFAULT '0', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` DATETIME on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_PK PRIMARY KEY (id), CONSTRAINT username_UC UNIQUE (`username`), CONSTRAINT email_UC UNIQUE (`email`)) ENGINE = InnoDB;
```

#### With Foreign Keys

[](#with-foreign-keys)

```
use Hindbiswas\QueBee\Col;
use Hindbiswas\QueBee\Table;
use Hindbiswas\QueBee\Table\Values\DefaultVal;
use Hindbiswas\QueBee\Table\Values\FK;

// $usersTable = create a table to constrain with

$table = Table::create('tokens')->columns([
    'id' => Col::integer()->unsigned()->pk()->ai(),
    'selector' => Col::varchar(),
    'hashed_validator' => Col::varchar(),
    'user_id' => Col::integer(11)->unsigned(),
    'expiry' => Col::dateTime(),
])->foreign('user_id')->onDelete(FK::CASCADE)->reference($usersTable, 'id');

// Resulting SQL query
// CREATE TABLE IF NOT EXISTS tokens (`id` INT UNSIGNED NULL AUTO_INCREMENT, `selector` VARCHAR(255) NOT NULL, `hashed_validator` VARCHAR(255) NOT NULL, `user_id` INT(11) UNSIGNED NOT NULL, `expiry` DATETIME NOT NULL, CONSTRAINT tokens_PK PRIMARY KEY (id), FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE) ENGINE = InnoDB;
```

#### Available Data Types as of `v1.2.0`

[](#available-data-types-as-of-v120)

- String
    - TEXT =&gt; `Col::text()`
    - VARCHAR =&gt; `Col::varchar(225)`
- Numeric
    - BIT =&gt; `Col::bit()`
    - INT =&gt; `Col::integer()`
    - BIGINT =&gt; `Col::bigInt()`
    - MEDIUMINT =&gt; `Col::mediumInt()`
    - SMALLINT =&gt; `Col::smallInt()`
    - TINYINT =&gt; `Col::tinyInt()`
    - DECIMAL =&gt; `Col::decimal(11, 6)`
    - FLOAT =&gt; `Col::float(6, 2)`
    - DOUBLE =&gt; `Col::double(11, 6)`
    - REAL =&gt; `Col::real(11, 6)`
- Time
    - DATE =&gt; `Col::date()`
    - DATETIME =&gt; `Col::dateTime()`

Best Practices
--------------

[](#best-practices)

Here are some best practices when using **QueBee**:

1. **Sanitize User Inputs:** Always sanitize user inputs before using them in queries.
2. **Error Handling:** Handle exceptions appropriately, especially when building queries. QueBee can throw exceptions for invalid input or method calls.
3. **Database Abstraction:** Consider using a database abstraction layer alongside QueBee for more extensive database interactions.
4. **Code Organization:** Organize your code logically, separating query building from execution and result handling.

Conclusion
----------

[](#conclusion)

QueBee simplifies SQL query construction in PHP, making it easier to build clean, secure, and efficient database interactions. With its fluent API, it provides a user-friendly way to create SQL queries for various database systems.

For more detailed usage and customization options, refer to the QueBee GitHub repository.

That's it! You're ready to start using QueBee for building SQL queries in your PHP applications.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Recently: every ~12 days

Total

12

Last Release

748d ago

Major Versions

v1.3.0 → v2.0.02023-11-28

v1.3.3 → v2.0.22024-04-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f80c3a03d68d7009942d400a5e29d6f56c203405870e58c9073d5a8dd03b5f7?d=identicon)[HindSagarBiswas](/maintainers/HindSagarBiswas)

---

Top Contributors

[![hind-sagar-biswas](https://avatars.githubusercontent.com/u/69765092?v=4)](https://github.com/hind-sagar-biswas "hind-sagar-biswas (151 commits)")

---

Tags

composer-librarymysqlphp-libraryphp8query-buildersql-query-builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hindbiswas-quebee/health.svg)

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

PHPackages © 2026

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