Merge dc13677b4b into f23d687423
This commit is contained in:
commit
89accb665f
6 changed files with 31 additions and 6 deletions
|
|
@ -9,6 +9,8 @@
|
||||||
* Add support for INTERSECT (@jakemcc)
|
* Add support for INTERSECT (@jakemcc)
|
||||||
* Upgrade Clojure dependency (@michaelblume)
|
* Upgrade Clojure dependency (@michaelblume)
|
||||||
|
|
||||||
|
* Added support for quoted database function calls. (@jrdoane)
|
||||||
|
|
||||||
## 0.6.3
|
## 0.6.3
|
||||||
|
|
||||||
Fix bug when SqlCall/SqlRaw object is first argument to another helper (@MichaelBlume)
|
Fix bug when SqlCall/SqlRaw object is first argument to another helper (@MichaelBlume)
|
||||||
|
|
|
||||||
10
README.md
10
README.md
|
|
@ -249,6 +249,16 @@ To be able to use dashes in quoted names, you can pass ```:allow-dashed-names tr
|
||||||
=> ["SELECT \"f\".\"foo-id\", \"f\".\"foo-name\" FROM \"foo-bar\" \"f\" WHERE \"f\".\"foo-id\" = 12345"]
|
=> ["SELECT \"f\".\"foo-id\", \"f\".\"foo-name\" FROM \"foo-bar\" \"f\" WHERE \"f\".\"foo-id\" = 12345"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
In some cases, you may want to quote function calls. To do this, you can use the
|
||||||
|
```sql/call-quoted``` function instead of the ```sql/call``` function.
|
||||||
|
|
||||||
|
```clj
|
||||||
|
(sql/format
|
||||||
|
{:select (sql/quoted-call :my-schema.some-function 1 2 3)}
|
||||||
|
:quoting :ansi :allow-quoted-names? true)
|
||||||
|
=> ["SELECT \"my-schema\".\"some-function\"(1, 2, 3)"]
|
||||||
|
```
|
||||||
|
|
||||||
Here's a big, complicated query. Note that Honey SQL makes no attempt to verify that your queries make any sense. It merely renders surface syntax.
|
Here's a big, complicated query. Note that Honey SQL makes no attempt to verify that your queries make any sense. It merely renders surface syntax.
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
[clojure.string :as string]))
|
[clojure.string :as string]))
|
||||||
|
|
||||||
(defalias call types/call)
|
(defalias call types/call)
|
||||||
|
(defalias call-quoted types/call-quoted)
|
||||||
(defalias raw types/raw)
|
(defalias raw types/raw)
|
||||||
(defalias param types/param)
|
(defalias param types/param)
|
||||||
(defalias format format/format)
|
(defalias format format/format)
|
||||||
|
|
|
||||||
|
|
@ -310,9 +310,9 @@
|
||||||
SqlCall
|
SqlCall
|
||||||
(to-sql [x]
|
(to-sql [x]
|
||||||
(binding [*fn-context?* true]
|
(binding [*fn-context?* true]
|
||||||
(let [fn-name (name (.-name x))
|
(let [quoted? (.-quoted? x)
|
||||||
fn-name (fn-aliases fn-name fn-name)]
|
fn-name ((if quoted? to-sql name) (.-name x))]
|
||||||
(apply fn-handler fn-name (.-args x)))))
|
(apply fn-handler (fn-aliases fn-name fn-name) (.-args x)))))
|
||||||
SqlRaw
|
SqlRaw
|
||||||
(to-sql [x] (.-s x))
|
(to-sql [x] (.-s x))
|
||||||
clojure.lang.IPersistentMap
|
clojure.lang.IPersistentMap
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,24 @@
|
||||||
(ns honeysql.types)
|
(ns honeysql.types)
|
||||||
|
|
||||||
(defrecord SqlCall [name args])
|
(defrecord SqlCall [name args quoted?])
|
||||||
|
|
||||||
(defn call
|
(defn call
|
||||||
"Represents a SQL function call. Name should be a keyword."
|
"Represents a SQL function call. Name should be a keyword."
|
||||||
[name & args]
|
[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]
|
(defn read-sql-call [form]
|
||||||
;; late bind so that we get new class on REPL reset
|
;; late bind so that we get new class on REPL reset
|
||||||
(apply (resolve `call) form))
|
(apply (resolve `call) form))
|
||||||
|
|
||||||
(defmethod print-method SqlCall [^SqlCall o ^java.io.Writer w]
|
(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]
|
(defmethod print-dup SqlCall [o w]
|
||||||
(print-method o w))
|
(print-method o w))
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,12 @@
|
||||||
(from "table")
|
(from "table")
|
||||||
sql/format))))
|
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
|
(deftest join-test
|
||||||
(testing "nil join"
|
(testing "nil join"
|
||||||
(is (= ["SELECT * FROM foo INNER JOIN x ON foo.id = x.id INNER JOIN y"]
|
(is (= ["SELECT * FROM foo INNER JOIN x ON foo.id = x.id INNER JOIN y"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue