Fixes #139 by checking columns arguments
This commit is contained in:
parent
7831ebed38
commit
4ca74f2b0d
2 changed files with 28 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
## Changes coming in 0.9.7
|
## Changes coming in 0.9.7
|
||||||
|
|
||||||
* Fix #248 by treating alias as "not a subquery" when generating SQL for it. (@seancorfield)
|
* Fix #248 by treating alias as "not a subquery" when generating SQL for it. (@seancorfield)
|
||||||
|
* Fix #139 by checking arguments to `columns`/`merge-columns` and throwing an exception if a single collection is supplied (instead of varargs).
|
||||||
* Fix #128 by adding `truncate` support.
|
* Fix #128 by adding `truncate` support.
|
||||||
* 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.
|
* 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.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,13 +221,34 @@
|
||||||
([table] (insert-into nil table))
|
([table] (insert-into nil table))
|
||||||
([m table] (build-clause :insert-into m table)))
|
([m table] (build-clause :insert-into m table)))
|
||||||
|
|
||||||
(macros/usetime
|
(defn- check-varargs
|
||||||
(defhelper columns [m fields]
|
"Called for helpers that require unrolled arguments to catch the mistake
|
||||||
(assoc m :columns (collify fields))))
|
of passing a collection as a single argument."
|
||||||
|
[helper args]
|
||||||
|
(when (and (coll? args) (= 1 (count args)) (coll? (first args)))
|
||||||
|
(let [msg (str (name helper) " takes varargs, not a single collection")]
|
||||||
|
(throw #?(:clj (IllegalArgumentException. msg)
|
||||||
|
:cljs (js/Error. msg))))))
|
||||||
|
|
||||||
(macros/usetime
|
(defmethod build-clause :columns [_ m fields]
|
||||||
(defhelper merge-columns [m fields]
|
(assoc m :columns (collify fields)))
|
||||||
(update-in m [:columns] concat (collify fields))))
|
|
||||||
|
(defn columns [& args]
|
||||||
|
(let [[m fields] (if (map? (first args))
|
||||||
|
[(first args) (rest args)]
|
||||||
|
[{} args])]
|
||||||
|
(check-varargs :columns fields)
|
||||||
|
(build-clause :columns m fields)))
|
||||||
|
|
||||||
|
(defmethod build-clause :merge-columns [_ m fields]
|
||||||
|
(update-in m [:columns] concat (collify fields)))
|
||||||
|
|
||||||
|
(defn merge-columns [& args]
|
||||||
|
(let [[m fields] (if (map? (first args))
|
||||||
|
[(first args) (rest args)]
|
||||||
|
[{} args])]
|
||||||
|
(check-varargs :merge-columns fields)
|
||||||
|
(build-clause :merge-columns m fields)))
|
||||||
|
|
||||||
(defmethod build-clause :values [_ m vs]
|
(defmethod build-clause :values [_ m vs]
|
||||||
(assoc m :values vs))
|
(assoc m :values vs))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue