Support basic common table expressions.
This commit is contained in:
parent
0c3f3d0403
commit
7fc3b371b0
2 changed files with 11 additions and 1 deletions
|
|
@ -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 :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,10 @@
|
|||
|
||||
(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))))
|
||||
|
|
|
|||
|
|
@ -212,3 +212,6 @@
|
|||
(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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue