diff --git a/CHANGELOG.md b/CHANGELOG.md index 73279ca..71cf762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Only accretive/fixative changes will be made from now on. * 1.3.next in progress + * Fix [#222](https://github.com/seancorfield/next-jdbc/issues/222) by correcting implementation of `.cons` on a row. * Address [#218](https://github.com/seancorfield/next-jdbc/issues/218) by moving `:extend-via-metadata true` after the protocols' docstrings. * Document `:useBulkCopyForBatchInsert` for Microsoft SQL Server via PR [#216](https://github.com/seancorfield/next-jdbc/issues/216) -- [danskarda](https://github.com/danskarda). * Address [#215](https://github.com/seancorfield/next-jdbc/issues/215) by dropping official support for JDK 8 and updating various JDBC drivers in the testing matrix. diff --git a/src/next/jdbc/result_set.clj b/src/next/jdbc/result_set.clj index 75cc1c5..65e9fdd 100644 --- a/src/next/jdbc/result_set.clj +++ b/src/next/jdbc/result_set.clj @@ -528,7 +528,8 @@ clojure.lang.IPersistentCollection (cons [this obj] - (cons obj (seq (row-builder @builder)))) + (let [row (row-builder @builder)] + (conj row obj))) (empty [this] {}) (equiv [this obj] diff --git a/test/next/jdbc/result_set_test.clj b/test/next/jdbc/result_set_test.clj index 5b502a8..69bdcce 100644 --- a/test/next/jdbc/result_set_test.clj +++ b/test/next/jdbc/result_set_test.clj @@ -367,7 +367,40 @@ (p/-execute (ds) ["select * from fruit"] {}))))) (is (every? map-entry? (reduce (fn [_ row] (reduced (seq row))) nil - (p/-execute (ds) ["select * from fruit"] {}))))) + (p/-execute (ds) ["select * from fruit"] {})))) + (is (map? (reduce (fn [_ row] (reduced (conj row {:a 1}))) + nil + (p/-execute (ds) ["select * from fruit"] {})))) + (is (map? (reduce (fn [_ row] (reduced (conj row [:a 1]))) + nil + (p/-execute (ds) ["select * from fruit"] {})))) + (is (map? (reduce (fn [_ row] (reduced (conj row {:a 1 :b 2}))) + nil + (p/-execute (ds) ["select * from fruit"] {})))) + (is (= 1 (:a (reduce (fn [_ row] (reduced (conj row {:a 1}))) + nil + (p/-execute (ds) ["select * from fruit"] {}))))) + (is (= 1 (:a (reduce (fn [_ row] (reduced (conj row [:a 1]))) + nil + (p/-execute (ds) ["select * from fruit"] {}))))) + (is (= 1 (:a (reduce (fn [_ row] (reduced (conj row {:a 1 :b 2}))) + nil + (p/-execute (ds) ["select * from fruit"] {}))))) + (is (= 2 (:b (reduce (fn [_ row] (reduced (conj row {:a 1 :b 2}))) + nil + (p/-execute (ds) ["select * from fruit"] {}))))) + (is (vector? (reduce (fn [_ row] (reduced (conj row :a))) + nil + (p/-execute (ds) ["select * from fruit"] + {:builder-fn rs/as-arrays})))) + (is (= :a (peek (reduce (fn [_ row] (reduced (conj row :a))) + nil + (p/-execute (ds) ["select * from fruit"] + {:builder-fn rs/as-arrays}))))) + (is (= :b (peek (reduce (fn [_ row] (reduced (conj row :a :b))) + nil + (p/-execute (ds) ["select * from fruit"] + {:builder-fn rs/as-arrays})))))) (testing "datafiable-row builds map; with metadata" (is (map? (reduce (fn [_ row] (reduced (rs/datafiable-row row (ds) {}))) nil