diff --git a/README.md b/README.md index 17ce1e6..4c6b1bc 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ postgres.async ============== +[![Clojars Project](https://img.shields.io/clojars/v/alaisi/postgres.async.svg)](https://clojars.org/alaisi/postgres.async) + Asynchronous PostgreSQL client for Clojure. ## Download Add the following to your [Leiningen](http://github.com/technomancy/leiningen) `project.clj`: -![latest postgres.async version](https://clojars.org/alaisi/postgres.async/latest-version.svg) - +[![latest postgres.async version](https://clojars.org/alaisi/postgres.async/latest-version.svg)](https://clojars.org/alaisi/postgres.async) ## Setting up a connection pool @@ -138,7 +139,14 @@ Support for custom types can be added by extending `IPgParameter` protocol and ` (.getBytes (str store) "UTF-8"))) (defmethod from-pg-value com.github.pgasync.impl.Oid/HSTORE [oid ^bytes value] - (my-h-store/parse-string (String. value "UTF-8))) + (my-h-store/parse-string (String. value "UTF-8"))) +``` + +`from-pg-value` can also be used for overriding "core" types. This is especially useful with temporal data types that are by default converted to `java.sql.Date`, `java.sql.Time`, `java.sql.Timestamp`. + +```clojure +(defmethod from-pg-value com.github.pgasync.impl.Oid/DATE [oid ^bytes value] + (java.time.LocalDate/parse (String. value "UTF-8"))) ``` ## Dependencies diff --git a/project.clj b/project.clj index 858bf78..f78cba8 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject alaisi/postgres.async "0.7.0" +(defproject alaisi/postgres.async "0.9.0-SNAPSHOT" :description "Asynchronous PostgreSQL Clojure client" :url "http://github.com/alaisi/postgres.async" :license {:name "Eclipse Public License" @@ -7,7 +7,7 @@ :url "http://github.com/alaisi/postgres.async.git"} :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/core.async "0.2.374"] - [com.github.alaisi.pgasync/postgres-async-driver "0.8"] + [com.github.alaisi.pgasync/postgres-async-driver "0.9"] [cheshire "5.6.1" :scope "provided"]] :lein-release {:deploy-via :clojars} :global-vars {*warn-on-reflection* true} diff --git a/src/postgres/async.clj b/src/postgres/async.clj index 9ec8854..caa2c60 100644 --- a/src/postgres/async.clj +++ b/src/postgres/async.clj @@ -13,15 +13,15 @@ (defn- create-converter [] (proxy [DataConverter] [] + (fromConvertable [value] + (to-pg-value value)) (toObject [oid value] (when value - (let [val (from-pg-value oid value)] - (if (= ::raw-value val) - (proxy-call-with-super #(.toObject ^DataConverter this oid value) - this "toObject") - val)))) - (fromConvertable [value] - (to-pg-value value)))) + (let [val (from-pg-value oid value) + this ^DataConverter this] + (if-not (= ::raw-value val) + val + (proxy-super toObject oid value))))))) (defn open-db "Creates a db connection pool" diff --git a/src/postgres/async/impl.clj b/src/postgres/async/impl.clj index 435f55e..924b9bc 100644 --- a/src/postgres/async/impl.clj +++ b/src/postgres/async/impl.clj @@ -22,12 +22,8 @@ (vec (map column->value value)) value)) -;; TODO: make columns public in the Java driver (defn- get-columns [^PgRow row] - (-> (doto (.getDeclaredField PgRow "columns") - (.setAccessible true)) - (.get row) - (keys))) + (keys (.getColumns row))) (defn- row->map [^PgRow row ^Object rowmap ^String col] (assoc rowmap