summaryrefslogtreecommitdiff
path: root/src/clojure_sql
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-09-30 10:21:00 +1000
committerCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-09-30 10:21:00 +1000
commit22784e9846a645f62b2a31b320c802a8140a2ad0 (patch)
tree48080edbc2bbadd26784248b15072dfb0cc51d2a /src/clojure_sql
parent46be6f6f99212b828585ead196b042ba981daaff (diff)
Fix up union/intersection operations
Previously the union/intersection operations didn't work when you tried to select/project/sort/drop/whatever on them. Now they just automatically introduce a subquery, which means that they can be used in other operations automatically. (There is a potential for a minor decrease in query speed, but I think it's worthwhile to maintain the abstraction.)
Diffstat (limited to 'src/clojure_sql')
-rw-r--r--src/clojure_sql/dsl.clj22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/clojure_sql/dsl.clj b/src/clojure_sql/dsl.clj
index 015dfda..16bc2e5 100644
--- a/src/clojure_sql/dsl.clj
+++ b/src/clojure_sql/dsl.clj
@@ -370,19 +370,21 @@
(apply = (map (comp set keys :fields) queries))))
(defn union
- "Combine the results of two queries"
+ "Combine the results of two queries.
+
+ Will always introduce a subquery."
[& queries]
{:pre [(apply union-compatible? queries)]}
- (assoc (q/->Query)
- :set-operation :union
- :queries queries
- :fields (zipmap (keys (:fields (first queries))) (repeat nil))))
+ (convert-to-subquery (q/map->Query {:set-operation :union
+ :queries queries
+ :fields (zipmap (keys (:fields (first queries))) (repeat nil))})))
(defn intersection
- "Take the common rows in two queries"
+ "Take the common rows in two queries.
+
+ Will always introduce a subquery."
[& queries]
{:pre [(apply union-compatible? queries)]}
- (assoc (q/->Query)
- :set-operation :intersect
- :queries queries
- :fields (zipmap (keys (:fields (first queries))) (repeat nil))))
+ (convert-to-subquery (q/map->Query {:set-operation :intersect
+ :queries queries
+ :fields (zipmap (keys (:fields (first queries))) (repeat nil))})))