Fixes #294 by applying inline everywhere
This commit is contained in:
parent
645ce897c5
commit
38da6f567b
1 changed files with 29 additions and 18 deletions
|
|
@ -145,6 +145,14 @@
|
||||||
(defn- namespace-_ [x] (some-> (namespace x) (str/replace "-" "_")))
|
(defn- namespace-_ [x] (some-> (namespace x) (str/replace "-" "_")))
|
||||||
(defn- name-_ [x] (str/replace (name x) "-" "_"))
|
(defn- name-_ [x] (str/replace (name x) "-" "_"))
|
||||||
|
|
||||||
|
(defn- sqlize-value [x]
|
||||||
|
(cond
|
||||||
|
(nil? x) "NULL"
|
||||||
|
(string? x) (str \' (str/replace x "'" "''") \')
|
||||||
|
(symbol? x) (sql-kw x)
|
||||||
|
(keyword? x) (sql-kw x)
|
||||||
|
:else (str x)))
|
||||||
|
|
||||||
(defn format-entity
|
(defn format-entity
|
||||||
"Given a simple SQL entity (a keyword or symbol -- or string),
|
"Given a simple SQL entity (a keyword or symbol -- or string),
|
||||||
return the equivalent SQL fragment (as a string -- no parameters).
|
return the equivalent SQL fragment (as a string -- no parameters).
|
||||||
|
|
@ -166,15 +174,16 @@
|
||||||
t
|
t
|
||||||
(str (q t) "."))))
|
(str (q t) "."))))
|
||||||
|
|
||||||
(defn- ->param [k]
|
(defn- param-value [k]
|
||||||
(with-meta (constantly k)
|
|
||||||
{::wrapper
|
|
||||||
(fn [fk _]
|
|
||||||
(let [k (fk)]
|
|
||||||
(if (contains? *params* k)
|
(if (contains? *params* k)
|
||||||
(get *params* k)
|
(get *params* k)
|
||||||
(throw (ex-info (str "missing parameter value for " k)
|
(throw (ex-info (str "missing parameter value for " k)
|
||||||
{:params (keys *params*)})))))}))
|
{:params (keys *params*)}))))
|
||||||
|
|
||||||
|
(defn- ->param [k]
|
||||||
|
(with-meta (constantly k)
|
||||||
|
{::wrapper
|
||||||
|
(fn [fk _] (param-value (fk)))}))
|
||||||
|
|
||||||
(defn- format-var [x & [opts]]
|
(defn- format-var [x & [opts]]
|
||||||
(let [c (name-_ x)]
|
(let [c (name-_ x)]
|
||||||
|
|
@ -183,7 +192,10 @@
|
||||||
;; TODO: this does not quote arguments -- does that matter?
|
;; TODO: this does not quote arguments -- does that matter?
|
||||||
[(str (upper-case f) "(" (str/join "," args) ")")])
|
[(str (upper-case f) "(" (str/join "," args) ")")])
|
||||||
(= \? (first c))
|
(= \? (first c))
|
||||||
["?" (->param (keyword (subs c 1)))]
|
(let [k (keyword (subs c 1))]
|
||||||
|
(if *inline*
|
||||||
|
[(sqlize-value (param-value k))]
|
||||||
|
["?" (->param k)]))
|
||||||
:else
|
:else
|
||||||
[(format-entity x opts)])))
|
[(format-entity x opts)])))
|
||||||
|
|
||||||
|
|
@ -701,14 +713,6 @@
|
||||||
(def ^:private op-ignore-nil (atom #{:and :or}))
|
(def ^:private op-ignore-nil (atom #{:and :or}))
|
||||||
(def ^:private op-variadic (atom #{:and :or :+ :* :||}))
|
(def ^:private op-variadic (atom #{:and :or :+ :* :||}))
|
||||||
|
|
||||||
(defn- sqlize-value [x]
|
|
||||||
(cond
|
|
||||||
(nil? x) "NULL"
|
|
||||||
(string? x) (str \' (str/replace x "'" "''") \')
|
|
||||||
(symbol? x) (sql-kw x)
|
|
||||||
(keyword? x) (sql-kw x)
|
|
||||||
:else (str x)))
|
|
||||||
|
|
||||||
(defn- unwrap [x opts]
|
(defn- unwrap [x opts]
|
||||||
(if-let [m (meta x)]
|
(if-let [m (meta x)]
|
||||||
(if-let [f (::wrapper m)]
|
(if-let [f (::wrapper m)]
|
||||||
|
|
@ -821,8 +825,13 @@
|
||||||
(into [(str "INTERVAL " sql " " (sql-kw units))] params)))
|
(into [(str "INTERVAL " sql " " (sql-kw units))] params)))
|
||||||
:lift
|
:lift
|
||||||
(fn [_ [x]]
|
(fn [_ [x]]
|
||||||
|
(if *inline*
|
||||||
|
;; this is pretty much always going to be wrong,
|
||||||
|
;; but it could produce a valid result so we just
|
||||||
|
;; assume that the user knows what they are doing:
|
||||||
|
[(sqlize-value x)]
|
||||||
["?" (with-meta (constantly x)
|
["?" (with-meta (constantly x)
|
||||||
{::wrapper (fn [fx _] (fx))})])
|
{::wrapper (fn [fx _] (fx))})]))
|
||||||
:nest
|
:nest
|
||||||
(fn [_ [x]]
|
(fn [_ [x]]
|
||||||
(format-expr x {:nested true}))
|
(format-expr x {:nested true}))
|
||||||
|
|
@ -846,7 +855,9 @@
|
||||||
(into [(str/join ", " sqls)] params)))
|
(into [(str/join ", " sqls)] params)))
|
||||||
:param
|
:param
|
||||||
(fn [_ [k]]
|
(fn [_ [k]]
|
||||||
["?" (->param k)])
|
(if *inline*
|
||||||
|
[(sqlize-value (param-value k))]
|
||||||
|
["?" (->param k)]))
|
||||||
:raw
|
:raw
|
||||||
(fn [_ [s]]
|
(fn [_ [s]]
|
||||||
(if (sequential? s)
|
(if (sequential? s)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue