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