Use auto_increment so H2 will return generated keys
Also update the result set builder used in one test
This commit is contained in:
parent
c229fa28e0
commit
214470bf9d
3 changed files with 21 additions and 14 deletions
|
|
@ -85,8 +85,15 @@
|
||||||
["select * from fruit where id = ?" 3]
|
["select * from fruit where id = ?" 3]
|
||||||
{:gen-fn rs/as-lower-maps})]
|
{:gen-fn rs/as-lower-maps})]
|
||||||
(is (map? row))
|
(is (map? row))
|
||||||
(is (= 3 (:id row)))
|
(is (= 3 (:fruit/id row)))
|
||||||
(is (= "Peach" (:name row))))))
|
(is (= "Peach" (:fruit/name row)))))
|
||||||
|
(testing "lower-case row builder"
|
||||||
|
(let [row (p/-execute-one (ds)
|
||||||
|
["select * from fruit where id = ?" 4]
|
||||||
|
{:gen-fn rs/as-unqualified-lower-maps})]
|
||||||
|
(is (map? row))
|
||||||
|
(is (= 4 (:id row)))
|
||||||
|
(is (= "Orange" (:name row))))))
|
||||||
|
|
||||||
(deftest test-mapify
|
(deftest test-mapify
|
||||||
(testing "no row builder is used"
|
(testing "no row builder is used"
|
||||||
|
|
|
||||||
|
|
@ -114,21 +114,21 @@
|
||||||
|
|
||||||
(deftest test-insert-delete
|
(deftest test-insert-delete
|
||||||
(testing "single insert/delete"
|
(testing "single insert/delete"
|
||||||
;; H2 with :return-keys true produces an empty result set
|
(is (= {:FRUIT/ID 5}
|
||||||
(is (nil? (sql/insert! (ds) :fruit
|
(sql/insert! (ds) :fruit
|
||||||
{:id 5 :name "Kiwi" :appearance "green & fuzzy"
|
{:name "Kiwi" :appearance "green & fuzzy"
|
||||||
:cost 100 :grade 99.9})))
|
:cost 100 :grade 99.9})))
|
||||||
(is (= 5 (count (sql/query (ds) ["select * from fruit"]))))
|
(is (= 5 (count (sql/query (ds) ["select * from fruit"]))))
|
||||||
(is (= {:next.jdbc/update-count 1}
|
(is (= {:next.jdbc/update-count 1}
|
||||||
(sql/delete! (ds) :fruit {:id 5})))
|
(sql/delete! (ds) :fruit {:id 5})))
|
||||||
(is (= 4 (count (sql/query (ds) ["select * from fruit"])))))
|
(is (= 4 (count (sql/query (ds) ["select * from fruit"])))))
|
||||||
(testing "multiple insert/delete"
|
(testing "multiple insert/delete"
|
||||||
;; H2 with :return-keys true produces an empty result set
|
(is (= [{:FRUIT/ID 6} {:FRUIT/ID 7} {:FRUIT/ID 8}]
|
||||||
(is (= [] (sql/insert-multi! (ds) :fruit
|
(sql/insert-multi! (ds) :fruit
|
||||||
[:id :name :appearance :cost :grade]
|
[:name :appearance :cost :grade]
|
||||||
[[5 "Kiwi" "green & fuzzy" 100 99.9]
|
[["Kiwi" "green & fuzzy" 100 99.9]
|
||||||
[6 "Grape" "black" 10 50]
|
["Grape" "black" 10 50]
|
||||||
[7 "Lemon" "yellow" 20 9.9]])))
|
["Lemon" "yellow" 20 9.9]])))
|
||||||
(is (= 7 (count (sql/query (ds) ["select * from fruit"]))))
|
(is (= 7 (count (sql/query (ds) ["select * from fruit"]))))
|
||||||
(is (= {:next.jdbc/update-count 1}
|
(is (= {:next.jdbc/update-count 1}
|
||||||
(sql/delete! (ds) :fruit {:id 6})))
|
(sql/delete! (ds) :fruit {:id 6})))
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@
|
||||||
(catch Exception _))
|
(catch Exception _))
|
||||||
(jdbc/execute-one! con ["
|
(jdbc/execute-one! con ["
|
||||||
CREATE TABLE fruit (
|
CREATE TABLE fruit (
|
||||||
id int default 0,
|
id int auto_increment primary key,
|
||||||
name varchar(32) primary key,
|
name varchar(32),
|
||||||
appearance varchar(32),
|
appearance varchar(32),
|
||||||
cost int,
|
cost int,
|
||||||
grade real
|
grade real
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue