PHPackages                             cloud-castle/sql-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. cloud-castle/sql-builder

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

cloud-castle/sql-builder
========================

Sqlbuilder library

1.0.0.6(1y ago)10MITPHPPHP &gt;=8.3CI failing

Since May 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/zorinalexey/cloud-castle-sql-builder)[ Packagist](https://packagist.org/packages/cloud-castle/sql-builder)[ RSS](/packages/cloud-castle-sql-builder/feed)WikiDiscussions main Synced 1mo ago

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

CloudCastle SQL Builder
=======================

[](#cloudcastle-sql-builder)

A powerful and flexible SQL query builder library for PHP that provides a fluent interface for building complex database queries.

Features
--------

[](#features)

- Fluent interface for building SQL queries
- Support for all major SQL operations:
    - SELECT queries with advanced features
    - INSERT operations
    - UPDATE operations
    - DELETE operations
- Advanced query building capabilities:
    - JOIN operations (LEFT, RIGHT, INNER, etc.)
    - WHERE conditions
    - Aggregate functions (MIN, MAX, AVG, SUM)
    - DISTINCT queries
    - CASE statements
    - Subqueries
    - Table aliases
- Type-safe implementation with strict typing
- Clean and maintainable code structure

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

[](#installation)

```
composer require cloud-castle/sql-builder
```

Usage
-----

[](#usage)

### Basic Query Building

[](#basic-query-building)

```
use CloudCastle\SqlBuilder\QueryBuilder;

$queryBuilder = new QueryBuilder();

// SELECT query
$selectQuery = $queryBuilder->select('users')
    ->columns(['id', 'name', 'email'])
    ->where('active', '=', true)
    ->toSql();

// INSERT query
$insertQuery = $queryBuilder->insert('users')
    ->values([
        'name' => 'John Doe',
        'email' => 'john@example.com'
    ])
    ->toSql();

// UPDATE query
$updateQuery = $queryBuilder->update('users')
    ->set(['active' => false])
    ->where('id', '=', 1)
    ->toSql();

// DELETE query
$deleteQuery = $queryBuilder->delete('users')
    ->where('id', '=', 1)
    ->toSql();
```

### Advanced Features

[](#advanced-features)

#### JOIN Operations

[](#join-operations)

```
$select = $queryBuilder->select('users');
$join = $select->join('orders', 'left')
    ->on('users.id', '=', 'orders.user_id')
    ->columns(['users.*', 'orders.total']);
```

#### Aggregate Functions

[](#aggregate-functions)

```
$query = $queryBuilder->select('orders')
    ->min('total', 'min_total')
    ->max('total', 'max_total')
    ->avg('total', 'avg_total')
    ->sum('total', 'total_sum');
```

#### DISTINCT Queries

[](#distinct-queries)

```
$query = $queryBuilder->select('users')
    ->distinct(['email', 'name']);
```

#### CASE Statements

[](#case-statements)

```
$select = $queryBuilder->select('orders');
$case = $select->case('status_label')
    ->when('status', '=', 'pending', 'Pending')
    ->when('status', '=', 'completed', 'Completed')
    ->else('Unknown');
```

Project Structure
-----------------

[](#project-structure)

```
src/
├── Common/         # Common components and utilities
├── Enums/          # Enumeration classes
├── Interfaces/     # Interface definitions
├── Query/          # Query implementation classes
├── Schema/         # Database schema related classes
└── Traits/         # Reusable traits

```

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance47

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community7

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

Total

6

Last Release

416d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/74205167?v=4)[Алексей](/maintainers/zorinalexey)[@zorinalexey](https://github.com/zorinalexey)

---

Top Contributors

[![zorinalexey](https://avatars.githubusercontent.com/u/74205167?v=4)](https://github.com/zorinalexey "zorinalexey (21 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cloud-castle-sql-builder/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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