diff --git a/CHANGELOG.md b/CHANGELOG.md index f9781fc..7cc7cfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Only accretive/fixative changes will be made from now on. Changes made on **develop** since the 1.1.547 release: +* Fix #130 by implementing `clojure.lang.ILookup` on the three builder adapters. * Correct MySQL batch statement rewrite tip: it's `:rewriteBatchedStatements true` (plural). Also surface the batch statement tips in the **Tips & Tricks** page. * Clarify how combining is interleaving with reducing in **Reducing and Folding with `plan`**. * Use "JDBC URL" consistently everywhere (instead of "JDBC URI" in several places). diff --git a/src/next/jdbc/optional.clj b/src/next/jdbc/optional.clj index 5107cb4..6e4b083 100644 --- a/src/next/jdbc/optional.clj +++ b/src/next/jdbc/optional.clj @@ -125,4 +125,7 @@ rs/ResultSetBuilder (->rs [this] (rs/->rs mrsb)) (with-row [this mrs row] (rs/with-row mrsb mrs row)) - (rs! [this mrs] (rs/rs! mrsb mrs)))))) + (rs! [this mrs] (rs/rs! mrsb mrs)) + clojure.lang.ILookup + (valAt [this k] (get mrsb k)) + (valAt [this k not-found] (get mrsb k not-found)))))) diff --git a/src/next/jdbc/result_set.clj b/src/next/jdbc/result_set.clj index 810b930..360779a 100644 --- a/src/next/jdbc/result_set.clj +++ b/src/next/jdbc/result_set.clj @@ -244,7 +244,10 @@ ResultSetBuilder (->rs [this] (->rs mrsb)) (with-row [this mrs row] (with-row mrsb mrs row)) - (rs! [this mrs] (rs! mrsb mrs)))))) + (rs! [this mrs] (rs! mrsb mrs)) + clojure.lang.ILookup + (valAt [this k] (get mrsb k)) + (valAt [this k not-found] (get mrsb k not-found)))))) (defn clob->string "Given a CLOB column value, read it as a string." @@ -360,7 +363,10 @@ ResultSetBuilder (->rs [this] (->rs arsb)) (with-row [this mrs row] (with-row arsb mrs row)) - (rs! [this mrs] (rs! arsb mrs)))))) + (rs! [this mrs] (rs! arsb mrs)) + clojure.lang.ILookup + (valAt [this k] (get arsb k)) + (valAt [this k not-found] (get arsb k not-found)))))) (declare navize-row) diff --git a/test/next/jdbc/result_set_test.clj b/test/next/jdbc/result_set_test.clj index dd17313..fb555ba 100644 --- a/test/next/jdbc/result_set_test.clj +++ b/test/next/jdbc/result_set_test.clj @@ -182,6 +182,32 @@ (is (contains? row (column :FRUIT/appearance))) (is (nil? ((column :FRUIT/appearance) row))) (is (= 3 ((column :FRUIT/id) row))) + (is (= "Peach" ((column :FRUIT/name) row)))) + (let [builder (rs/as-maps-adapter + rs/as-modified-maps + (fn [^ResultSet rs _ ^Integer i] + (.getObject rs i))) + row (p/-execute-one (ds) + ["select * from fruit where id = ?" 3] + (assoc + (default-options) + :builder-fn (rs/as-maps-adapter + builder + (fn [^ResultSet rs + ^ResultSetMetaData rsmeta + ^Integer i] + (condp = (.getColumnType rsmeta i) + java.sql.Types/VARCHAR + (.getString rs i) + java.sql.Types/INTEGER + (.getLong rs i) + (.getObject rs i)))) + :label-fn str/lower-case + :qualifier-fn identity))] + (is (map? row)) + (is (contains? row (column :FRUIT/appearance))) + (is (nil? ((column :FRUIT/appearance) row))) + (is (= 3 ((column :FRUIT/id) row))) (is (= "Peach" ((column :FRUIT/name) row)))))) (deftest test-row-number