Merge 0ce17ccfcf into 88bc556578
This commit is contained in:
commit
5704b9c561
2 changed files with 74 additions and 31 deletions
|
|
@ -156,9 +156,9 @@
|
||||||
|
|
||||||
(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
|
[:select :insert-into :update :delete :delete-from :columns :set :from :join
|
||||||
:left-join :right-join :where :group-by :having :order-by :limit :offset
|
:left-join :right-join :where :aggregate :over :partition-by :group-by :having
|
||||||
:values :query-values])
|
:order-by :limit :offset :values :query-values])
|
||||||
|
|
||||||
(def known-clauses (set clause-order))
|
(def known-clauses (set clause-order))
|
||||||
|
|
||||||
|
|
@ -386,3 +386,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 :delete [[_ table] _]
|
||||||
|
(str "DELETE " (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))))
|
||||||
|
|
@ -209,3 +209,33 @@
|
||||||
(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 :delete [_ m table]
|
||||||
|
(assoc m :delete table))
|
||||||
|
|
||||||
|
(defn delete
|
||||||
|
([table] (delete nil table))
|
||||||
|
([m table] (build-clause :delete 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 (first 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)))
|
||||||
Loading…
Reference in a new issue