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:
parent
f8a2eedf45
commit
06c97376ef
2 changed files with 8 additions and 3 deletions
|
|
@ -7,12 +7,17 @@
|
||||||
(defmethod build-clause :default [_ m & args]
|
(defmethod build-clause :default [_ m & args]
|
||||||
m)
|
m)
|
||||||
|
|
||||||
|
(defn plain-map? [m]
|
||||||
|
(and
|
||||||
|
(map? m)
|
||||||
|
(not (instance? clojure.lang.IRecord m))))
|
||||||
|
|
||||||
(defmacro defhelper [helper arglist & more]
|
(defmacro defhelper [helper arglist & more]
|
||||||
(let [kw (keyword (name helper))]
|
(let [kw (keyword (name helper))]
|
||||||
`(do
|
`(do
|
||||||
(defmethod build-clause ~kw ~(into ['_] arglist) ~@more)
|
(defmethod build-clause ~kw ~(into ['_] arglist) ~@more)
|
||||||
(doto (defn ~helper [& args#]
|
(doto (defn ~helper [& args#]
|
||||||
(let [[m# args#] (if (map? (first args#))
|
(let [[m# args#] (if (plain-map? (first args#))
|
||||||
[(first args#) (rest args#)]
|
[(first args#) (rest args#)]
|
||||||
[{} args#])]
|
[{} args#])]
|
||||||
(build-clause ~kw m# args#)))
|
(build-clause ~kw m# args#)))
|
||||||
|
|
|
||||||
|
|
@ -155,13 +155,13 @@
|
||||||
:param3 param3})))))
|
:param3 param3})))))
|
||||||
|
|
||||||
(deftest test-raw
|
(deftest test-raw
|
||||||
(is (= ["1 + 1"]
|
(is (= ["SELECT 1 + 1 FROM foo"]
|
||||||
(-> (select (sql/raw "1 + 1"))
|
(-> (select (sql/raw "1 + 1"))
|
||||||
(from :foo)
|
(from :foo)
|
||||||
sql/format))))
|
sql/format))))
|
||||||
|
|
||||||
(deftest test-call
|
(deftest test-call
|
||||||
(is (= ["min(?)" "time"]
|
(is (= ["SELECT min(?) FROM ?" "time" "table"]
|
||||||
(-> (select (sql/call :min "time"))
|
(-> (select (sql/call :min "time"))
|
||||||
(from "table")
|
(from "table")
|
||||||
sql/format))))
|
sql/format))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue