From a610f256dd50e1405ad9ad3c0181eca3d557b58d Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Mon, 27 Feb 2023 20:07:24 -0800 Subject: [PATCH] address #466 by collapsing 0-arity :and/:or --- CHANGELOG.md | 1 + src/honey/sql.cljc | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1089a02..00d9372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * 2.4.next in progress * Fix [#467](https://github.com/seancorfield/honeysql/issues/467) by allowing single keywords (symbols) as a short hand for a single-element sequence in more constructs via PR [#470](https://github.com/seancorfield/honeysql/pull/470) [@p-himik](https://github.com/p-himik). + * Address [#466](https://github.com/seancorfield/honeysql/issues/466) by treating `[:and]` as `TRUE` and `[:or]` as `FALSE`. * Fix [#465](https://github.com/seancorfield/honeysql/issues/465) to allow multiple columns in `:order-by` special syntax via PR [#468](https://github.com/seancorfield/honeysql/pull/468) [@p-himik](https://github.com/p-himik). * Fix [#464](https://github.com/seancorfield/honeysql/issues/464) by adding an optional type argument to `:array` via PR [#469](https://github.com/seancorfield/honeysql/pull/469) [@p-himik](https://github.com/p-himik). diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 13f23e1..3f559b1 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -1590,12 +1590,19 @@ (vector) (into p1) (into p2))) - (let [x (if (contains? @op-ignore-nil op) - (remove nil? expr) - expr) + (let [args (cond->> (rest expr) + (contains? @op-ignore-nil op) + (remove nil?)) + args (cond (seq args) + args + (= :and op) + [true] + (= :or op) + [false] + :else ; args is empty and not a special case + []) [sqls params] - (reduce-sql (map #(format-expr % {:nested true}) - (rest x)))] + (reduce-sql (map #(format-expr % {:nested true}) args))] (when-not (pos? (count sqls)) (throw (ex-info (str "no operands found for " op') {:expr expr})))