PHPackages                             phel-lang/phel-sql - 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. phel-lang/phel-sql

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

phel-lang/phel-sql
==================

Data-driven SQL DSL for Phel Lang. HoneySQL-style. Pure data in, \[sql params\] out.

v0.1.0(3w ago)51[1 issues](https://github.com/phel-lang/phel-sql/issues)MITShellPHP &gt;=8.4CI passing

Since May 13Pushed 1w agoCompare

[ Source](https://github.com/phel-lang/phel-sql)[ Packagist](https://packagist.org/packages/phel-lang/phel-sql)[ Docs](https://phel-lang.org/)[ RSS](/packages/phel-lang-phel-sql/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

phel-sql
========

[](#phel-sql)

Data-driven SQL DSL for [Phel Lang](https://phel-lang.org/). Map in, `[sql params]` out. No database driver: the only job here is turning data into a parameterised query string.

Inspired by [HoneySQL](https://github.com/seancorfield/honeysql).

```
(sql/format
  {:select [:id :name]
   :from   [:users]
   :where  [:= :status "active"]})
;; => ["SELECT id, name FROM users WHERE status = ?" ["active"]]

```

Install
-------

[](#install)

```
composer require phel-lang/phel-sql
```

Requires PHP 8.4+ and `phel-lang/phel-lang` 0.37+.

Use it
------

[](#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
--------------

[](#what-it-covers)

StatementClauses`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, returningSet opsunion, union-all, intersect, except (top-level over a vector of queries)VALUEStop-level `{:values [...]}` as a standalone expressionWHERE 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:

FormRenders`[: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
----

[](#docs)

- [Quickstart](docs/quickstart.md): three queries, end to end.
- [Clauses](docs/clauses.md): every clause and operator.
- [Expressions](docs/expressions.md): function calls, CAST, CASE, window, FILTER, LATERAL.
- [Parameters](docs/parameters.md): keywords vs values, subqueries, raw fragments.
- [Contributing](docs/contributing.md): repo layout, tests, adding a clause.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance93

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

27d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d166420c6770c5941e10bd68b2d26501eabb432e280d8e6eba0a344bcc1e5ae?d=identicon)[Chemaclass](/maintainers/Chemaclass)

---

Top Contributors

[![Chemaclass](https://avatars.githubusercontent.com/u/5256287?v=4)](https://github.com/Chemaclass "Chemaclass (26 commits)")

---

Tags

phelphel-langphel-sqlsqlsqlquery builderlispphelhoneysql

### Embed Badge

![Health badge](/badges/phel-lang-phel-sql/health.svg)

```
[![Health](https://phpackages.com/badges/phel-lang-phel-sql/health.svg)](https://phpackages.com/packages/phel-lang-phel-sql)
```

###  Alternatives

[cycle/orm

PHP DataMapper ORM and Data Modelling Engine

1.3k888.3k72](/packages/cycle-orm)[usmanhalalit/pixie

A lightweight, expressive, framework agnostic query builder for PHP.

6872.2M16](/packages/usmanhalalit-pixie)[foolz/sphinxql-query-builder

A PHP query builder for SphinxQL and ManticoreQL with MySQLi and PDO drivers.

3232.2M33](/packages/foolz-sphinxql-query-builder)[nilportugues/sql-query-builder

An elegant lightweight and efficient SQL QueryInterface BuilderInterface supporting bindings and complicated query generation.

425242.6k6](/packages/nilportugues-sql-query-builder)[timgws/query-builder-parser

Build complex Eloquent &amp; QueryBuilder queries automatically when using jQuery-QueryBuilder

161399.7k](/packages/timgws-query-builder-parser)[cycle/database

DBAL, schema introspection, migration and pagination

65746.2k45](/packages/cycle-database)

PHPackages © 2026

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