Format sequential values as full SQL expressions

This commit is contained in:
Sean Corfield 2020-10-12 11:33:18 -07:00
parent 2decf35072
commit ccd5447a09
2 changed files with 8 additions and 4 deletions

View file

@ -511,7 +511,7 @@ RIGHT JOIN bock ON bock.z = c.e
WHERE ((f.a = ?) AND (b.baz <> ?)) OR ((? < ?) AND (? < ?)) OR (f.e IN (?, ?, ?)) OR f.e BETWEEN ? AND ? WHERE ((f.a = ?) AND (b.baz <> ?)) OR ((? < ?) AND (? < ?)) OR (f.e IN (?, ?, ?)) OR f.e BETWEEN ? AND ?
GROUP BY f.a, c.e GROUP BY f.a, c.e
HAVING ? < f.e HAVING ? < f.e
ORDER BY b.baz DESC, c.quux, f.a NULLS FIRST ORDER BY b.baz DESC, c.quux ASC, f.a NULLS FIRST
LIMIT ? LIMIT ?
OFFSET ? OFFSET ?
" "

View file

@ -619,9 +619,8 @@
(str " " (first sqls)) (str " " (first sqls))
(str "(" (str/join ", " sqls) ")")))] (str "(" (str/join ", " sqls) ")")))]
params))) params)))
(if *inline* (let [[sqls params] (format-expr-list x)]
[(str "(" (str/join ", " (map #'sqlize-value x)) ")")] (into [(str "(" (str/join ", " sqls) ")")] params))))
(into [(str "(" (str/join ", " (repeat (count x) "?")) ")")] x))))
(or (true? x) (false? x)) ; because (boolean? x) requires Clojure 1.9+ (or (true? x) (false? x)) ; because (boolean? x) requires Clojure 1.9+
[(upper-case (str x))] [(upper-case (str x))]
@ -760,4 +759,9 @@
{:dialect :mysql})) {:dialect :mysql}))
(println (format {:select [:*] :from [:table] (println (format {:select [:*] :from [:table]
:where [:in :id [1 2 3 4]]} {:pretty? true})) :where [:in :id [1 2 3 4]]} {:pretty? true}))
(println (format {:select [:*] :from [:table]
:where [:and [:in :id [1 [:param :foo]]]
[:= :bar [:param :quux]]]}
{:params {:foo 42 :quux 13}
:pretty? true}))
,) ,)