Allow for row-build to return metadata

Instead of using `with-meta`, use `vary-meta` with `assoc` to _add_ 
metadata.
This commit is contained in:
Sean Corfield 2020-09-25 15:45:19 -07:00
parent 9cc0577214
commit 65ec940ccc

View file

@ -571,16 +571,17 @@
(let [row (try (.getRow rs) (catch Throwable t t)) (let [row (try (.getRow rs) (catch Throwable t t))
cols (try (:cols @builder) (catch Throwable t t)) cols (try (:cols @builder) (catch Throwable t t))
meta (try (d/datafy (.getMetaData rs)) (catch Throwable t t))] meta (try (d/datafy (.getMetaData rs)) (catch Throwable t t))]
(with-meta (vary-meta
(row-builder @builder) (row-builder @builder)
{`core-p/datafy assoc
`core-p/datafy
(navize-row connectable opts) (navize-row connectable opts)
`row-number `row-number
(fn [_] (if (instance? Throwable row) (throw row) row)) (fn [_] (if (instance? Throwable row) (throw row) row))
`column-names `column-names
(fn [_] (if (instance? Throwable cols) (throw cols) cols)) (fn [_] (if (instance? Throwable cols) (throw cols) cols))
`metadata `metadata
(fn [_] (if (instance? Throwable meta) (throw meta) meta))}))) (fn [_] (if (instance? Throwable meta) (throw meta) meta)))))
(toString [_] (toString [_]
(try (try
@ -604,8 +605,10 @@
;; in reality, this is going to be over-optimistic and will like cause `nav` ;; in reality, this is going to be over-optimistic and will like cause `nav`
;; to fail on attempts to navigate into result sets that are not hash maps ;; to fail on attempts to navigate into result sets that are not hash maps
(datafiable-row [this connectable opts] (datafiable-row [this connectable opts]
(with-meta this (vary-meta
{`core-p/datafy (navize-row connectable opts)}))) this
assoc
`core-p/datafy (navize-row connectable opts))))
(defn datafiable-result-set (defn datafiable-result-set
"Given a ResultSet, a connectable, and an options hash map, return a fully "Given a ResultSet, a connectable, and an options hash map, return a fully
@ -1029,8 +1032,10 @@
assumed foreign key column name." assumed foreign key column name."
[connectable opts] [connectable opts]
(fn [row] (fn [row]
(with-meta row (vary-meta
{`core-p/nav (fn [_ k v] row
assoc
`core-p/nav (fn [_ k v]
(try (try
(let [[table fk cardinality] (let [[table fk cardinality]
(expand-schema k (or (get-in opts [:schema k]) (expand-schema k (or (get-in opts [:schema k])
@ -1052,4 +1057,4 @@
(catch Exception _ (catch Exception _
;; assume an exception means we just cannot ;; assume an exception means we just cannot
;; navigate anywhere, so return just the value ;; navigate anywhere, so return just the value
v)))}))) v))))))