Updated SqlCall to support quoted function calls.
Added test to check if a quoted call is actually quoted.
This commit is contained in:
parent
43df955a86
commit
780fa126b5
4 changed files with 19 additions and 6 deletions
|
|
@ -7,6 +7,7 @@
|
|||
[clojure.string :as string]))
|
||||
|
||||
(defalias call types/call)
|
||||
(defalias call-quoted types/call-quoted)
|
||||
(defalias raw types/raw)
|
||||
(defalias param types/param)
|
||||
(defalias format format/format)
|
||||
|
|
|
|||
|
|
@ -312,9 +312,9 @@
|
|||
SqlCall
|
||||
(to-sql [x]
|
||||
(binding [*fn-context?* true]
|
||||
(let [fn-name (name (.-name x))
|
||||
fn-name (fn-aliases fn-name fn-name)]
|
||||
(apply fn-handler fn-name (.-args x)))))
|
||||
(let [quoted? (.-quoted? x)
|
||||
fn-name ((if quoted? to-sql name) (.-name x))]
|
||||
(apply fn-handler (fn-aliases fn-name fn-name) (.-args x)))))
|
||||
SqlRaw
|
||||
(to-sql [x] (.-s x))
|
||||
clojure.lang.IPersistentMap
|
||||
|
|
|
|||
|
|
@ -1,18 +1,24 @@
|
|||
(ns honeysql.types)
|
||||
|
||||
(defrecord SqlCall [name args])
|
||||
(defrecord SqlCall [name args quoted?])
|
||||
|
||||
(defn call
|
||||
"Represents a SQL function call. Name should be a keyword."
|
||||
[name & args]
|
||||
(SqlCall. name args))
|
||||
(SqlCall. name args false))
|
||||
|
||||
(defn call-quoted
|
||||
"Represents a SQL function call that must be quoted. Like the normal SqlCall
|
||||
the name should be a keyword."
|
||||
[name & args] (SqlCall. name args true))
|
||||
|
||||
(defn read-sql-call [form]
|
||||
;; late bind so that we get new class on REPL reset
|
||||
(apply (resolve `call) form))
|
||||
|
||||
(defmethod print-method SqlCall [^SqlCall o ^java.io.Writer w]
|
||||
(.write w (str "#sql/call " (pr-str (into [(.-name o)] (.-args o))))))
|
||||
(.write w (str "#sql/call" (when (.-quoted? o) "-quoted")
|
||||
" " (pr-str (into [(.-name o)] (.-args o))))))
|
||||
|
||||
(defmethod print-dup SqlCall [o w]
|
||||
(print-method o w))
|
||||
|
|
|
|||
|
|
@ -166,6 +166,12 @@
|
|||
(from "table")
|
||||
sql/format))))
|
||||
|
||||
(deftest test-quoted-call
|
||||
(is (= ["SELECT \"foo\".\"bar\"(1, 2, 3)"]
|
||||
(sql/format
|
||||
{:select [(sql/call-quoted :foo.bar 1 2 3)]}
|
||||
:quoting :ansi))))
|
||||
|
||||
(deftest join-test
|
||||
(testing "nil join"
|
||||
(is (= ["SELECT * FROM foo INNER JOIN x ON foo.id = x.id INNER JOIN y"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue