diff options
author | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-06-16 01:26:31 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-06-16 01:26:31 +1000 |
commit | 4ab5ae273750c0d52ec72f103fe9165b52d2abb6 (patch) | |
tree | e44bea2b9bdbc117dc7530334b756e4b1574597b /src | |
parent | 233e9bd34462d3b02a7a3af148994f9a013b34ab (diff) |
Fix up some more join stuff, and a bit of sorting stuff.
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure_sql/compiler.clj | 15 | ||||
-rw-r--r-- | src/clojure_sql/dsl.clj | 9 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/clojure_sql/compiler.clj b/src/clojure_sql/compiler.clj index 0022256..6f940c0 100644 --- a/src/clojure_sql/compiler.clj +++ b/src/clojure_sql/compiler.clj @@ -118,6 +118,13 @@ ((p-lift string/join ", "))) (return "*"))) +(def ^:private join-type-names + {:inner "INNER" + :left "LEFT OUTER" + :right "RIGHT OUTER" + :outer "FULL OUTER" + :cross "CROSS"}) + (defmulti compile-tables (fn [db _ _] db)) (defmethod compile-tables :default [db join tables-map] (if (vector? join) @@ -128,10 +135,12 @@ (let [{:keys [left right type on]} join] ($str (return "(") (compile-tables db left tables-map) - (return (str " " (name type) " JOIN ")) + (return (str " " (get join-type-names type (name type)) " JOIN ")) (compile-tables db right tables-map) - (return " ON ") - (compile-expression db on) + (if on + ($str (return " ON ") + (compile-expression db on)) + (return "")) (return ")"))))) (defmulti compile-where (fn [db _] db)) diff --git a/src/clojure_sql/dsl.clj b/src/clojure_sql/dsl.clj index a75b8f7..6f01198 100644 --- a/src/clojure_sql/dsl.clj +++ b/src/clojure_sql/dsl.clj @@ -157,18 +157,19 @@ (assoc query :sort-by (for [field fields-seq] (if (vector? field) - (resolve-field table-name (:fields query) field) + [(resolve-field table-name (:fields query) (first field)) (second field)] [(resolve-field table-name (:fields query) field) :asc]))))) (let [id 10] - (-> (table :x) + (-> (table {:x :carlo-table}) (project [:x]) (select `(and (in :x [1 2 3 :y]) (= :x ~id))) (join (-> (table :y) (project [:y])) - :on `(= :x :y)) + :on `(= :x :y) + :type :left) (join (-> (table :z) (project [:x]))) - (sort-by [:x]))) + (sort-by [[:x :desc]]))) |