diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 0c10921..3a48576 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -16,7 +16,7 @@ (declare clause-format) (def ^:private default-clause-order "The (default) order for known clauses. Can have items added and removed." - [:with :with-recursive :intersect :union :union-all :except :except-all + [:nest :with :with-recursive :intersect :union :union-all :except :except-all :select :insert-into :update :delete :delete-from :truncate :columns :composite :set :from :join :left-join :right-join :inner-join :outer-join :full-join @@ -361,7 +361,8 @@ (def ^:private clause-format "The (default) behavior for each known clause. Can also have items added and removed." - (atom {:with #'format-with + (atom {:nest (fn [_ x] (format-expr x)) + :with #'format-with :with-recursive #'format-with :intersect #'format-on-set-op :union #'format-on-set-op @@ -516,8 +517,11 @@ (into params-b)))) :cast (fn [_ [x type]] - (let [[sql & params] (format-expr x)] - (into [(str "CAST(" sql " AS " (sql-kw type) ")")] params))) + (let [[sql & params] (format-expr x) + [sql' & params'] (format-expr type)] + (-> [(str "CAST(" sql " AS " sql' ")")] + (into params) + (into params')))) :default (fn [_ []] ["DEFAULT"]) @@ -528,6 +532,9 @@ (fn [_ [n units]] (let [[sql & params] (format-expr n)] (into [(str "INTERVAL " sql " " (sql-kw units))] params))) + :nest + (fn [_ [x]] + (format-expr x {:nested? true})) :not (fn [_ [x]] (let [[sql & params] (format-expr x)] diff --git a/src/honey/sql/helpers.cljc b/src/honey/sql/helpers.cljc index c78ed1a..8986639 100644 --- a/src/honey/sql/helpers.cljc +++ b/src/honey/sql/helpers.cljc @@ -26,6 +26,7 @@ (helper-merge data k args)) (helper-merge {} k args))) +(defn nest [& args] (generic :nest args)) (defn with [& args] (generic :with args)) (defn with-recursive [& args] (generic :with-recursive args)) (defn intersect [& args] (generic :intersect args))