diff --git a/CHANGELOG.md b/CHANGELOG.md index 447abd5..93d1689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 2.4.next in progress + * Fix [#484](https://github.com/seancorfield/honeysql/issues/484) by adding `TABLE` to `TRUNCATE`. * Fix [#483](https://github.com/seancorfield/honeysql/issues/483) by adding a function-like `:join` syntax to produce nested `JOIN` expressions. * 2.4.1011 -- 2023-03-23 * Address [#481](https://github.com/seancorfield/honeysql/issues/481) by adding more examples around `:do-update-set`. diff --git a/README.md b/README.md index 97d0427..0835380 100644 --- a/README.md +++ b/README.md @@ -518,11 +518,11 @@ If you want to delete everything from a table, you can use `truncate`: ```clojure (-> (truncate :films) (sql/format)) -=> ["TRUNCATE films"] +=> ["TRUNCATE TABLE films"] ;; or as pure data DSL: (-> {:truncate :films} (sql/format)) -=> ["TRUNCATE films"] +=> ["TRUNCATE TABLE films"] ``` ### Set operations diff --git a/doc/clause-reference.md b/doc/clause-reference.md index 3a8f3e4..49e5544 100644 --- a/doc/clause-reference.md +++ b/doc/clause-reference.md @@ -645,9 +645,9 @@ or a table name followed by various options: ```clojure user=> (sql/format '{truncate transport}) -["TRUNCATE transport"] +["TRUNCATE TABLE transport"] user=> (sql/format '{truncate (transport restart identity)}) -["TRUNCATE transport RESTART IDENTITY"] +["TRUNCATE TABLE transport RESTART IDENTITY"] ``` ## columns diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 3056769..68cda52 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -998,12 +998,12 @@ (when opts (format-ddl-options opts context))))) -(defn- format-truncate [k xs] +(defn- format-truncate [_ xs] (let [[table & options] (ensure-sequential xs) [pre table ine options] (destructure-ddl-item [table options] "truncate")] (when (seq pre) (throw (ex-info "TRUNCATE syntax error" {:unexpected pre}))) (when (seq ine) (throw (ex-info "TRUNCATE syntax error" {:unexpected ine}))) - [(str/join " " (cond-> [(sql-kw k) table] + [(str/join " " (cond-> ["TRUNCATE TABLE" table] (seq options) (conj options)))])) diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index a0b3d16..2e8fa0d 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -562,10 +562,10 @@ (format))))) (deftest truncate-test - (is (= ["TRUNCATE `foo`"] + (is (= ["TRUNCATE TABLE `foo`"] (-> {:truncate :foo} (format {:dialect :mysql})))) - (is (= ["TRUNCATE `foo` CONTINUE IDENTITY"] + (is (= ["TRUNCATE TABLE `foo` CONTINUE IDENTITY"] (-> {:truncate [:foo :continue :identity]} (format {:dialect :mysql})))))