Skip to content

Commit

Permalink
fixes #538
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Corfield <[email protected]>
  • Loading branch information
seancorfield committed Sep 23, 2024
1 parent 084c1ec commit 230cc46
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 2.6.next in progress
* Fix [#543](https://github.com/seancorfield/honeysql/issues/543) by supporting both symbols and keywords in named parameters.
* Getting Started updated based on feedback from Los Angeles Clojure meetup walkthrough [#539](https://github.com/seancorfield/honeysql/issues/539).
* Fix [#538](https://github.com/seancorfield/honeysql/issues/538) by removing `mod` from list of infix operators.
* Update Clojure version to 1.12.0.

* 2.6.1161 -- 2024-08-29
Expand Down
2 changes: 1 addition & 1 deletion doc/extending-honeysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ register formatters or behavior corresponding to clauses,
operators, and functions.

Built in clauses include: `:select`, `:from`, `:where` and
many more. Built in operators include: `:=`, `:+`, `:mod`.
many more. Built in operators include: `:=`, `:+`, `:%`.
Built in functions (special syntax) include: `:array`, `:case`,
`:cast`, `:inline`, `:raw` and many more.

Expand Down
2 changes: 1 addition & 1 deletion src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@
:regex :regexp})

(def ^:private infix-ops
(-> #{"mod" "and" "or" "xor" "<>" "<=" ">=" "||" "<->"
(-> #{"and" "or" "xor" "<>" "<=" ">=" "||" "<->"
"like" "not-like" "regexp" "~" "&&"
"ilike" "not-ilike" "similar-to" "not-similar-to"
"is" "is-not" "not=" "!=" "regex"
Expand Down
10 changes: 9 additions & 1 deletion test/honey/sql/helpers_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,15 @@
{:params {:ids values} :numbered true})))))))

(deftest test-case
(is (= ["SELECT CASE WHEN foo < ? THEN ? WHEN (foo > ?) AND ((foo MOD ?) = ?) THEN foo / ? ELSE ? END FROM bar"
(is (= ["SELECT CASE WHEN foo < ? THEN ? WHEN (foo > ?) AND ((foo % ?) = ?) THEN foo / ? ELSE ? END FROM bar"
0 -1 0 2 0 2 0]
(sql/format
{:select [[[:case
[:< :foo 0] -1
[:and [:> :foo 0] [:= [:% :foo 2] 0]] [:/ :foo 2]
:else 0]]]
:from [:bar]})))
(is (= ["SELECT CASE WHEN foo < ? THEN ? WHEN (foo > ?) AND (MOD(foo, ?) = ?) THEN foo / ? ELSE ? END FROM bar"
0 -1 0 2 0 2 0]
(sql/format
{:select [[[:case
Expand Down
6 changes: 5 additions & 1 deletion test/honey/sql_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@

(deftest compare-expressions-test
(testing "Sequences should be fns when in value/comparison spots"
(is (= ["SELECT foo FROM bar WHERE (col1 MOD ?) = (col2 + ?)" 4 4]
(is (= ["SELECT foo FROM bar WHERE (col1 % ?) = (col2 + ?)" 4 4]
(format {:select [:foo]
:from [:bar]
:where [:= [:% :col1 4] [:+ :col2 4]]})))
(is (= ["SELECT foo FROM bar WHERE MOD(col1, ?) = (col2 + ?)" 4 4]
(format {:select [:foo]
:from [:bar]
:where [:= [:mod :col1 4] [:+ :col2 4]]}))))
Expand Down

0 comments on commit 230cc46

Please sign in to comment.