Merge 404c0b7272 into f63de95e14
This commit is contained in:
commit
7042149340
2 changed files with 29 additions and 1 deletions
|
|
@ -156,7 +156,7 @@
|
||||||
|
|
||||||
(def clause-order
|
(def clause-order
|
||||||
"Determines the order that clauses will be placed within generated SQL"
|
"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
|
:left-join :right-join :where :group-by :having :order-by :limit :offset
|
||||||
:values :query-values])
|
:values :query-values])
|
||||||
|
|
||||||
|
|
@ -386,3 +386,19 @@
|
||||||
|
|
||||||
(defmethod format-clause :delete-from [[_ table] _]
|
(defmethod format-clause :delete-from [[_ table] _]
|
||||||
(str "DELETE FROM " (to-sql 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)))
|
||||||
|
|
@ -213,3 +213,15 @@
|
||||||
(defn delete-from
|
(defn delete-from
|
||||||
([table] (delete-from nil table))
|
([table] (delete-from nil table))
|
||||||
([m table] (build-clause :delete-from m 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