Merge pull request #201 from vincent-dm/master

adds support for JOIN ... USING (...) syntax (#188)
This commit is contained in:
Michael Blume 2018-04-12 23:39:59 -07:00 committed by GitHub
commit 43e94bf497
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -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 %)

View file

@ -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 :*)