fixes #461; prep for 2.4.980
This commit is contained in:
parent
0a6f645d91
commit
de0adf56ef
6 changed files with 43 additions and 7 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ SQL as Clojure data structures. Build queries programmatically -- even at runtim
|
|||
|
||||
## Build
|
||||
|
||||
[](https://clojars.org/com.github.seancorfield/honeysql) [](https://cljdoc.org/d/com.github.seancorfield/honeysql/CURRENT)
|
||||
[](https://clojars.org/com.github.seancorfield/honeysql) [](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.
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Supported Clojure versions: 1.7 and later.
|
|||
In `deps.edn`:
|
||||
<!-- :test-doc-blocks/skip -->
|
||||
```clojure
|
||||
com.github.seancorfield/honeysql {:mvn/version "2.4.979"}
|
||||
com.github.seancorfield/honeysql {:mvn/version "2.4.980"}
|
||||
```
|
||||
|
||||
Required as:
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ For the Clojure CLI, add the following dependency to your `deps.edn` file:
|
|||
|
||||
<!-- :test-doc-blocks/skip -->
|
||||
```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:
|
||||
|
||||
<!-- :test-doc-blocks/skip -->
|
||||
```clojure
|
||||
[com.github.seancorfield/honeysql "2.4.979"]
|
||||
[com.github.seancorfield/honeysql "2.4.980"]
|
||||
```
|
||||
|
||||
HoneySQL produces SQL statements but does not execute them.
|
||||
|
|
|
|||
|
|
@ -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 ")")))]
|
||||
|
|
|
|||
|
|
@ -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"]]]}))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue