diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa2271..d48d9c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/doc/extending-honeysql.md b/doc/extending-honeysql.md index efdf849..6011b8d 100644 --- a/doc/extending-honeysql.md +++ b/doc/extending-honeysql.md @@ -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. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 9362fc8..0f28423 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -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" diff --git a/test/honey/sql/helpers_test.cljc b/test/honey/sql/helpers_test.cljc index 932be21..db6b89a 100644 --- a/test/honey/sql/helpers_test.cljc +++ b/test/honey/sql/helpers_test.cljc @@ -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 diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 6e579a2..b16eefb 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -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]]}))))