8000 Nested array support · alaisi/postgres.async@ab118f9 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit ab118f9

Browse files
committed
Nested array support
1 parent e6d768a commit ab118f9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/postgres/async/impl.clj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
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)))
20+
(defn column->value [^Object value]
21+
(if (or (nil? value)
22+
(not (-> value .getClass .isArray)))
23+
value
24+
(vec (map column->value value))))
2525

2626
(defn result->map [^ResultSet result]
2727
(let [columns (.getColumns result)
2828
row->map (fn [^PgRow row rowmap ^String col]
29-
(assoc rowmap (keyword (.toLowerCase col)) (column->value row col)))]
29+
(assoc rowmap (keyword (.toLowerCase col))
30+
(column->value (.get row col))))]
3031
{:updated (.updatedRows result)
3132
:rows (vec (map (fn [row]
3233
(reduce (partial row->map row) {} columns))

test/postgres/async_test.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
(deftest query-for-array
4242
(testing "arrays are converted to vectors"
4343
(let [rs (wait (<query! *db* ["select '{1,2}'::INT[] as a"]))]
44-
(is (= [1 2] (get-in rs [0 :a]))))))
44+
(is (= [1 2] (get-in rs [0 :a])))))
45+
(testing "nested arrays are converted to vectors"
46+
(let [rs (wait (<query! *db* ["select '{{1,2},{3,4},{5,NULL}}'::INT[][] as a"]))]
47+
(is (= [[1 2] [3 4] [5 nil]] (get-in rs [0 :a]))))))
4548

4649
(deftest inserts
4750
(testing "insert returns row count"

0 commit comments

Comments
 (0)
0