andrew-gos/query-builder
最新稳定版本:v1.2.0
Composer 安装命令:
composer require andrew-gos/query-builder
包简介
QueryBuilder
README 文档
README
A lightweight, fluent SQL query builder with multi-dialect support (ANSI, MySQL, PostgreSQL) and an extensible expression system. Write complex SQL queries programmatically without string concatenation.
Quick Start
use AndrewGos\QueryBuilder\Grammar\DefaultGrammar; use AndrewGos\QueryBuilder\Query\Select\SelectQuery; $grammar = new DefaultGrammar(); $query = (new SelectQuery()) ->select(['id', 'name', 'email']) ->from(['users']) ->where(['active' => true]); $built = $grammar->buildSelectQuery($query); echo $built->sql; // SELECT "id", "name", "email" FROM "users" WHERE "active" IS TRUE print_r($built->params); // []
Features
| Feature | Status |
|---|---|
| SELECT, INSERT, UPDATE, DELETE, VALUES queries | ✅ |
| WHERE, HAVING, GROUP BY, ORDER BY, LIMIT / OFFSET | ✅ |
| JOIN (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL variants) | ✅ |
| Window functions (OVER, PARTITION BY, frame specs) | ✅ |
| Common Table Expressions (WITH, WITH RECURSIVE) | ✅ |
| PostgreSQL: MATERIALIZED CTE, SEARCH / CYCLE | ✅ |
| Set operations: UNION, INTERSECT, EXCEPT (ALL / DISTINCT) | ✅ |
| Row-level locking (FOR UPDATE / FOR SHARE, NOWAIT / SKIP LOCKED) | ✅ |
| MySQL: HIGH_PRIORITY, STRAIGHT_JOIN, SQL_* hints, PARTITION | ✅ |
| PostgreSQL: DISTINCT ON, ONLY modifier, RETURNING, ON CONFLICT | ✅ |
| Named parameter binding with auto-generated IDs | ✅ |
| MERGE query | ✅ |
| PostgreSQL: MERGE RETURNING, DO NOTHING | ✅ |
| Additional SQL dialects | 🚧 In development |
Documentation
- Quick Start Guide — Installation, first query, architecture overview.
- Query Types — Full reference for SELECT, INSERT, UPDATE, DELETE, VALUES, MERGE.
- Expressions — Expression system, ValueBuilder, conditions, windows, CTEs.
- Dialects — Default/ANSI, MySQL, and PostgreSQL grammar specifics.
Requirements
- PHP 8.5+
andrew-gos/helpers^1.0
Installation
composer require andrew-gos/query-builder
Roadmap
- v1.2.0 — Additional SQL dialects (SQLite, MariaDB)
License
This library is open-source software licensed under the MIT License.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-08