summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-05-15 11:01:18 +1000
committerCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-05-15 11:01:18 +1000
commit47ffb78fccb44d62db29971dcb6e6d750869e1a7 (patch)
treeda98e57c63d56d09cd05854f3cbffe20eea13007 /src
parent66914e32be56663950b08996ac076e11b1f56e61 (diff)
Change some error reporting stuff. Nothing major.
Diffstat (limited to 'src')
-rw-r--r--src/clojure_sql/core.clj15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj
index c829331..43e5089 100644
--- a/src/clojure_sql/core.clj
+++ b/src/clojure_sql/core.clj
@@ -184,9 +184,10 @@
{:table arg}
{:table {arg arg}})))
-(defn ambiguous-error [field]
- (throw (ex-info (str "Ambiguous field " field)
- {:field field})))
+(defn ambiguous-error [field & [query]]
+ (throw (ex-info (str "Ambiguous field " field " in query with more than one table")
+ {:field field
+ :query query})))
(defn project [query fields]
(let [table (if-not (:joins query)
@@ -198,7 +199,7 @@
(or (get alias-lookup field nil)
(if table
[table field]
- (ambiguous-error field)))))]
+ (ambiguous-error field query)))))]
(assoc query
:fields (->> (for [[key val] (if (map? fields)
fields
@@ -217,7 +218,7 @@
original-name (fn [field]
(cond (vector? field) field
(contains? alias-lookup field) (get alias-lookup field)
- :else (throw (ex-info (str "Invalid field in rename: " (pr-str field))
+ :else (throw (ex-info (str "Cannot rename field " (pr-str field) ". Field does not exist in query.")
{:field field
:query query
:renames field-renames})))
@@ -342,6 +343,10 @@
(rename {:id :name
:name :id})
deref)
+ (-> (table :users)
+ (project {:id :name
+ :name :id})
+ deref)
(-> (table :anotherStack)
(project [:anotherNumber])