diff options
-rw-r--r-- | src/clojure_sql/core.clj | 15 |
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]) |