diff --git a/CHANGELOG.md b/CHANGELOG.md index 75244eb..5d3c7bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changes +* 2.4.980 -- 2023-02-15 + * Fix [#461](https://github.com/seancorfield/honeysql/issues/461) -- a regression introduced in 2.4.979 -- by restricting unary operators to just `+`, `-`, and `~` (bitwise negation). + * 2.4.979 -- 2023-02-11 * Address [#459](https://github.com/seancorfield/honeysql/issues/459) by making all operators variadic (except `:=` and `:<>`). * Address [#458](https://github.com/seancorfield/honeysql/issues/458) by adding `registered-*?` predicates. diff --git a/README.md b/README.md index 942814f..24069ad 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ SQL as Clojure data structures. Build queries programmatically -- even at runtim ## Build -[![Clojars Project](https://clojars.org/com.github.seancorfield/honeysql/latest-version.svg)](https://clojars.org/com.github.seancorfield/honeysql) [![cljdoc badge](https://cljdoc.org/badge/com.github.seancorfield/honeysql?2.4.979)](https://cljdoc.org/d/com.github.seancorfield/honeysql/CURRENT) +[![Clojars Project](https://clojars.org/com.github.seancorfield/honeysql/latest-version.svg)](https://clojars.org/com.github.seancorfield/honeysql) [![cljdoc badge](https://cljdoc.org/badge/com.github.seancorfield/honeysql?2.4.980)](https://cljdoc.org/d/com.github.seancorfield/honeysql/CURRENT) This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository. diff --git a/doc/differences-from-1-x.md b/doc/differences-from-1-x.md index ce26961..deab784 100644 --- a/doc/differences-from-1-x.md +++ b/doc/differences-from-1-x.md @@ -63,7 +63,7 @@ Supported Clojure versions: 1.7 and later. In `deps.edn`: ```clojure -com.github.seancorfield/honeysql {:mvn/version "2.4.979"} +com.github.seancorfield/honeysql {:mvn/version "2.4.980"} ``` Required as: diff --git a/doc/getting-started.md b/doc/getting-started.md index f3e67ed..2c7cfa2 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -10,14 +10,14 @@ For the Clojure CLI, add the following dependency to your `deps.edn` file: ```clojure - com.github.seancorfield/honeysql {:mvn/version "2.4.979"} + com.github.seancorfield/honeysql {:mvn/version "2.4.980"} ``` For Leiningen, add the following dependency to your `project.clj` file: ```clojure - [com.github.seancorfield/honeysql "2.4.979"] + [com.github.seancorfield/honeysql "2.4.980"] ``` HoneySQL produces SQL statements but does not execute them. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 19e9c45..ffc0ecd 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -1268,7 +1268,7 @@ (def ^:private infix-ops (-> #{"mod" "and" "or" "xor" "<>" "<=" ">=" "||" "<->" - "like" "not-like" "regexp" "&&" + "like" "not-like" "regexp" "~" "&&" "ilike" "not-ilike" "similar-to" "not-similar-to" "is" "is-not" "not=" "!=" "regex"} (into (map str "+-*%|&^=<>")) @@ -1279,6 +1279,10 @@ (atom))) (def ^:private op-ignore-nil (atom #{:and :or})) +(def ^:private op-can-be-unary + "The operators that can be unary. This is a fixed set until someone + identifies any new ones." + (atom (into #{} (map (comp keyword str) "+-~")))) (defn- unwrap [x opts] (if-let [m (meta x)] @@ -1591,7 +1595,8 @@ (throw (ex-info (str "no operands found for " op') {:expr expr}))) (into [(cond-> (str/join (str " " (sql-kw op) " ") sqls) - (= 1 (count sqls)) + (and (contains? @op-can-be-unary op) + (= 1 (count sqls))) (as-> s (str (sql-kw op) " " s)) nested (as-> s (str "(" s ")")))] diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 4894d98..14b21fb 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -1065,9 +1065,37 @@ ORDER BY id = ? DESC (deftest issue-459-variadic-ops (sut/register-op! :op) - (is (= ["SELECT OP a"] + (is (= ["SELECT a"] ; not unary! (sut/format {:select [[[:op :a]]]}))) (is (= ["SELECT a OP b"] (sut/format {:select [[[:op :a :b]]]}))) (is (= ["SELECT a OP b OP c"] (sut/format {:select [[[:op :a :b :c]]]})))) + +(deftest issue-461-unary-ops + (is (= ["SELECT TRUE"] + (sut/format {:select [[[:and true]]]}))) + (is (= ["SELECT TRUE"] + (sut/format {:select [[[:or true]]]}))) + (is (= ["SELECT ?" 1] + (sut/format {:select [[[:* 1]]]}))) + (is (= ["SELECT TRUE AND a AND b"] + (sut/format {:select [[[:and true :a :b]]]}))) + (is (= ["SELECT TRUE OR a OR b"] + (sut/format {:select [[[:or true :a :b]]]}))) + (is (= ["SELECT ? * ? * ?" 1 2 3] + (sut/format {:select [[[:* 1 2 3]]]}))) + ;; but these three genuinely are unary: + (is (= ["SELECT + ?" 1] + (sut/format {:select [[[:+ 1]]]}))) + (is (= ["SELECT - ?" 1] + (sut/format {:select [[[:- 1]]]}))) + (is (= ["SELECT ~ ?" 1] ; bitwise negation + (sut/format {:select [[[(keyword "~") 1]]]}))) + ;; and can still be used as variadic: + (is (= ["SELECT ? + ?" 1 2] + (sut/format {:select [[[:+ 1 2]]]}))) + (is (= ["SELECT ? - ?" 1 2] + (sut/format {:select [[[:- 1 2]]]}))) + (is (= ["SELECT ? ~ ?" "a" "b"] ; regex op + (sut/format {:select [[[(keyword "~") "a" "b"]]]}))))