Fixes #130 by implementing lookup on the adapters

This commit is contained in:
Sean Corfield 2020-07-05 15:57:10 -07:00
parent 71ea50eff8
commit 65296ee4ad
4 changed files with 39 additions and 3 deletions

View file

@ -3,6 +3,7 @@
Only accretive/fixative changes will be made from now on. Only accretive/fixative changes will be made from now on.
Changes made on **develop** since the 1.1.547 release: 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. * 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`**. * 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). * Use "JDBC URL" consistently everywhere (instead of "JDBC URI" in several places).

View file

@ -125,4 +125,7 @@
rs/ResultSetBuilder rs/ResultSetBuilder
(->rs [this] (rs/->rs mrsb)) (->rs [this] (rs/->rs mrsb))
(with-row [this mrs row] (rs/with-row mrsb mrs row)) (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))))))

View file

@ -244,7 +244,10 @@
ResultSetBuilder ResultSetBuilder
(->rs [this] (->rs mrsb)) (->rs [this] (->rs mrsb))
(with-row [this mrs row] (with-row mrsb mrs row)) (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 (defn clob->string
"Given a CLOB column value, read it as a string." "Given a CLOB column value, read it as a string."
@ -360,7 +363,10 @@
ResultSetBuilder ResultSetBuilder
(->rs [this] (->rs arsb)) (->rs [this] (->rs arsb))
(with-row [this mrs row] (with-row arsb mrs row)) (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) (declare navize-row)

View file

@ -182,6 +182,32 @@
(is (contains? row (column :FRUIT/appearance))) (is (contains? row (column :FRUIT/appearance)))
(is (nil? ((column :FRUIT/appearance) row))) (is (nil? ((column :FRUIT/appearance) row)))
(is (= 3 ((column :FRUIT/id) 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)))))) (is (= "Peach" ((column :FRUIT/name) row))))))
(deftest test-row-number (deftest test-row-number