fix #484 by adding TABLE to TRUNCAT
This commit is contained in:
parent
dffedb115e
commit
2efe05def2
5 changed files with 9 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
* 2.4.next in progress
|
* 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.
|
* 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
|
* 2.4.1011 -- 2023-03-23
|
||||||
* Address [#481](https://github.com/seancorfield/honeysql/issues/481) by adding more examples around `:do-update-set`.
|
* Address [#481](https://github.com/seancorfield/honeysql/issues/481) by adding more examples around `:do-update-set`.
|
||||||
|
|
|
||||||
|
|
@ -518,11 +518,11 @@ If you want to delete everything from a table, you can use `truncate`:
|
||||||
```clojure
|
```clojure
|
||||||
(-> (truncate :films)
|
(-> (truncate :films)
|
||||||
(sql/format))
|
(sql/format))
|
||||||
=> ["TRUNCATE films"]
|
=> ["TRUNCATE TABLE films"]
|
||||||
;; or as pure data DSL:
|
;; or as pure data DSL:
|
||||||
(-> {:truncate :films}
|
(-> {:truncate :films}
|
||||||
(sql/format))
|
(sql/format))
|
||||||
=> ["TRUNCATE films"]
|
=> ["TRUNCATE TABLE films"]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set operations
|
### Set operations
|
||||||
|
|
|
||||||
|
|
@ -645,9 +645,9 @@ or a table name followed by various options:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
user=> (sql/format '{truncate transport})
|
user=> (sql/format '{truncate transport})
|
||||||
["TRUNCATE transport"]
|
["TRUNCATE TABLE transport"]
|
||||||
user=> (sql/format '{truncate (transport restart identity)})
|
user=> (sql/format '{truncate (transport restart identity)})
|
||||||
["TRUNCATE transport RESTART IDENTITY"]
|
["TRUNCATE TABLE transport RESTART IDENTITY"]
|
||||||
```
|
```
|
||||||
|
|
||||||
## columns
|
## columns
|
||||||
|
|
|
||||||
|
|
@ -998,12 +998,12 @@
|
||||||
(when opts
|
(when opts
|
||||||
(format-ddl-options opts context)))))
|
(format-ddl-options opts context)))))
|
||||||
|
|
||||||
(defn- format-truncate [k xs]
|
(defn- format-truncate [_ xs]
|
||||||
(let [[table & options] (ensure-sequential xs)
|
(let [[table & options] (ensure-sequential xs)
|
||||||
[pre table ine options] (destructure-ddl-item [table options] "truncate")]
|
[pre table ine options] (destructure-ddl-item [table options] "truncate")]
|
||||||
(when (seq pre) (throw (ex-info "TRUNCATE syntax error" {:unexpected pre})))
|
(when (seq pre) (throw (ex-info "TRUNCATE syntax error" {:unexpected pre})))
|
||||||
(when (seq ine) (throw (ex-info "TRUNCATE syntax error" {:unexpected ine})))
|
(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)
|
(seq options)
|
||||||
(conj options)))]))
|
(conj options)))]))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -562,10 +562,10 @@
|
||||||
(format)))))
|
(format)))))
|
||||||
|
|
||||||
(deftest truncate-test
|
(deftest truncate-test
|
||||||
(is (= ["TRUNCATE `foo`"]
|
(is (= ["TRUNCATE TABLE `foo`"]
|
||||||
(-> {:truncate :foo}
|
(-> {:truncate :foo}
|
||||||
(format {:dialect :mysql}))))
|
(format {:dialect :mysql}))))
|
||||||
(is (= ["TRUNCATE `foo` CONTINUE IDENTITY"]
|
(is (= ["TRUNCATE TABLE `foo` CONTINUE IDENTITY"]
|
||||||
(-> {:truncate [:foo :continue :identity]}
|
(-> {:truncate [:foo :continue :identity]}
|
||||||
(format {:dialect :mysql})))))
|
(format {:dialect :mysql})))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue