From 9cc0577214d375f8432a675c7d427f1b2c9ce854 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Fri, 25 Sep 2020 15:09:44 -0700 Subject: [PATCH] Change (supposedly) opaque wrapper used by next.jdbc.types/as-* fns --- CHANGELOG.md | 1 + src/next/jdbc/types.clj | 8 ++++---- test/next/jdbc/types_test.clj | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faf132e..acb3b98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Only accretive/fixative changes will be made from now on. * 1.1.next in progress * Fix #140 by adding `"duckdb"` to `next.jdbc.connection/dbtypes`. + * Change `next.jdbc.types/as-*` functions to use a thunk instead of a vector to convey metadata, so that wrapped values do not get unpacked by HoneySQL. ## Stable Builds diff --git a/src/next/jdbc/types.clj b/src/next/jdbc/types.clj index 8dcb1e8..23ffa27 100644 --- a/src/next/jdbc/types.clj +++ b/src/next/jdbc/types.clj @@ -25,13 +25,13 @@ (str/lower-case) (str/replace "_" "-"))))] `(defn ~as-n - ~(str "Wrap a Clojure value in a vector with metadata to implement `set-parameter` + ~(str "Wrap a Clojure value in a thunk with metadata to implement `set-parameter` so that `.setObject()` is called with the `java.sql.Types/" n "` SQL type.") [~'obj] - (with-meta [~'obj] + (with-meta (constantly ~'obj) {'next.jdbc.prepare/set-parameter - (fn [[v#] ^PreparedStatement s# ^long i#] - (.setObject s# i# v# ~(symbol "java.sql.Types" n)))}))))))) + (fn [vf# ^PreparedStatement s# ^long i#] + (.setObject s# i# (vf#) ~(symbol "java.sql.Types" n)))}))))))) (all-types) diff --git a/test/next/jdbc/types_test.clj b/test/next/jdbc/types_test.clj index d3706ae..ba36a0c 100644 --- a/test/next/jdbc/types_test.clj +++ b/test/next/jdbc/types_test.clj @@ -2,13 +2,13 @@ (ns next.jdbc.types-test "Some tests for the type-assist functions." - (:require [clojure.test :refer [deftest is testing]] + (:require [clojure.test :refer [deftest is]] [next.jdbc.types :refer [as-varchar]])) (set! *warn-on-reflection* true) (deftest as-varchar-test (let [v (as-varchar "Hello")] - (is (= ["Hello"] v)) + (is (= "Hello" (v))) (is (contains? (meta v) 'next.jdbc.prepare/set-parameter)) (is (fn? (get (meta v) 'next.jdbc.prepare/set-parameter)))))