This commit is contained in:
Alexander Hudek 2015-03-04 03:14:28 +00:00
commit 7042149340
2 changed files with 29 additions and 1 deletions

View file

@ -156,7 +156,7 @@
(def clause-order
"Determines the order that clauses will be placed within generated SQL"
[: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])
@ -386,3 +386,19 @@
(defmethod format-clause :delete-from [[_ table] _]
(str "DELETE FROM " (to-sql table)))
(defn cte->sql
[[cte-name query]]
(str (to-sql cte-name) " AS " (to-sql query)))
(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 format-clause :union [[_ maps] _]
(string/join " UNION " (map to-sql maps)))
(defmethod format-clause :union-all [[_ maps] _]
(string/join " UNION ALL " (map to-sql maps)))

View file

@ -213,3 +213,15 @@
(defn delete-from
([table] (delete-from nil table))
([m table] (build-clause :delete-from m table)))
(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))