Improve :inline/:raw
Note: these are still in flux!
This commit is contained in:
parent
b762a514b6
commit
273732089b
2 changed files with 9 additions and 6 deletions
|
|
@ -473,8 +473,8 @@
|
||||||
(cond
|
(cond
|
||||||
(nil? x) "NULL"
|
(nil? x) "NULL"
|
||||||
(string? x) (str \' (str/replace x "'" "''") \')
|
(string? x) (str \' (str/replace x "'" "''") \')
|
||||||
(symbol? x) (name-_ x)
|
(symbol? x) (sql-kw x)
|
||||||
(keyword? x) (name-_ x)
|
(keyword? x) (sql-kw x)
|
||||||
:else (str x)))
|
:else (str x)))
|
||||||
|
|
||||||
(def ^:private special-syntax
|
(def ^:private special-syntax
|
||||||
|
|
@ -525,7 +525,9 @@
|
||||||
["DEFAULT"])
|
["DEFAULT"])
|
||||||
:inline
|
:inline
|
||||||
(fn [_ [x]]
|
(fn [_ [x]]
|
||||||
[(sqlize-value x)])
|
(if (sequential? x)
|
||||||
|
[(str/join " " (map #'sqlize-value x))]
|
||||||
|
[(sqlize-value x)]))
|
||||||
:interval
|
:interval
|
||||||
(fn [_ [n units]]
|
(fn [_ [n units]]
|
||||||
(let [[sql & params] (format-expr n)]
|
(let [[sql & params] (format-expr n)]
|
||||||
|
|
@ -544,9 +546,10 @@
|
||||||
(fn [_ [k]]
|
(fn [_ [k]]
|
||||||
["?" (->param k)])
|
["?" (->param k)])
|
||||||
:raw
|
:raw
|
||||||
;; TODO: only supports single raw string right now
|
|
||||||
(fn [_ [s]]
|
(fn [_ [s]]
|
||||||
[s])}))
|
(if (sequential? s)
|
||||||
|
[(str/join " " s)]
|
||||||
|
[s]))}))
|
||||||
|
|
||||||
(defn format-expr [x & [{:keys [nested?] :as opts}]]
|
(defn format-expr [x & [{:keys [nested?] :as opts}]]
|
||||||
(cond (or (keyword? x) (symbol? x))
|
(cond (or (keyword? x) (symbol? x))
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,7 @@
|
||||||
(format {:dialect :mysql})))))
|
(format {:dialect :mysql})))))
|
||||||
|
|
||||||
(deftest inlined-values-are-stringified-correctly
|
(deftest inlined-values-are-stringified-correctly
|
||||||
(is (= ["SELECT 'foo', 'It''s a quote!', bar, NULL"]
|
(is (= ["SELECT 'foo', 'It''s a quote!', BAR, NULL"]
|
||||||
(format {:select [[[:inline "foo"]]
|
(format {:select [[[:inline "foo"]]
|
||||||
[[:inline "It's a quote!"]]
|
[[:inline "It's a quote!"]]
|
||||||
[[:inline :bar]]
|
[[:inline :bar]]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue