summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clojure_sql/core.clj18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj
index 0032bb6..2ff64e0 100644
--- a/src/clojure_sql/core.clj
+++ b/src/clojure_sql/core.clj
@@ -184,19 +184,21 @@
{:table arg}
{:table {arg arg}})))
+(defn ambiguous-error [field]
+ (throw (ex-info (str "Ambiguous field " field)
+ {:field field})))
+
(defn project [query fields]
(let [table (if-not (:joins query)
(-> query :table first val))
- alias-lookup (->> query :fields
- (map (comp vec reverse))
- (into {}))
+ alias-lookup (u/flip-map (:fields query))
original-name (fn [field]
(if (vector? field)
field
(or (get alias-lookup field nil)
(if table
- [table field]
- (throw (RuntimeException. (str "Ambiguous field " field " cannot be resolved")))))))]
+ [table field]
+ (ambiguous-error field)))))]
(assoc query
:fields (->> (for [[key val] (if (map? fields)
fields
@@ -206,9 +208,7 @@
(defn rename [query field-renames]
{:pre [(map? field-renames)]}
- (let [alias-lookup (->> query :fields
- (map (comp vec reverse))
- (into {}))
+ (let [alias-lookup (u/flip-map (:fields query))
original-name (fn [field]
(cond (vector? field) field
(contains? alias-lookup field) (get alias-lookup field)
@@ -227,7 +227,7 @@
(or (field-alias-lookup field)
(if table
[table field]
- (throw (RuntimeException. (str "Ambiguous field " field " cannot be resolved")))))))
+ (ambiguous-error field)))))
(defn ^:private resolve-fields [table aliases expression]
(clojure.walk/postwalk (fn [expr]