From 8979e938f36763ed6262144181e44d25c2a92449 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Thu, 23 Dec 2021 13:32:47 -0800 Subject: [PATCH] fixes #374 --- .github/workflows/test-and-release.yml | 2 +- .github/workflows/test-and-snapshot.yml | 4 ++-- .github/workflows/test.yml | 2 +- CHANGELOG.md | 3 ++- deps.edn | 2 +- doc/operator-reference.md | 28 ++++++++++++++++++++++--- src/honey/sql.cljc | 4 +--- test/honey/sql_test.cljc | 24 ++++++++++++++++++++- 8 files changed, 56 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index fb0f793..a5c113b 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Clojure uses: DeLaGuardo/setup-clojure@master with: - tools-deps: '1.10.3.1040' + tools-deps: '1.10.3.1053' - name: Cache All The Things uses: actions/cache@v2 with: diff --git a/.github/workflows/test-and-snapshot.yml b/.github/workflows/test-and-snapshot.yml index d74cf7c..b04ee1a 100644 --- a/.github/workflows/test-and-snapshot.yml +++ b/.github/workflows/test-and-snapshot.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Clojure uses: DeLaGuardo/setup-clojure@master with: - tools-deps: '1.10.3.1040' + tools-deps: '1.10.3.1053' - name: Cache All The Things uses: actions/cache@v2 with: @@ -49,7 +49,7 @@ jobs: - name: Clojure CLI uses: DeLaGuardo/setup-clojure@master with: - tools-deps: '1.10.3.1040' + tools-deps: '1.10.3.1053' - name: Cache All The Things uses: actions/cache@v2 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 22a0d08..3825c90 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: - name: Clojure CLI uses: DeLaGuardo/setup-clojure@master with: - tools-deps: '1.10.3.1040' + tools-deps: '1.10.3.1053' - name: Cache All The Things uses: actions/cache@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3666d..dc3a532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ * 2.1.next in progress * Fix #375 for `:nest` statement. + * Fix #374 by removing aliasing of `:is` / `:is-not` -- this changes the behavior of `[:is-not :col true/false]` to be _correct_ and _include `NULL` values_. Using `:is` / `:is-not` with values that are not Boolean and not `nil` will produce invalid SQL. * Update test dependencies. - * Update `build-clj` to v0.6.1. + * Update `build-clj` to v0.6.5. * 2.1.833 -- 2021-12-03 * Fix #372 by merging `:select-distinct-on` differently. diff --git a/deps.edn b/deps.edn index d365bdd..1fec44a 100644 --- a/deps.edn +++ b/deps.edn @@ -4,7 +4,7 @@ :aliases {;; for help: clojure -A:deps -T:build help/doc :build {:deps {io.github.seancorfield/build-clj - {:git/tag "v0.6.2" :git/sha "97c275a"}} + {:git/tag "v0.6.5" :git/sha "972031a"}} :ns-default build} ;; versions to test against: diff --git a/doc/operator-reference.md b/doc/operator-reference.md index 36e4a58..d4e75e4 100644 --- a/doc/operator-reference.md +++ b/doc/operator-reference.md @@ -37,9 +37,31 @@ can simply evaluate to `nil` instead). Binary comparison operators. These expect exactly two arguments. -The following aliases are also supported: -* `is` -- an alias for `=` -* `is-not`, `not=`, `!=` -- aliases for `<>` +`not=` and `!=` are accepted as aliases for `<>`. + +## is, is-not + +Binary predicates for `NULL` and Boolean values: + +```clojure +{... + :where [:is :id nil] + ...} +;;=> ["...WHERE col IS NULL..."] +{... + :where [:is-not :id nil] + ...} +;;=> ["...WHERE col IS NOT NULL..."] +{... + :where [:is :col true] + ...} +;;=> ["...WHERE col IS TRUE..."] +{... + ;; unlike [:<> :col false], the following will include NULLs: + :where [:is-not :col false] + ...} +;;=> ["...WHERE col IS NOT FALSE..."] +``` ## mod, xor, + - * / % | & ^ diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 64cc91d..c3d1eb9 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -988,9 +988,7 @@ (def ^:private infix-aliases "Provided for backward compatibility with earlier HoneySQL versions." - {:is := - :is-not :<> - :not= :<> + {:not= :<> :!= :<> :regex :regexp}) diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 17d2a27..ab8c538 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -14,17 +14,39 @@ {:dialect :mysql})))) (deftest expr-tests + ;; special-cased = nil: (is (= ["id IS NULL"] (sut/format-expr [:= :id nil]))) (is (= ["id IS NULL"] (sut/format-expr [:is :id nil]))) + (is (= ["id = TRUE"] + (sut/format-expr [:= :id true]))) + (is (= ["id IS TRUE"] + (sut/format-expr [:is :id true]))) + (is (= ["id <> TRUE"] + (sut/format-expr [:<> :id true]))) + (is (= ["id IS NOT TRUE"] + (sut/format-expr [:is-not :id true]))) + (is (= ["id = FALSE"] + (sut/format-expr [:= :id false]))) + (is (= ["id IS FALSE"] + (sut/format-expr [:is :id false]))) + (is (= ["id <> FALSE"] + (sut/format-expr [:<> :id false]))) + (is (= ["id IS NOT FALSE"] + (sut/format-expr [:is-not :id false]))) + ;; special-cased <> nil: (is (= ["id IS NOT NULL"] (sut/format-expr [:<> :id nil]))) + ;; legacy alias: (is (= ["id IS NOT NULL"] (sut/format-expr [:!= :id nil]))) + ;; legacy alias: + (is (= ["id IS NOT NULL"] + (sut/format-expr [:not= :id nil]))) (is (= ["id IS NOT NULL"] (sut/format-expr [:is-not :id nil]))) - ;; degenerate cases: + ;; degenerate (special) cases: (is (= ["NULL IS NULL"] (sut/format-expr [:= nil nil]))) (is (= ["NULL IS NOT NULL"]