Bug fixes for JOINs
This commit is contained in:
parent
b547a94003
commit
8025d3520d
1 changed files with 13 additions and 7 deletions
|
|
@ -256,13 +256,19 @@
|
||||||
[(str (sql-kw k) " " (format-entity-alias table))])
|
[(str (sql-kw k) " " (format-entity-alias table))])
|
||||||
[(str (sql-kw k) " " (format-entity-alias table))]))
|
[(str (sql-kw k) " " (format-entity-alias table))]))
|
||||||
|
|
||||||
(defn- format-join [k [j e]]
|
(defn- format-join [k clauses]
|
||||||
(let [[sql & params] (format-expr e)]
|
(let [[sqls params]
|
||||||
;; for backward compatibility, treat plain JOIN as INNER JOIN:
|
(reduce (fn [[sqls params] [j e]]
|
||||||
(into [(str (sql-kw (if (= :join k) :inner-join k)) " "
|
;; TODO: join using!
|
||||||
(format-entity-alias j) " ON "
|
(let [[sql & params'] (when e (format-expr e))]
|
||||||
sql)]
|
[(cond-> (conj sqls
|
||||||
params)))
|
(sql-kw (if (= :join k) :inner-join k))
|
||||||
|
(format-entity-alias j))
|
||||||
|
e (conj "ON" sql))
|
||||||
|
(into params params')]))
|
||||||
|
[[] []]
|
||||||
|
(partition 2 clauses))]
|
||||||
|
(into [(str/join " " sqls)] params)))
|
||||||
|
|
||||||
(defn- format-on-expr [k e]
|
(defn- format-on-expr [k e]
|
||||||
(if (or (not (sequential? e)) (seq e))
|
(if (or (not (sequential? e)) (seq e))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue