parent
dae09ff601
commit
92e0a04a84
3 changed files with 27 additions and 8 deletions
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
* 2.0.next in progress
|
||||
* Address #364 by recommending how to handle PostgreSQL operators that contain `@`.
|
||||
* Fix #363 by aligning more closely the semantics of `:inline` syntax with the `:inline true` option. A side effect of this is that `[:inline [:param :foo]]` will now (correctly) inline the value of the parameter `:foo` whereas it previously produced `PARAMS SOURCE`. In addition, inlining has been extended to vector values, so `[:inline ["a" "b" "c"]]` will now produce `('a', 'b', 'c')` and `[:inline [:lift ["a" "b" "c"]]]` will now produce `['a', 'b', 'c']` which is what people seemed to expect (the behavior was previously unspecified).
|
||||
* Fix #363 and #362 by aligning more closely the semantics of `:inline` syntax with the `:inline true` option. A side effect of this is that `[:inline [:param :foo]]` will now (correctly) inline the value of the parameter `:foo` whereas it previously produced `PARAMS SOURCE`. In addition, inlining has been extended to vector values, so `[:inline ["a" "b" "c"]]` will now produce `('a', 'b', 'c')` and `[:inline [:lift ["a" "b" "c"]]]` will now produce `['a', 'b', 'c']` which is what people seemed to expect (the behavior was previously unspecified).
|
||||
* Fix #353 by correcting handling of strings used as SQL entities (such as table names); this was a regression introduced by a recent enhancement to `:create-table`.
|
||||
* Fix #349 by adding an optional `:quoted` argument to `set-dialect!`.
|
||||
* Support `AS` aliasing in `DELETE FROM`.
|
||||
* Switch from `readme` to `test-doc-blocks` so all documentation is tested!
|
||||
* Clean up build/update deps.
|
||||
|
|
|
|||
|
|
@ -325,7 +325,15 @@ specify a dialect in the `format` call, you can specify
|
|||
;;=> nil
|
||||
(sql/format '{select (id) from (table)} {:quoted true})
|
||||
;;=> ["SELECT [id] FROM [table]"]
|
||||
;; and to the default of :ansi
|
||||
;; you can also choose to enable quoting globally
|
||||
;; when you set a dialect:
|
||||
(sql/set-dialect! :mysql :quoted true)
|
||||
(sql/format '{select (id) from (table)})
|
||||
;;=> ["SELECT `id` FROM `table`"]
|
||||
;; and opt out for a specific call:
|
||||
(sql/format '{select (id) from (table)} {:quoted false})
|
||||
;;=> ["SELECT id FROM table"]
|
||||
;; and reset back to the default of :ansi
|
||||
(sql/set-dialect! :ansi)
|
||||
;;=> nil
|
||||
(sql/format '{select (id) from (table)} {:quoted true})
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
* `register-fn!` -- register a new function call (or special syntax)
|
||||
formatter.
|
||||
* `register-op!` -- register a new operator formatter.
|
||||
* `set-dialect!` -- set the default dialect to be used for formatting.
|
||||
* `set-dialect!` -- set the default dialect to be used for formatting,
|
||||
and optionally set a global `:quoted` option.
|
||||
* `sql-kw` -- turns a Clojure keyword (or symbol) into SQL code (makes
|
||||
it uppercase and replaces - with space). "
|
||||
(:refer-clojure :exclude [format])
|
||||
|
|
@ -97,6 +98,7 @@
|
|||
|
||||
; should become defonce
|
||||
(def ^:private default-dialect (atom (:ansi dialects)))
|
||||
(def ^:private default-quoted (atom nil))
|
||||
|
||||
(def ^:private ^:dynamic *dialect* nil)
|
||||
;; nil would be a better default but that makes testing individual
|
||||
|
|
@ -1323,9 +1325,12 @@
|
|||
@current-clause-order)
|
||||
*inline* (when (contains? opts :inline)
|
||||
(:inline opts))
|
||||
*quoted* (if (contains? opts :quoted)
|
||||
(:quoted opts)
|
||||
dialect?)
|
||||
*quoted* (cond (contains? opts :quoted)
|
||||
(:quoted opts)
|
||||
dialect?
|
||||
true
|
||||
:else
|
||||
@default-quoted)
|
||||
*quoted-snake* (when (contains? opts :quoted-snake)
|
||||
(:quoted-snake opts))
|
||||
*params* (:params opts)]
|
||||
|
|
@ -1337,11 +1342,15 @@
|
|||
|
||||
Can be: `:ansi` (the default), `:mysql`, `:oracle`, or `:sqlserver`.
|
||||
|
||||
Can optionally accept `:quoted true` (or `:quoted false`) to set the
|
||||
default global quoting strategy.
|
||||
|
||||
Dialects are always applied to the base order to create the current order."
|
||||
[dialect]
|
||||
[dialect & {:keys [quoted]}]
|
||||
(reset! default-dialect (get dialects (check-dialect dialect)))
|
||||
(when-let [f (:clause-order-fn @default-dialect)]
|
||||
(reset! current-clause-order (f @base-clause-order))))
|
||||
(reset! current-clause-order (f @base-clause-order)))
|
||||
(reset! default-quoted quoted))
|
||||
|
||||
(defn clause-order
|
||||
"Return the current order that known clauses will be applied when
|
||||
|
|
|
|||
Loading…
Reference in a new issue