Skip to content

Commit

Permalink
fixes #461; prep for 2.4.980
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Feb 16, 2023
1 parent 0a6f645 commit de0adf5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion doc/differences-from-1-x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "+-*%|&^=<>"))
Expand All @@ -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)]
Expand Down Expand Up @@ -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 ")")))]
Expand Down
30 changes: 29 additions & 1 deletion test/honey/sql_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]]}))))

0 comments on commit de0adf5

Please sign in to comment.