From 06c97376ef97d5302a1b3476205e02c21b013cbc Mon Sep 17 00:00:00 2001 From: Michael Blume Date: Tue, 9 Feb 2016 12:02:17 -0800 Subject: [PATCH] prevent records from being treated as maps Thanks to @djwhitt and @blinsay for reporting and for providing test cases. Fixes #106 --- src/honeysql/helpers.clj | 7 ++++++- test/honeysql/core_test.clj | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/honeysql/helpers.clj b/src/honeysql/helpers.clj index a9825b3..3cf7a5f 100644 --- a/src/honeysql/helpers.clj +++ b/src/honeysql/helpers.clj @@ -7,12 +7,17 @@ (defmethod build-clause :default [_ m & args] m) +(defn plain-map? [m] + (and + (map? m) + (not (instance? clojure.lang.IRecord m)))) + (defmacro defhelper [helper arglist & more] (let [kw (keyword (name helper))] `(do (defmethod build-clause ~kw ~(into ['_] arglist) ~@more) (doto (defn ~helper [& args#] - (let [[m# args#] (if (map? (first args#)) + (let [[m# args#] (if (plain-map? (first args#)) [(first args#) (rest args#)] [{} args#])] (build-clause ~kw m# args#))) diff --git a/test/honeysql/core_test.clj b/test/honeysql/core_test.clj index f0ec2b1..299d90b 100644 --- a/test/honeysql/core_test.clj +++ b/test/honeysql/core_test.clj @@ -155,13 +155,13 @@ :param3 param3}))))) (deftest test-raw - (is (= ["1 + 1"] + (is (= ["SELECT 1 + 1 FROM foo"] (-> (select (sql/raw "1 + 1")) (from :foo) sql/format)))) (deftest test-call - (is (= ["min(?)" "time"] + (is (= ["SELECT min(?) FROM ?" "time" "table"] (-> (select (sql/call :min "time")) (from "table") sql/format))))