prevent records from being treated as maps

Thanks to @djwhitt and @blinsay for reporting and for providing
test cases.

Fixes #106
This commit is contained in:
Michael Blume 2016-02-09 12:02:17 -08:00
parent f8a2eedf45
commit 06c97376ef
2 changed files with 8 additions and 3 deletions

View file

@ -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#)))

View file

@ -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))))