Adds `*allow-namespaced-names?*` Var and `:allow-namespaced-names?` option so the previous behavior can still be used.
This commit is contained in:
parent
c573f3bd9c
commit
f17a6f5582
4 changed files with 19 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
|||
## Changes coming in 0.9.7
|
||||
|
||||
* Fix #248 by treating alias as "not a subquery" when generating SQL for it. (@seancorfield)
|
||||
* Fix #247 by reverting #132 / #131 so the default behavior is friendlier for namespace-qualified keywords used for table and column names, but adds `honeysql.format/*allow-namespaced-names?*` to restore the previous behavior. A `:allow-namespaced-names?` option has been adding to `format` to set this more easily.
|
||||
* Fix #235 by adding `set0` (`:set0`) and `set1` (`:set1`) variants of `sset` (`:set`) to support different placements of `SET` (before `FROM` or after `JOIN` respectively) that different databases require. See also #200. (@seancorfield)
|
||||
* Fix #139 by checking arguments to `columns`/`merge-columns` and throwing an exception if a single collection is supplied (instead of varargs). (@seancorfield)
|
||||
* Fix #128 by adding `truncate` support. (@seancorfield)
|
||||
|
|
@ -64,7 +65,6 @@ BREAKING CHANGES:
|
|||
|
||||
* Reprioritize WITH wrt UNION and UNION ALL (@emidln)
|
||||
* Helpers for :with and :with-recursive clauses (@enaeher)
|
||||
* Allow namespaced keywords and symbols for queries. (@jrdoane)
|
||||
* Ensure sequences act as function invocations when in value position (@joodie)
|
||||
* Correct generated arglist for helpers defined with defhelper (@michaelblume)
|
||||
* Don't depend on map iteration order, fix bug with multiple map types (@tomconnors)
|
||||
|
|
|
|||
|
|
@ -334,8 +334,8 @@ To quote identifiers, pass the `:quoting` keyword option to `format`. Valid opti
|
|||
=> ["SELECT `foo`.`a` FROM `foo` WHERE `foo`.`a` = ?" "baz"]
|
||||
```
|
||||
|
||||
To issue a locking select, add a :lock to the query or use the lock helper. The lock value must be a map with a :mode value. The built-in
|
||||
modes are the standard :update (FOR UPDATE) or the vendor-specific :mysql-share (LOCK IN SHARE MODE) or :postresql-share (FOR SHARE). The
|
||||
To issue a locking select, add a `:lock` to the query or use the lock helper. The lock value must be a map with a `:mode` value. The built-in
|
||||
modes are the standard :update (FOR UPDATE) or the vendor-specific `:mysql-share` (LOCK IN SHARE MODE) or `:postresql-share` (FOR SHARE). The
|
||||
lock map may also provide a :wait value, which if false will append the NOWAIT parameter, supported by PostgreSQL.
|
||||
|
||||
```clojure
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@
|
|||
|
||||
(def ^:dynamic *allow-dashed-names?* false)
|
||||
|
||||
(def ^:dynamic *allow-namespaced-names?* false)
|
||||
|
||||
(def ^:dynamic *name-transform-fn* nil)
|
||||
|
||||
(def ^:private quote-fns
|
||||
|
|
@ -93,8 +95,11 @@
|
|||
s (cond
|
||||
(or (keyword? x) (symbol? x))
|
||||
(name-transform-fn
|
||||
(str (when-let [n (namespace x)]
|
||||
(str n "/")) (name x)))
|
||||
(if *allow-namespaced-names?*
|
||||
(str (when-let [n (namespace x)]
|
||||
(str n "/"))
|
||||
(name x))
|
||||
(name x)))
|
||||
(string? x) (if qf x (name-transform-fn x))
|
||||
:else (str x))]
|
||||
(if-not qf
|
||||
|
|
@ -279,7 +284,8 @@
|
|||
*input-params* (atom params)
|
||||
*quote-identifier-fn* (quote-fns (:quoting opts))
|
||||
*parameterizer* (or (:parameterizer opts) :jdbc)
|
||||
*allow-dashed-names?* (:allow-dashed-names? opts)]
|
||||
*allow-dashed-names?* (:allow-dashed-names? opts)
|
||||
*allow-namespaced-names?* (:allow-namespaced-names? opts)]
|
||||
(let [sql-str (to-sql sql-map)]
|
||||
(if (and (seq @*params*) (not= :none (:parameterizer opts)))
|
||||
(if (:return-param-names opts)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
honeysql.core
|
||||
[honeysql.types :as sql]
|
||||
[honeysql.format :refer
|
||||
[*allow-dashed-names?* quote-identifier format-clause format
|
||||
[*allow-dashed-names?* *allow-namespaced-names?*
|
||||
quote-identifier format-clause format
|
||||
parameterize]]))
|
||||
|
||||
(deftest test-quote
|
||||
|
|
@ -35,8 +36,11 @@
|
|||
"\"foo-bar\".\"moo-bar\""))))
|
||||
|
||||
(deftest test-namespaced-identifier
|
||||
(is (= (quote-identifier :foo/bar) "foo/bar"))
|
||||
(is (= (quote-identifier :foo/bar :style :ansi) "\"foo/bar\"")))
|
||||
(is (= (quote-identifier :foo/bar) "bar"))
|
||||
(is (= (quote-identifier :foo/bar :style :ansi) "\"bar\""))
|
||||
(binding [*allow-namespaced-names?* true]
|
||||
(is (= (quote-identifier :foo/bar) "foo/bar"))
|
||||
(is (= (quote-identifier :foo/bar :style :ansi) "\"foo/bar\""))))
|
||||
|
||||
(deftest alias-splitting
|
||||
(is (= ["SELECT `aa`.`c` AS `a.c`, `bb`.`c` AS `b.c`, `cc`.`c` AS `c.c`"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue