summaryrefslogtreecommitdiff
path: root/src/clojure_sql/dsl.clj
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-06-16 01:20:35 +1000
committerCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-06-16 01:20:35 +1000
commit233e9bd34462d3b02a7a3af148994f9a013b34ab (patch)
tree07c19fe366ccd61823d8124370ea5f3c93b14679 /src/clojure_sql/dsl.clj
parent82aa383a9c0f9d9d921135a10e919125d9115924 (diff)
Fix expression processing in the DSL, notably on vectors
Diffstat (limited to 'src/clojure_sql/dsl.clj')
-rw-r--r--src/clojure_sql/dsl.clj23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/clojure_sql/dsl.clj b/src/clojure_sql/dsl.clj
index 5cf7f59..a75b8f7 100644
--- a/src/clojure_sql/dsl.clj
+++ b/src/clojure_sql/dsl.clj
@@ -46,9 +46,9 @@
[table field]
(ambiguous-error field)))))
-(defn ^:private resolve-fields [table aliases expression]
- (cond ;;(vector? expression) (mapv (partial resolve-fields table aliases) expression)
- (sequential? expression) (map (partial resolve-fields table aliases) expression)
+(defn ^:private process-expression [table aliases expression]
+ (cond (vector? expression) (list 'quote expression)
+ (sequential? expression) (map (partial process-expression table aliases) expression)
(keyword? expression) (resolve-field table aliases expression)
:else expression))
@@ -56,7 +56,7 @@
(let [table (if (= (count (:tables query)) 1)
(-> query :tables first key))
alias-lookup (or (:fields query) {})
- get-real-name #(resolve-fields table alias-lookup %)]
+ get-real-name #(resolve-field table alias-lookup %)]
(assoc query
:fields (->> (for [[old-name new-name] (if (map? fields)
fields
@@ -126,7 +126,7 @@
{:left left
:right right
:common-fields common-fields}))
- :else (resolve-fields nil merged-fields on))
+ :else (process-expression nil merged-fields on))
type (or type
(if join-condition :inner)
:cross)]
@@ -144,7 +144,7 @@
(let [table-name (if (= (count (:tables query)) 1)
(-> query :tables first key))
old-where (:where query)
- resolved-expression (resolve-fields table-name (:fields query) expression)
+ resolved-expression (process-expression table-name (:fields query) expression)
new-where (combine-wheres old-where resolved-expression)]
(assoc query :where new-where)))
@@ -162,17 +162,6 @@
(let [id 10]
- (->> (-> (table :x)
- (project [:x])
- (select `(and (in :x [1 2 3 :y])
- (= :x ~id)))
- (join (-> (table :y)
- (project [:y]))
- :on `(= :x :y))
- (join (-> (table :z)
- (project [:x])))
- (sort-by [:x]))
- (into {}))
(-> (table :x)
(project [:x])
(select `(and (in :x [1 2 3 :y])