File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 66 [com.github.pgasync.impl.conversion DataConverter]))
77
88(defmulti from-pg-value (fn [oid value] oid))
9+ (defmethod from-pg-value :default [oid value] ::raw-value )
10+
911(defprotocol IPgParameter
1012 (to-pg-value [value]))
1113
1214(defn- create-converter []
1315 (proxy [DataConverter] []
14- (toConvertable [oid value]
15- (from-pg-value oid value))
16+ (toObject [oid value]
17+ (when value
18+ (let [val (from-pg-value oid value)]
19+ (if (= ::raw-value val)
20+ (proxy-call-with-super #(.toObject ^DataConverter this oid value)
21+ this " toObject" )
22+ val))))
1623 (fromConvertable [value]
1724 (to-pg-value value))))
1825
Original file line number Diff line number Diff line change 6666 (is (instance? SqlException (<!! c)))
6767 (is (nil? (<!! c)))))
6868
69+ (deftest query-for-overridden-types
70+
71+ (defmethod from-pg-value com.github.pgasync.impl.Oid /TIMESTAMP [oid ^bytes value]
72+ (String. value " utf-8" ))
73+
74+ (testing " timestamp can be returned as string"
75+ (let [c (query-rows! *db* [" select $1::TIMESTAMP as ts"
76+ " 2016-05-01T12:00:00.001" ])]
77+ (is (= {:ts " 2016-05-01 12:00:00.001" } (<!! c)))))
78+
79+ (testing " unsupported type throws an exception"
80+ (let [c (query-rows! *db* [" select '<x/>'::xml" ])
81+ ^Throwable ex (<!! c)]
82+ (is (= " Unknown conversion source: XML" (.getMessage ex))))))
83+
6984(deftest inserts
7085
7186 (testing " insert returns row count"
You can’t perform that action at this time.
0 commit comments