fix set-dialect! reset and document it

This commit is contained in:
Sean Corfield 2022-09-11 15:09:12 -07:00
parent 63df2f3dc9
commit 723b134e90
2 changed files with 8 additions and 5 deletions

View file

@ -339,6 +339,8 @@ globally via the `set-dialect!` function.
;; and reset back to the default of :ansi ;; and reset back to the default of :ansi
(sql/set-dialect! :ansi) (sql/set-dialect! :ansi)
;;=> nil ;;=> nil
;; which also resets the quoting default (back to nil)
;; so only unusual entity names get quoted:
(sql/format '{select (id) from (table)} {:quoted true}) (sql/format '{select (id) from (table)} {:quoted true})
;;=> ["SELECT \"id\" FROM \"table\""] ;;=> ["SELECT \"id\" FROM \"table\""]
``` ```

View file

@ -1563,16 +1563,17 @@
Can be: `:ansi` (the default), `:mysql`, `:oracle`, or `:sqlserver`. Can be: `:ansi` (the default), `:mysql`, `:oracle`, or `:sqlserver`.
Can optionally accept `:quoted true` (or `:quoted false`) to set the Can optionally accept `:quoted true` (or `:quoted false`) to set the
default global quoting strategy. Note that calling `set-options!` can default global quoting strategy. Without `:quoted`, the default global
override this default. quoting strategy will be reset (only quoting unusual entity names).
Note that calling `set-options!` can override this default.
Dialects are always applied to the base order to create the current order." Dialects are always applied to the base order to create the current order."
[dialect & {:as opts}] [dialect & {:keys [quoted]}]
(reset! default-dialect (get @dialects (check-dialect dialect))) (reset! default-dialect (get @dialects (check-dialect dialect)))
(when-let [f (:clause-order-fn @default-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)))
(when (contains? opts :quoted) (reset! default-quoted quoted))
(reset! default-quoted (:quoted opts))))
(defn set-options! (defn set-options!
"Set default values for any or all of the following options: "Set default values for any or all of the following options: