Merge pull request #108 from MichaelBlume/maps-records
prevent records from being treated as maps
This commit is contained in:
commit
61cd800aa2
2 changed files with 18 additions and 1 deletions
|
|
@ -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#)))
|
||||
|
|
|
|||
|
|
@ -153,3 +153,15 @@
|
|||
{:param1 param1
|
||||
:param2 param2
|
||||
:param3 param3})))))
|
||||
|
||||
(deftest test-raw
|
||||
(is (= ["SELECT 1 + 1 FROM foo"]
|
||||
(-> (select (sql/raw "1 + 1"))
|
||||
(from :foo)
|
||||
sql/format))))
|
||||
|
||||
(deftest test-call
|
||||
(is (= ["SELECT min(?) FROM ?" "time" "table"]
|
||||
(-> (select (sql/call :min "time"))
|
||||
(from "table")
|
||||
sql/format))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue