diff --git a/src/honeysql/format.cljc b/src/honeysql/format.cljc index bb89012..234fe34 100644 --- a/src/honeysql/format.cljc +++ b/src/honeysql/format.cljc @@ -216,6 +216,7 @@ :union-all 45 :select 50 :insert-into 60 + :replace-into 60 :update 70 :delete 75 :delete-from 80 @@ -594,6 +595,15 @@ (to-sql (second table)))) (str "INSERT INTO " (to-sql table)))) +(defmethod format-clause :replace-into [[_ table] _] + (if (and (sequential? table) (sequential? (first table))) + (str "REPLACE INTO " + (to-sql (ffirst table)) + " (" (comma-join (map to-sql (second (first table)))) ") " + (binding [*subquery?* false] + (to-sql (second table)))) + (str "REPLACE INTO " (to-sql table)))) + (defmethod format-clause :columns [[_ fields] _] (str "(" (comma-join (map to-sql fields)) ")")) diff --git a/src/honeysql/helpers.cljc b/src/honeysql/helpers.cljc index 9a9dced..75e2992 100644 --- a/src/honeysql/helpers.cljc +++ b/src/honeysql/helpers.cljc @@ -220,6 +220,13 @@ ([table] (insert-into nil table)) ([m table] (build-clause :insert-into m table))) +(defmethod build-clause :replace-into [_ m table] + (assoc m :replace-into table)) + +(defn replace-into + ([table] (replace-into nil table)) + ([m table] (build-clause :replace-into m table))) + (macros/usetime (defhelper columns [m fields] (assoc m :columns (collify fields))))