This commit is contained in:
Michael Blume 2015-10-14 11:43:04 +00:00
commit b19d2df03c
2 changed files with 38 additions and 2 deletions

View file

@ -187,6 +187,9 @@
:right-join 140 :right-join 140
:full-join 150 :full-join 150
:where 160 :where 160
:aggregate 162
:over 165
:partition 167
:group-by 170 :group-by 170
:having 180 :having 180
:order-by 190 :order-by 190
@ -512,6 +515,16 @@
(defmethod format-clause :delete-from [[_ table] _] (defmethod format-clause :delete-from [[_ table] _]
(str "DELETE FROM " (to-sql table))) (str "DELETE FROM " (to-sql table)))
(defmethod format-clause :over [[_ part-clause] _]
(str "OVER " (to-sql part-clause)))
(defmethod format-clause :aggregate [[_ aggregate-fn] _]
(str (to-sql aggregate-fn)))
(defmethod format-clause :partition-by [[_ fields] _]
(str "PARTITION BY "
(comma-join (map to-sql fields))))
(defn cte->sql (defn cte->sql
[[cte-name query]] [[cte-name query]]
(str (to-sql cte-name) " AS " (to-sql query))) (str (to-sql cte-name) " AS " (to-sql query)))

View file

@ -225,6 +225,29 @@
([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 :over [_ m table]
(assoc m :over table))
(defn over
([part-clause] (over nil part-clause))
([m part-clause] (build-clause :over m part-clause)))
(defhelper merge-over [m fields]
(update-in m [:over] (partial apply merge) (collify fields)))
(defhelper aggregate [m aggregate-fn]
(assoc m :aggregate aggregate-fn))
(defn aggregate
([table] (aggregate nil table))
([m table] (build-clause :aggregate m table)))
(defhelper spartition-by [m fields]
(assoc m :partition-by (collify fields)))
(defhelper merge-partition-by [m fields]
(update-in m [:partition-by] concat (collify fields)))
(defmethod build-clause :with [_ m ctes] (defmethod build-clause :with [_ m ctes]
(assoc m :with ctes)) (assoc m :with ctes))