Skip to content

Commit

Permalink
Merge pull request #8 from ianbishop/master
Browse files Browse the repository at this point in the history
Add support for union
  • Loading branch information
icylisper authored Feb 26, 2019
2 parents 9c5ad3b + 97429ea commit fc38fba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/sqly/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
(remove nil?)
(str/join " "))))

(def-sql-op union [{:keys [union]}]
(->> union
(map emit-select)
(str/join " union ")))

(defn emit-columns [columns]
(when columns
(->> columns
Expand Down
15 changes: 15 additions & 0 deletions test/sqly/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,18 @@
(deftest canonicalize-alpha-numeric-idents
(is (= "a_v3" (sql/ident-str :a-v3)))
(is (= "foo/a_v3" (sql/ident-str :foo/a-v3))))

(deftest union-test
(is (= (canon
["select related_id,type,description from a_events"
" where related_id = '{{related-id}}'"
" union "
"select related_id,type,description from b_events"
" where related_id = '{{related-id}}'"])
(sql/sql
'{:union [{:select [:related_id :type :description]
:from :a_events
:where {:related_id "{{related-id}}"}}
{:select [:related_id :type :description]
:from :b_events
:where {:related_id "{{related-id}}"}}]}))))

0 comments on commit fc38fba

Please sign in to comment.