8000 Convert arrays to vecs · theasp/postgres.async@5c818bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c818bb

Browse files
committed
Convert arrays to vecs
1 parent ee1031f commit 5c818bb

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ pom.xml
55
pom.xml.asc
66
*.jar
77
*.class
8+
*.iml
9+
/.idea
810
/.lein-*
911
/.nrepl-port

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
:url "http://github.com/alaisi/postgres.async.git"}
88
:dependencies [[org.clojure/clojure "1.6.0"]
99
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
10-
[com.github.alaisi.pgasync/postgres-async-driver "0.3"]]
10+
[com.github.alaisi.pgasync/postgres-async-driver "0.4-SNAPSHOT"]]
1111
:global-vars {*warn-on-reflection* true}
1212
:target-path "target/%s")

src/postgres/async/impl.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717
`(reify Consumer (accept [_# ~param]
1818
(~@body))))
1919

20+
(defn column->value [^PgRow row ^String col]
21+
(let [r (.get row col)]
22+
(if (-> r .getClass .isArray)
23+
(vec r)
24+
r)))
25+
2026
(defn result->map [^ResultSet result]
2127
(let [columns (.getColumns result)
2228
row->map (fn [^PgRow row rowmap ^String col]
23-
(assoc rowmap (keyword (.toLowerCase col)) (.get row col)))]
29+
(assoc rowmap (keyword (.toLowerCase col)) (column->value row col)))]
2430
{:updated (.updatedRows result)
2531
:rows (vec (map (fn [row]
2632
(reduce (partial row->map row) {} columns))

test/postgres/async_test.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
(let [rs (wait (<query! *db* ["select 1 as x"]))]
3939
(is (= 1 (get-in rs [0 :x]))))))
4040

41+
(deftest query-for-array
42+
(testing "arrays are converted to vectors"
43+
(let [rs (wait (<query! *db* ["select '{1,2}'::INT[] as a"]))]
44+
(is (= [1 2] (get-in rs [0 :a]))))))
45+
4146
(deftest inserts
4247
(testing "insert returns row count"
4348
(let [rs (wait (<insert! *db* {:table table} {:t "x"}))]

0 commit comments

Comments
 (0)
0