Fixes #162 by adding composite/:composite
Relies on paren-wrapping within subqueries which is the context for values.
This commit is contained in:
parent
f17a6f5582
commit
bb73dcbda7
4 changed files with 26 additions and 0 deletions
|
|
@ -3,6 +3,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 #162 by adding `composite`/`:composite` constructor for values. (@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)
|
||||
* Fix #99 by adding a note to the first use of `select` in the README that column names can be keywords or symbols but not strings. (@seancorfield)
|
||||
|
|
|
|||
15
README.md
15
README.md
|
|
@ -186,6 +186,21 @@ The column values do not have to be literals, they can be nested queries:
|
|||
"user"]
|
||||
```
|
||||
|
||||
Composite types are supported:
|
||||
|
||||
```clojure
|
||||
(-> (insert-into :comp_table)
|
||||
(columns :name :comp_column)
|
||||
(values
|
||||
[["small" (composite 1 "inch")]
|
||||
["large" (composite 10 "feet")]])
|
||||
sql/format)
|
||||
=> [#sql/regularize
|
||||
"INSERT INTO comp_table (name, comp_column)
|
||||
VALUES (?, (?, ?)), (?, (?, ?))"
|
||||
"small" 1 "inch" "large" 10 "feet"]
|
||||
```
|
||||
|
||||
Updates are possible too (note the double S in `sset` to avoid clashing
|
||||
with `clojure.core/set`):
|
||||
|
||||
|
|
|
|||
|
|
@ -226,6 +226,7 @@
|
|||
:delete-from 80
|
||||
:truncate 85
|
||||
:columns 90
|
||||
:composite 95
|
||||
:set0 100 ; low-priority set clause
|
||||
:from 110
|
||||
:join 120
|
||||
|
|
@ -612,6 +613,9 @@
|
|||
(defmethod format-clause :columns [[_ fields] _]
|
||||
(str "(" (comma-join (map to-sql fields)) ")"))
|
||||
|
||||
(defmethod format-clause :composite [[_ fields] _]
|
||||
(comma-join (map to-sql fields)))
|
||||
|
||||
(defmethod format-clause :values [[_ values] _]
|
||||
(if (sequential? (first values))
|
||||
(str "VALUES " (comma-join (for [x values]
|
||||
|
|
|
|||
|
|
@ -250,6 +250,12 @@
|
|||
(check-varargs :merge-columns fields)
|
||||
(build-clause :merge-columns m fields)))
|
||||
|
||||
(macros/usetime
|
||||
(defhelper composite [m ms]
|
||||
(if (nil? ms)
|
||||
m
|
||||
(assoc m :composite (collify ms)))))
|
||||
|
||||
(defmethod build-clause :values [_ m vs]
|
||||
(assoc m :values vs))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue