Merge in Pull Request #34, Support basic common table expressions.
This commit is contained in:
parent
6d0ff344b9
commit
11e6d1c017
2 changed files with 31 additions and 1 deletions
|
|
@ -161,7 +161,9 @@
|
|||
|
||||
(def default-clause-priorities
|
||||
"Determines the order that clauses will be placed within generated SQL"
|
||||
{:select 50
|
||||
{:with 30
|
||||
:with-recursive 40
|
||||
:select 50
|
||||
:insert-into 60
|
||||
:update 70
|
||||
:delete-from 80
|
||||
|
|
@ -416,3 +418,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)))
|
||||
|
|
|
|||
|
|
@ -219,3 +219,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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue