diff --git a/CHANGELOG.md b/CHANGELOG.md index a9ef8d7..9c139ad 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 [#227](https://github.com/seancorfield/next-jdbc/issues/227) by correcting how [#221](https://github.com/seancorfield/next-jdbc/issues/221) was implemented. * Address [#224](https://github.com/seancorfield/next-jdbc/issues/224) by attempting to clarify how to use the snake/kebab options and builders. * 1.3.828 -- 2022-09-11 diff --git a/src/next/jdbc/result_set.clj b/src/next/jdbc/result_set.clj index dda376a..4073c7e 100644 --- a/src/next/jdbc/result_set.clj +++ b/src/next/jdbc/result_set.clj @@ -486,7 +486,9 @@ (metadata-preserving) operations on it." [^ResultSet rs opts] (let [builder (delay ((get opts :builder-fn as-maps) rs opts)) - name-fn (get opts :column-fn name)] + name-fn (if (contains? opts :column-fn) + (comp (get opts :column-fn) name) + name)] (reify MapifiedResultSet diff --git a/test/next/jdbc/plan_test.clj b/test/next/jdbc/plan_test.clj index d33daad..255f50f 100644 --- a/test/next/jdbc/plan_test.clj +++ b/test/next/jdbc/plan_test.clj @@ -6,7 +6,8 @@ [next.jdbc.plan :as plan] [next.jdbc.specs :as specs] [next.jdbc.test-fixtures - :refer [with-test-db ds]])) + :refer [with-test-db ds]] + [clojure.string :as str])) (set! *warn-on-reflection* true) @@ -55,3 +56,17 @@ (is (= {1 "Apple", 2 "Banana", 3 "Peach", 4 "Orange"} (plan/select! (ds) (juxt :id :name) ["select * from fruit order by id"] {:into {}})))) + +(deftest select-issue-227 + (is (= ["Apple"] + (plan/select! (ds) :name ["select * from fruit where id = ?" 1] + {:column-fn #(str/replace % "-" "_")}))) + (is (= ["Apple"] + (plan/select! (ds) :foo/name ["select * from fruit where id = ?" 1] + {:column-fn #(str/replace % "-" "_")}))) + (is (= ["Apple"] + (plan/select! (ds) #(get % "name") ["select * from fruit where id = ?" 1] + {:column-fn #(str/replace % "-" "_")}))) + (is (= [["Apple"]] + (plan/select! (ds) (juxt :name) ["select * from fruit where id = ?" 1] + {:column-fn #(str/replace % "-" "_")}))))