Skip to content

Commit

Permalink
address #466 by collapsing 0-arity :and/:or
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Feb 28, 2023
1 parent 63c7a45 commit a610f25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
17 changes: 12 additions & 5 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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})))
Expand Down

0 comments on commit a610f25

Please sign in to comment.