Search by

alekvolsk / qbuilder

AlekVolsk

SQL Query Builder with fluent interface supporting multiple database drivers (MySQL, PostgreSQL, SQLite, MSSQL, Oracle, ClickHouse)

v1.0.0 2026-09-23 03:15 UTC

This package is auto-updated.

Last update: 2026-09-23 03:46:05 UTC


README

License: MIT PHP Version

QBuilder is a PHP library that builds SQL query strings through a fluent API for MySQL/MariaDB, PostgreSQL, ClickHouse, MS SQL Server, Oracle and SQLite. It generates SQL only and does not open connections or execute queries.

  • SELECT, INSERT, UPDATE, DELETE queries
  • WHERE and HAVING conditions with nested groups
  • JOINs, subqueries, aggregates, UNION, recursive CTEs
  • Two syntaxes: method chaining and closures
  • PHPUnit test suite, PHPStan level 10

Installation

composer require alekvolsk/qbuilder

Requirements

  • PHP >= 8.4

Quick Start

use QBuilder\QbConsts;
use QBuilder\QueryBuilder;

$sql = (new QueryBuilder(QbConsts::DRIVER_PDO_MYSQL))
    ->select('id', 'name', 'email')
    ->from('users')
    ->where()
        ->eq('status', 'active')
        ->end()
    ->build(true);

// SELECT `id`, `name`, `email` FROM `users` WHERE (`status` = 'active')

Documentation

Contributing

See CONTRIBUTING.md.

License

MIT