fixes #456
This commit is contained in:
parent
6ab8c6452b
commit
213c152fdb
4 changed files with 21 additions and 9 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
* 2.4.next in progress
|
||||||
|
* Address [#456](https://github.com/seancorfield/honeysql/issues/456) by allowing `format` to handling expressions (via `format-expr`) as well as statements (via `format-dsl` per previous versions).
|
||||||
|
|
||||||
* 2.4.969 -- 2023-01-14
|
* 2.4.969 -- 2023-01-14
|
||||||
* Fix [#454](https://github.com/seancorfield/honeysql/issues/454) by allowing `-` to be variadic.
|
* Fix [#454](https://github.com/seancorfield/honeysql/issues/454) by allowing `-` to be variadic.
|
||||||
* Address [#452](https://github.com/seancorfield/honeysql/pull/452) by adding `:replace-into` to the core SQL supported, instead of just for the MySQL and SQLite dialects (so the latter is not needed yet).
|
* Address [#452](https://github.com/seancorfield/honeysql/pull/452) by adding `:replace-into` to the core SQL supported, instead of just for the MySQL and SQLite dialects (so the latter is not needed yet).
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
:main 'clojure.main
|
:main 'clojure.main
|
||||||
:main-args (:main-opts combined)})
|
:main-args (:main-opts combined)})
|
||||||
{:keys [exit]} (b/process cmds)]
|
{:keys [exit]} (b/process cmds)]
|
||||||
(when-not (zero? exit) (throw "Task failed"))))
|
(when-not (zero? exit) (throw (ex-info "Task failed" {})))))
|
||||||
|
|
||||||
(defn eastwood "Run Eastwood." [opts]
|
(defn eastwood "Run Eastwood." [opts]
|
||||||
(run-task [:eastwood])
|
(run-task [:eastwood])
|
||||||
|
|
|
||||||
|
|
@ -1655,18 +1655,23 @@
|
||||||
This is the primary API for HoneySQL and handles dialects, quoting,
|
This is the primary API for HoneySQL and handles dialects, quoting,
|
||||||
and named parameters.
|
and named parameters.
|
||||||
|
|
||||||
|
If the data DSL is a hash map, it will be treated as a SQL statement
|
||||||
|
and formatted via `format-dsl`, otherwise it will be treated as a SQL
|
||||||
|
expression and formatted via `format-expr`.
|
||||||
|
|
||||||
`format` accepts options as either a single hash map argument or
|
`format` accepts options as either a single hash map argument or
|
||||||
as named arguments (alternating keys and values). If you are using
|
as named arguments (alternating keys and values). If you are using
|
||||||
Clojure 1.11 (or later) you can mix'n'match, providing some options
|
Clojure 1.11 (or later) you can mix'n'match, providing some options
|
||||||
as named arguments followed by other options in a hash map."
|
as named arguments followed by other options in a hash map."
|
||||||
([data] (format data {}))
|
([data] (format data {}))
|
||||||
([data opts]
|
([data opts]
|
||||||
(let [cache (:cache opts)
|
(let [cache (:cache opts)
|
||||||
dialect? (contains? opts :dialect)
|
dialect? (contains? opts :dialect)
|
||||||
dialect (when dialect? (get @dialects (check-dialect (:dialect opts))))
|
dialect (when dialect? (get @dialects (check-dialect (:dialect opts))))
|
||||||
numbered (if (contains? opts :numbered)
|
numbered (if (contains? opts :numbered)
|
||||||
(:numbered opts)
|
(:numbered opts)
|
||||||
@default-numbered)]
|
@default-numbered)
|
||||||
|
formatter (if (map? data) #'format-dsl #'format-expr)]
|
||||||
(binding [*dialect* (if dialect? dialect @default-dialect)
|
(binding [*dialect* (if dialect? dialect @default-dialect)
|
||||||
*caching* cache
|
*caching* cache
|
||||||
*checking* (if (contains? opts :checking)
|
*checking* (if (contains? opts :checking)
|
||||||
|
|
@ -1694,9 +1699,9 @@
|
||||||
*params* (:params opts)
|
*params* (:params opts)
|
||||||
*values-default-columns* (:values-default-columns opts)]
|
*values-default-columns* (:values-default-columns opts)]
|
||||||
(if cache
|
(if cache
|
||||||
(->> (through-opts opts cache data (fn [_] (format-dsl data (dissoc opts :cache))))
|
(->> (through-opts opts cache data (fn [_] (formatter data (dissoc opts :cache))))
|
||||||
(mapv #(unwrap % opts)))
|
(mapv #(unwrap % opts)))
|
||||||
(mapv #(unwrap % opts) (format-dsl data opts))))))
|
(mapv #(unwrap % opts) (formatter data opts))))))
|
||||||
([data k v & {:as opts}] (format data (assoc opts k v))))
|
([data k v & {:as opts}] (format data (assoc opts k v))))
|
||||||
|
|
||||||
(defn set-dialect!
|
(defn set-dialect!
|
||||||
|
|
|
||||||
|
|
@ -1058,3 +1058,7 @@ ORDER BY id = ? DESC
|
||||||
(deftest issue-434-case-quoting
|
(deftest issue-434-case-quoting
|
||||||
(is (= ["SELECT ARRAY (SELECT \"oid\" FROM \"pg_proc\" WHERE \"proname\" LIKE 'bytea%')"]
|
(is (= ["SELECT ARRAY (SELECT \"oid\" FROM \"pg_proc\" WHERE \"proname\" LIKE 'bytea%')"]
|
||||||
(sut/format {:select [[[:'ARRAY {:select :oid :from :pg_proc :where [:like :proname [:inline "bytea%"]]}]]]} :quoted true))))
|
(sut/format {:select [[[:'ARRAY {:select :oid :from :pg_proc :where [:like :proname [:inline "bytea%"]]}]]]} :quoted true))))
|
||||||
|
|
||||||
|
(deftest issue-456-format-expr
|
||||||
|
(is (= ["`x` + ?" 1]
|
||||||
|
(sut/format [:+ :x 1] {:dialect :mysql}))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue