diff --git a/src/honeysql/format.cljc b/src/honeysql/format.cljc index b952ce2..1d6521d 100644 --- a/src/honeysql/format.cljc +++ b/src/honeysql/format.cljc @@ -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 %) diff --git a/test/honeysql/core_test.cljc b/test/honeysql/core_test.cljc index 60b1ec5..c7fc6af 100644 --- a/test/honeysql/core_test.cljc +++ b/test/honeysql/core_test.cljc @@ -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 :*)