Fix #43 by relaxing the spec for insert-multi!

Adds tests for `insert-multi!` that pass sequences instead of vectors.
This commit is contained in:
Sean Corfield 2019-07-11 12:34:02 -07:00
parent 821f9b1a5a
commit 4d7a5a440b
3 changed files with 23 additions and 3 deletions

View file

@ -6,8 +6,9 @@ Only accretive/fixative changes will be made from now on.
The following changes have been committed to the **master** branch since the 1.0.1 release: The following changes have been committed to the **master** branch since the 1.0.1 release:
* Fix #45 by adding TimesTen driver support. * Fix #45 by adding [TimesTen](https://www.oracle.com/database/technologies/related/timesten.html) driver support.
* Fix #44 so that `insert-multi!` with an empty `rows` vector returns `[]`. * Fix #44 so that `insert-multi!` with an empty `rows` vector returns `[]`.
* Fix #43 by adjusting the spec for `insert-multi!` to "require less" of the `cols` and `rows` arguments.
* Fix #42 by adding specs for `execute-batch!` and `set-parameters` in `next.jdbc.prepare`. * Fix #42 by adding specs for `execute-batch!` and `set-parameters` in `next.jdbc.prepare`.
* Fix #41 by improving docstrings and documentation, especially around prepared statement handling. * Fix #41 by improving docstrings and documentation, especially around prepared statement handling.
* Fix #40 by adding `next.jdbc.prepare/execute-batch!`. * Fix #40 by adding `next.jdbc.prepare/execute-batch!`.

View file

@ -126,8 +126,8 @@
(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 vector?) :cols (s/coll-of keyword? :kind sequential?)
:rows (s/coll-of (s/coll-of any? :kind vector?) :kind vector?) :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 %)))))

View file

@ -155,6 +155,25 @@
(is (= {:next.jdbc/update-count 2} (is (= {:next.jdbc/update-count 2}
(sql/delete! (ds) :fruit ["id > ?" 4]))) (sql/delete! (ds) :fruit ["id > ?" 4])))
(is (= 4 (count (sql/query (ds) ["select * from fruit"]))))) (is (= 4 (count (sql/query (ds) ["select * from fruit"])))))
(testing "multiple insert/delete with sequential cols/rows" ; per #43
(is (= (cond (derby?)
[{:1 nil}] ; WTF Apache Derby?
(sqlite?)
[{(keyword "last_insert_rowid()") 11}]
:else
[{:FRUIT/ID 9} {:FRUIT/ID 10} {:FRUIT/ID 11}])
(sql/insert-multi! (ds) :fruit
'(:name :appearance :cost :grade)
'(("Kiwi" "green & fuzzy" 100 99.9)
("Grape" "black" 10 50)
("Lemon" "yellow" 20 9.9)))))
(is (= 7 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 1}
(sql/delete! (ds) :fruit {:id 9})))
(is (= 6 (count (sql/query (ds) ["select * from fruit"]))))
(is (= {:next.jdbc/update-count 2}
(sql/delete! (ds) :fruit ["id > ?" 4])))
(is (= 4 (count (sql/query (ds) ["select * from fruit"])))))
(testing "empty insert-multi!" ; per #44 (testing "empty insert-multi!" ; per #44
(is (= [] (sql/insert-multi! (ds) :fruit (is (= [] (sql/insert-multi! (ds) :fruit
[:name :appearance :cost :grade] [:name :appearance :cost :grade]