Depends on local clojure.java.data

This commit is contained in:
Sean Corfield 2020-05-31 14:13:55 -07:00
parent ab588070e6
commit ace912c867
2 changed files with 9 additions and 9 deletions

View file

@ -2,7 +2,8 @@
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/java.data {:mvn/version "1.0.64"}}
:aliases
{:test {:extra-paths ["test"]
{:local {:override-deps {org.clojure/java.data {:local/root "../java.data"}}}
:test {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.0.0"}
;; connection pooling
com.zaxxer/HikariCP {:mvn/version "3.4.2"}

View file

@ -9,6 +9,7 @@
are navigable to produce fully-realized datafiable result sets.
* `java.sql.ResultSetMetaData` -- datafies as a vector of column descriptions."
(:require [clojure.core.protocols :as core-p]
[clojure.java.data :as j]
[next.jdbc.result-set :as rs])
(:import (java.sql Connection
DatabaseMetaData
@ -63,10 +64,9 @@
:unknown))
:signed (fn [^ParameterMetaData o i] (.isSigned o i))})
(defn- safe-bean [o]
(defn- safe-bean [o opts]
(try
;; ensure we return a basic hash map:
(merge {} (bean o))
(j/from-java-shallow o (assoc opts :add-class true))
(catch Throwable t
(let [dex (juxt type (comp str ex-message))
cause (ex-cause t)]
@ -90,10 +90,10 @@
(extend-protocol core-p/Datafiable
Connection
(datafy [this] (safe-bean this))
(datafy [this] (safe-bean this {}))
DatabaseMetaData
(datafy [this]
(with-meta (let [data (safe-bean this)]
(with-meta (let [data (safe-bean this {})]
(cond-> data
(not (:exception (meta data)))
(assoc :all-tables [])))
@ -135,8 +135,7 @@
(datafy-result-set-meta-data this)
(let [s (.getStatement this)
c (when s (.getConnection s))]
(cond-> (safe-bean this)
(cond-> (safe-bean this {})
c (assoc :rows (rs/datafiable-result-set this c {}))))))
Statement
;; danger: .getMoreResults() is a mutating function!
(datafy [this] (safe-bean this)))
(datafy [this] (safe-bean this {:omit #{:moreResults}})))