Assert/spec/tests for empty cols in insert-multi!
This commit is contained in:
parent
4d7a5a440b
commit
4457161305
3 changed files with 10 additions and 2 deletions
|
|
@ -126,8 +126,11 @@
|
||||||
(s/fdef sql/insert-multi!
|
(s/fdef sql/insert-multi!
|
||||||
:args (s/and (s/cat :connectable ::connectable
|
:args (s/and (s/cat :connectable ::connectable
|
||||||
:table keyword?
|
:table keyword?
|
||||||
:cols (s/coll-of keyword? :kind sequential?)
|
:cols (s/coll-of keyword?
|
||||||
:rows (s/coll-of (s/coll-of any? :kind sequential?) :kind sequential?)
|
:kind sequential?
|
||||||
|
:min-count 1)
|
||||||
|
:rows (s/coll-of (s/coll-of any? :kind sequential?)
|
||||||
|
:kind sequential?)
|
||||||
:opts (s/? ::opts-map))
|
:opts (s/? ::opts-map))
|
||||||
#(apply = (count (:cols %))
|
#(apply = (count (:cols %))
|
||||||
(map count (:rows %)))))
|
(map count (:rows %)))))
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,7 @@
|
||||||
(assert (apply = (count cols) (map count rows))
|
(assert (apply = (count cols) (map count rows))
|
||||||
"column counts are not consistent across cols and rows")
|
"column counts are not consistent across cols and rows")
|
||||||
;; to avoid generating bad SQL
|
;; to avoid generating bad SQL
|
||||||
|
(assert (seq cols) "cols may not be empty")
|
||||||
(assert (seq rows) "rows may not be empty")
|
(assert (seq rows) "rows may not be empty")
|
||||||
(let [table-fn (:table-fn opts identity)
|
(let [table-fn (:table-fn opts identity)
|
||||||
column-fn (:column-fn opts identity)
|
column-fn (:column-fn opts identity)
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,10 @@
|
||||||
(is (thrown? clojure.lang.ExceptionInfo
|
(is (thrown? clojure.lang.ExceptionInfo
|
||||||
(sql/delete! (ds) :fruit {}))))
|
(sql/delete! (ds) :fruit {}))))
|
||||||
|
|
||||||
|
(deftest no-empty-columns
|
||||||
|
(is (thrown? clojure.lang.ExceptionInfo
|
||||||
|
(sql/insert-multi! (ds) :fruit [] [[] [] []]))))
|
||||||
|
|
||||||
(deftest no-empty-order-by
|
(deftest no-empty-order-by
|
||||||
(is (thrown? clojure.lang.ExceptionInfo
|
(is (thrown? clojure.lang.ExceptionInfo
|
||||||
(sql/find-by-keys (ds) :fruit
|
(sql/find-by-keys (ds) :fruit
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue