Skip to content

Commit ac01c00

Browse files
committed
Use alternate column syntax in update
1 parent 7746169 commit ac01c00

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

test/clj_postgres_async/core_test.clj

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,23 @@
1010
value
1111
default))
1212

13+
(defn await [chan]
14+
(let [[r err] (<!! chan)]
15+
(if err
16+
(throw err)
17+
r)))
18+
19+
1320
(defn create-tables [db]
14-
(let [[_ err] (<!! (go (dosql
15-
[_ (<execute! db ["drop table if exists clj_pg_test"])
16-
_ (<execute! db ["create table clj_pg_test (
17-
id serial, t varchar(10)
18-
)"])])))]
19-
(if err
20-
(throw err))))
21+
(await (<execute! db ["drop table if exists clj_pg_test"]))
22+
(await (<execute! db ["create table clj_pg_test (
23+
id serial, t varchar(10))"])))
24+
25+
(defn await [chan]
26+
(let [[r err] (<!! chan)]
27+
(if err
28+
(throw err)
29+
r)))
2130

2231
(defn db-fixture [f]
2332
(binding [*db* (open-db {:hostname (env "PG_HOST" "localhost")
@@ -35,15 +44,15 @@
3544

3645
(deftest queries
3746
(testing "<query! returns rows as map"
38-
(let [[rs err] (<!! (<query! *db* ["select 1 as x"]))]
47+
(let [rs (await (<query! *db* ["select 1 as x"]))]
3948
(is (= 1 (get-in rs [0 :x]))))))
4049

4150
(deftest inserts
4251
(testing "insert return row count"
43-
(let [[rs err] (<!! (<insert! *db* {:table "clj_pg_test"} {:t "x"}))]
52+
(let [rs (await (<insert! *db* {:table "clj_pg_test"} {:t "x"}))]
4453
(is (= 1 (:updated rs)))))
4554
(testing "insert with returning returns generated keys"
46-
(let [[rs err] (<!! (<insert! *db* {:table "clj_pg_test" :returning "id"} {:t "y"}))]
55+
(let [rs (await (<insert! *db* {:table "clj_pg_test" :returning "id"} {:t "y"}))]
4756
(is (get-in rs [:rows 0 :id])))))
4857

4958
(deftest sql-macro

0 commit comments

Comments
 (0)