Addresses #110 by adding row-number, column-names

This is a quick sketch that doesn't break the existing tests. 
Documentation and tests coming soon!
This commit is contained in:
Sean Corfield 2020-05-22 17:11:36 -07:00
parent 8e4dbd7bd9
commit 860298943c

View file

@ -385,6 +385,13 @@
(definterface MapifiedResultSet)
(defprotocol InspectableMapifiedResultSet :extend-via-metadata true
""
(row-number [this]
"")
(column-names [this]
""))
(defn- mapify-result-set
"Given a `ResultSet`, return an object that wraps the current row as a hash
map. Note that a result set is mutable and the current row will change behind
@ -403,6 +410,10 @@
MapifiedResultSet
;; marker, just for printing resolution
InspectableMapifiedResultSet
(row-number [this] (.getRow rs))
(column-names [this] (:cols @builder))
clojure.lang.IPersistentMap
(assoc [this k v]
(assoc (row-builder @builder) k v))
@ -458,9 +469,18 @@
DatafiableRow
(datafiable-row [this connectable opts]
;; since we have to call these eagerly, we trap any exceptions so
;; that they can be thrown when the actual functions are called
(let [row (try (.getRow rs) (catch Throwable t t))
cols (try (:cols @builder) (catch Throwable t t))]
(with-meta
(row-builder @builder)
{`core-p/datafy (navize-row connectable opts)}))
{`core-p/datafy
(navize-row connectable opts)
`row-number
(fn [_] (if (instance? Throwable row) (throw row) row))
`column-names
(fn [_] (if (instance? Throwable cols) (throw cols) cols))})))
(toString [_]
(try