From cbb7929c3660cc49a3829555827ec0a9af60413d Mon Sep 17 00:00:00 2001 From: "Alexander K. Hudek" Date: Tue, 20 Jan 2015 17:23:24 -0500 Subject: [PATCH] Added recursive queries and unions. --- src/honeysql/format.clj | 11 ++++++++++- src/honeysql/helpers.clj | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index f42bb32..627753a 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -156,7 +156,7 @@ (def clause-order "Determines the order that clauses will be placed within generated SQL" - [:with :select :insert-into :update :delete-from :columns :set :from :join + [:with :with-recursive :select :insert-into :update :delete-from :columns :set :from :join :left-join :right-join :where :group-by :having :order-by :limit :offset :values :query-values]) @@ -393,3 +393,12 @@ (defmethod format-clause :with [[_ ctes] _] (str "WITH " (comma-join (map cte->sql ctes)))) + +(defmethod format-clause :with-recursive [[_ ctes] _] + (str "WITH RECURSIVE " (comma-join (map cte->sql ctes)))) + +(defmethod fmt/format-clause :union [[_ maps] _] + (string/join " UNION " (map fmt/to-sql maps))) + +(defmethod fmt/format-clause :union-all [[_ maps] _] + (string/join " UNION ALL " (map fmt/to-sql maps))) \ No newline at end of file diff --git a/src/honeysql/helpers.clj b/src/honeysql/helpers.clj index 41d4b8b..2aa9c63 100644 --- a/src/honeysql/helpers.clj +++ b/src/honeysql/helpers.clj @@ -215,3 +215,12 @@ (defmethod build-clause :with [_ m ctes] (assoc m :with ctes)) + +(defmethod build-clause :with-recursive [_ m ctes] + (assoc m :with-recursive ctes)) + +(defmethod build-clause :union [_ m maps] + (assoc m :union maps)) + +(defmethod build-clause :union-all [_ m maps] + (assoc m :union-all maps))