From ace912c8679f9817c7cc5db9fa368d79f3f6049e Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 31 May 2020 14:13:55 -0700 Subject: [PATCH] Depends on local clojure.java.data --- deps.edn | 3 ++- src/next/jdbc/datafy.clj | 15 +++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/deps.edn b/deps.edn index 3a0c896..4a21009 100644 --- a/deps.edn +++ b/deps.edn @@ -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"} diff --git a/src/next/jdbc/datafy.clj b/src/next/jdbc/datafy.clj index 88c9446..aec5585 100644 --- a/src/next/jdbc/datafy.clj +++ b/src/next/jdbc/datafy.clj @@ -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}})))