phel-lang/phel-sql
Composer 安装命令:
composer require phel-lang/phel-sql
包简介
Data-driven SQL DSL for Phel Lang. HoneySQL-style. Pure data in, [sql params] out.
README 文档
README
Data-driven SQL DSL for Phel Lang. Map in, [sql params] out. No database driver: the only job here is turning data into a parameterised query string.
Inspired by HoneySQL.
(sql/format
{:select [:id :name]
:from [:users]
:where [:= :status "active"]})
;; => ["SELECT id, name FROM users WHERE status = ?" ["active"]]
Install
composer require phel-lang/phel-sql
Requires PHP 8.4+ and phel-lang/phel-lang 0.37+.
Use it
(ns my-app.queries
(:require phel.sql :as sql))
(sql/format
{:with [[:active {:select [:id] :from [:users] :where [:= :status "active"]}]]
:select [:u/id
[[:over [:fn :row_number]
{:partition-by [:u/dept]
:order-by [[:u/salary :desc]]}]
:rk]
[[:case [:> :u/salary 100000] "high" :else "low"] :tier]]
:from [[:users :u]]
:join [[:active :a] [:using :id]]
:where [:>= :u/age 18]
:order-by [[:u/dept :asc :nulls-last]]
:limit 10})
Pass the tuple to any PDO-like driver:
$pdo->prepare($sql)->execute($params);
What it covers
| Statement | Clauses |
|---|---|
SELECT |
with, with-recursive, select / select-distinct / select-distinct-on, from, joins (inner / left / right / full / cross / LATERAL), USING / ON, where, group-by, having, order-by (asc / desc / nulls-first / nulls-last), limit, offset, for (lock), returning |
INSERT |
with, insert-into, columns, values (vector rows or map rows), on-conflict + do-nothing / do-update-set / on-conflict-where / do-update-where (Postgres), on-duplicate-key-update (MySQL), returning |
UPDATE |
with, update, set, from, where, order-by, limit, returning |
DELETE |
with, delete-from, where, order-by, limit, returning |
| Set ops | union, union-all, intersect, except (top-level over a vector of queries) |
| VALUES | top-level {:values [...]} as a standalone expression |
WHERE operators: =, !=, <, >, <=, >=, like, not-like, ilike, not-ilike, and, or, not, in, not-in, between, not-between, is-null, is-not-null, exists, not-exists.
Tagged expression forms usable anywhere an identifier or operand is accepted:
| Form | Renders |
|---|---|
[:raw "SQL"] |
raw fragment |
[:fn name & args] |
name(args...) |
[:cast expr type] |
CAST(expr AS TYPE) |
[:case test then ... :else d] |
CASE WHEN ... THEN ... ELSE ... END |
[:over expr spec] |
window function with :partition-by, :order-by, :frame |
[:filter expr where] |
aggregate FILTER (WHERE ...) |
[:lateral subquery] |
LATERAL (...) |
Subqueries (maps) work anywhere an identifier or value is accepted. [:raw "SQL"] is the escape hatch for fragments the DSL does not yet cover.
Docs
- Quickstart: three queries, end to end.
- Clauses: every clause and operator.
- Expressions: function calls, CAST, CASE, window, FILTER, LATERAL.
- Parameters: keywords vs values, subqueries, raw fragments.
- Contributing: repo layout, tests, adding a clause.
phel-lang/phel-sql 适用场景与选型建议
phel-lang/phel-sql 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 5, 最近一次更新时间为 2026 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sql」 「lisp」 「query-builder」 「phel」 「honeysql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phel-lang/phel-sql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phel-lang/phel-sql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phel-lang/phel-sql 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel, Lumen and Native php elasticseach query builder to build complex queries using an elegant syntax
Query filtering in your frontend
GraphQL client and query builder.
GraphQL client and query builder. PHP 8.4 compatible
Database/ORM-agnostic query construction helper
Laravel SQL Queries Dumper
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 54
- 依赖项目数: 0
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-13