jardissupport/dbquery
Composer 安装命令:
composer require jardissupport/dbquery
包简介
Fluent SQL query builder with CTEs, window functions, subqueries, and JSON support for MySQL, MariaDB, PostgreSQL, and SQLite
关键字:
README 文档
README
Part of Jardis — the Domain-Driven Design platform for PHP. You model your domain; Jardis generates the production-ready hexagonal code (DTOs, Command/Query handlers, repositories, persistence). This package is part of the open-source foundation that generated code runs on.
A fluent SQL query builder for PHP that generates dialect-aware SQL for MySQL, MariaDB, PostgreSQL, and SQLite. Full support for CTEs, window functions, subqueries, JSON columns, and prepared statements. SQL injection protection built in.
Features
- Dialect-Aware SQL — generates correct syntax for MySQL, MariaDB, PostgreSQL, and SQLite from a single builder
- CTEs —
with()andwithRecursive()for common table expressions - Window Functions —
selectWindow(),window(), andselectWindowRef()for analytics queries - Subqueries — subqueries in FROM, JOIN constraints, SELECT columns, and WHERE EXISTS / NOT EXISTS
- JSON Column Support —
whereJson(),andJson(),orJson(),havingJson()for structured JSON field conditions - Union / Union All —
union()andunionAll()compose multiple SELECT statements - Prepared Statements —
sql($dialect, prepared: true)returns aDbPreparedQueryInterfacewith bound parameters - SQL Injection Validation — bracket and expression validation built into
sql()before generation - INSERT Conflict Handling —
DbInsertsupports ON DUPLICATE KEY (MySQL) and ON CONFLICT (PostgreSQL)
Installation
composer require jardissupport/dbquery
Quick Start
use JardisSupport\DbQuery\DbQuery; $query = (new DbQuery()) ->select('id, name, email') ->from('users') ->where('status')->equals('active') ->and('created_at')->greaterEquals('2024-01-01') ->orderBy('name') ->limit(50); // Generate prepared SQL for MySQL $prepared = $query->sql('mysql', prepared: true); // $prepared->sql() → "SELECT id, name, email FROM users WHERE status = ? AND created_at >= ? ORDER BY name ASC LIMIT 50" // $prepared->bindings() → ['active', '2024-01-01']
Advanced Usage
use JardisSupport\DbQuery\DbQuery; use JardisSupport\DbQuery\DbInsert; // CTE with recursive traversal $cte = (new DbQuery()) ->select('id, parent_id, name, 0 AS depth') ->from('categories') ->where('parent_id')->isNull() ->union( (new DbQuery()) ->select('c.id, c.parent_id, c.name, r.depth + 1') ->from('categories', 'c') ->innerJoin('category_tree', 'c.parent_id = r.id', 'r') ); $query = (new DbQuery()) ->withRecursive('category_tree', $cte) ->select('id, name, depth') ->from('category_tree') ->orderBy('depth') ->orderBy('name'); // Window function for ranking $ranked = (new DbQuery()) ->select('id, customer_id, total') ->selectWindow('ROW_NUMBER', 'row_num') ->over() ->partitionBy('customer_id') ->orderBy('total', 'DESC') ->end() ->from('orders'); // JSON column condition (PostgreSQL) $query = (new DbQuery()) ->select('id, payload') ->from('events') ->whereJson('payload')->path('$.type')->equals('order.created') ->andJson('payload')->path('$.amount')->greaterEquals(100); // INSERT with conflict resolution $insert = (new DbInsert()) ->into('products') ->fields('sku', 'name', 'price') ->values('ABC-001', 'Widget', 9.99) ->onDuplicateKey(['name', 'price']); $sql = $insert->sql('mysql', prepared: true);
Documentation
Full documentation, guides, and API reference:
docs.jardis.io/en/support/dbquery
License
This package is licensed under the MIT License.
Jardis · Documentation · Headgent
AI-Assisted Development
This package ships with a skill for Claude Code, Cursor, Continue, and Aider. Install it in your consuming project:
composer require --dev jardis/dev-skills
More details: https://docs.jardis.io/en/skills
jardissupport/dbquery 适用场景与选型建议
jardissupport/dbquery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 398 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「php」 「sql」 「query」 「pdo」 「query-builder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jardissupport/dbquery 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jardissupport/dbquery 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jardissupport/dbquery 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Query filtering in your frontend
A PSR-7 compatible library for making CRUD API endpoints
Database/ORM-agnostic query construction helper
统计信息
- 总下载量: 398
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 37
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-31