Merge pull request #201 from vincent-dm/master
adds support for JOIN ... USING (...) syntax (#188)
This commit is contained in:
commit
43e94bf497
2 changed files with 15 additions and 4 deletions
|
|
@ -489,10 +489,13 @@
|
|||
(str "WHERE " (format-predicate* pred)))
|
||||
|
||||
(defn format-join [type table pred]
|
||||
(cond-> (str (when type
|
||||
(str (string/upper-case (name type)) " "))
|
||||
"JOIN " (to-sql table))
|
||||
pred (str " ON " (format-predicate* pred))))
|
||||
(str (when type
|
||||
(str (string/upper-case (name type)) " "))
|
||||
"JOIN " (to-sql table)
|
||||
(when pred
|
||||
(if (= :using (first pred))
|
||||
(str " USING (" (->> pred rest (map quote-identifier) comma-join) ")")
|
||||
(str " ON " (format-predicate* pred))))))
|
||||
|
||||
(defmethod format-clause :join [[_ join-groups] _]
|
||||
(space-join (map #(apply format-join :inner %)
|
||||
|
|
|
|||
|
|
@ -192,6 +192,14 @@
|
|||
(join :x [:= :foo.id :x.id] :y nil)
|
||||
sql/format)))))
|
||||
|
||||
(deftest join-using-test
|
||||
(testing "nil join"
|
||||
(is (= ["SELECT * FROM foo INNER JOIN x USING (id) INNER JOIN y USING (foo, bar)"]
|
||||
(-> (select :*)
|
||||
(from :foo)
|
||||
(join :x [:using :id] :y [:using :foo :bar])
|
||||
sql/format)))))
|
||||
|
||||
(deftest inline-test
|
||||
(is (= ["SELECT * FROM foo WHERE id = 5"]
|
||||
(-> (select :*)
|
||||
|
|
|
|||
Loading…
Reference in a new issue