Fixes #257 by adding CROSS JOIN
This commit is contained in:
parent
919ffb3c4b
commit
b3baa094c2
6 changed files with 36 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
## 1.0.next in progress
|
## 1.0.next in progress
|
||||||
|
|
||||||
* Fix #259 so column names are always unqualified in inserts. (@jrdoane)
|
* Fix #259 so column names are always unqualified in inserts. (@jrdoane)
|
||||||
|
* Fix #257 by adding support for `cross-join` / `merge-cross-join` / `:cross-join`. (@dcj)
|
||||||
* Switch dev/test pipeline to use CLI/`deps.edn` instead of Leiningen. Also add CI vi both CircleCI and GitHub Actions.
|
* Switch dev/test pipeline to use CLI/`deps.edn` instead of Leiningen. Also add CI vi both CircleCI and GitHub Actions.
|
||||||
* Remove macrovich dependency as this is no longer needed with modern ClojureScript.
|
* Remove macrovich dependency as this is no longer needed with modern ClojureScript.
|
||||||
* Add mention of `next.jdbc` everywhere `clojure.java.jdbc` was mentioned.
|
* Add mention of `next.jdbc` everywhere `clojure.java.jdbc` was mentioned.
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@
|
||||||
:left-join, :merge-left-join
|
:left-join, :merge-left-join
|
||||||
:right-join, :merge-right-join
|
:right-join, :merge-right-join
|
||||||
:full-join, :merge-full-join
|
:full-join, :merge-full-join
|
||||||
|
:cross-join, :merge-cross-join
|
||||||
:where, :merge-where
|
:where, :merge-where
|
||||||
:group-by, :merge-group-by
|
:group-by, :merge-group-by
|
||||||
:having, :merge-having
|
:having, :merge-having
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,7 @@
|
||||||
:left-join 130
|
:left-join 130
|
||||||
:right-join 140
|
:right-join 140
|
||||||
:full-join 150
|
:full-join 150
|
||||||
|
:cross-join 152
|
||||||
:set 155
|
:set 155
|
||||||
:set1 156 ; high-priority set clause (synonym for :set)
|
:set1 156 ; high-priority set clause (synonym for :set)
|
||||||
:where 160
|
:where 160
|
||||||
|
|
@ -567,6 +568,9 @@
|
||||||
(space-join (map #(apply format-join :full %)
|
(space-join (map #(apply format-join :full %)
|
||||||
(partition 2 join-groups))))
|
(partition 2 join-groups))))
|
||||||
|
|
||||||
|
(defmethod format-clause :cross-join [[_ join-groups] _]
|
||||||
|
(space-join (map #(format-join :cross % nil) join-groups)))
|
||||||
|
|
||||||
(defmethod format-clause :group-by [[_ fields] _]
|
(defmethod format-clause :group-by [[_ fields] _]
|
||||||
(str "GROUP BY " (comma-join (map to-sql fields))))
|
(str "GROUP BY " (comma-join (map to-sql fields))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,12 @@
|
||||||
(defhelper merge-full-join [m clauses]
|
(defhelper merge-full-join [m clauses]
|
||||||
(update-in m [:full-join] concat clauses))
|
(update-in m [:full-join] concat clauses))
|
||||||
|
|
||||||
|
(defhelper cross-join [m clauses]
|
||||||
|
(assoc m :cross-join clauses))
|
||||||
|
|
||||||
|
(defhelper merge-cross-join [m clauses]
|
||||||
|
(update-in m [:cross-join] concat clauses))
|
||||||
|
|
||||||
(defmethod build-clause :group-by [_ m fields]
|
(defmethod build-clause :group-by [_ m fields]
|
||||||
(assoc m :group-by (collify fields)))
|
(assoc m :group-by (collify fields)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
:cljs [cljs.test :refer-macros]) [deftest testing is]]
|
:cljs [cljs.test :refer-macros]) [deftest testing is]]
|
||||||
[honeysql.core :as sql]
|
[honeysql.core :as sql]
|
||||||
[honeysql.helpers :refer [select modifiers from join left-join
|
[honeysql.helpers :refer [select modifiers from join left-join
|
||||||
right-join full-join where group having
|
right-join full-join cross-join
|
||||||
|
where group having
|
||||||
order-by limit offset values columns
|
order-by limit offset values columns
|
||||||
insert-into with merge-where]]
|
insert-into with merge-where]]
|
||||||
honeysql.format-test))
|
honeysql.format-test))
|
||||||
|
|
@ -254,4 +255,16 @@
|
||||||
(where nil nil nil nil)
|
(where nil nil nil nil)
|
||||||
sql/format)))))
|
sql/format)))))
|
||||||
|
|
||||||
|
(deftest cross-join-test
|
||||||
|
(is (= ["SELECT * FROM foo CROSS JOIN bar"]
|
||||||
|
(-> (select :*)
|
||||||
|
(from :foo)
|
||||||
|
(cross-join :bar)
|
||||||
|
sql/format)))
|
||||||
|
(is (= ["SELECT * FROM foo f CROSS JOIN bar b"]
|
||||||
|
(-> (select :*)
|
||||||
|
(from [:foo :f])
|
||||||
|
(cross-join [:bar :b])
|
||||||
|
sql/format))))
|
||||||
|
|
||||||
#?(:cljs (cljs.test/run-all-tests))
|
#?(:cljs (cljs.test/run-all-tests))
|
||||||
|
|
|
||||||
|
|
@ -310,3 +310,13 @@
|
||||||
(format {:select [:foo]
|
(format {:select [:foo]
|
||||||
:from [:bar]
|
:from [:bar]
|
||||||
:join [[:table :t] true]}))))
|
:join [[:table :t] true]}))))
|
||||||
|
|
||||||
|
(deftest cross-join-test
|
||||||
|
(is (= ["SELECT * FROM foo CROSS JOIN bar"]
|
||||||
|
(format {:select [:*]
|
||||||
|
:from [:foo]
|
||||||
|
:cross-join [:bar]})))
|
||||||
|
(is (= ["SELECT * FROM foo f CROSS JOIN bar b"]
|
||||||
|
(format {:select [:*]
|
||||||
|
:from [[:foo :f]]
|
||||||
|
:cross-join [[:bar :b]]}))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue