summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clojure_sql/compiler.clj15
-rw-r--r--src/clojure_sql/dsl.clj9
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]])))