Refactor format-values to do fewer allocations

This commit is contained in:
Oleksandr Yakushev 2025-01-08 17:55:21 +02:00
parent 3ecac63bea
commit d086631e54
2 changed files with 31 additions and 31 deletions

View file

@ -1,7 +1,7 @@
# Changes # Changes
* 2.6.next in progress * 2.6.next in progress
* More performance optimizations via PR [#560](https://github.com/seancorfield/honeysql/pull/560) [@alexander-yakushev](https://github.com/alexander-yakushev). * More performance optimizations via PRs [#560](https://github.com/seancorfield/honeysql/pull/560) and [#562](https://github.com/seancorfield/honeysql/pull/562) [@alexander-yakushev](https://github.com/alexander-yakushev).
* Fix two broken links to the [HoneySQL web app](https://john.shaffe.rs/honeysql/) via PR [#559](https://github.com/seancorfield/honeysql/pull/559) [@whatacold](https://github.com/whatacold). * Fix two broken links to the [HoneySQL web app](https://john.shaffe.rs/honeysql/) via PR [#559](https://github.com/seancorfield/honeysql/pull/559) [@whatacold](https://github.com/whatacold).
* Make SQL Server dialect auto-lift Boolean values to parameters since SQL Server has no `TRUE` / `FALSE` literals. * Make SQL Server dialect auto-lift Boolean values to parameters since SQL Server has no `TRUE` / `FALSE` literals.

View file

@ -1177,17 +1177,17 @@
x)) x))
xs))) xs)))
[sqls params] [sqls params]
(reduce (fn [[sql params] [sqls' params']] (reduce (fn [[sql params] x]
[(conj sql (if (sequential? x)
(if (sequential? sqls') (let [[sqls' params'] (format-expr-list x)]
(str "(" (join ", " sqls') ")") [(conj sql
sqls')) (if (sequential? sqls')
(into params params')]) (str "(" (join ", " sqls') ")")
sqls'))
(into* params params')])
[(conj sql (sql-kw x)) params]))
[[] []] [[] []]
(map #(if (sequential? %) xs')
(format-expr-list %)
[(sql-kw %)])
xs'))
sqls (if row-ctr (map #(str "ROW" %) sqls) sqls)] sqls (if row-ctr (map #(str "ROW" %) sqls) sqls)]
(into [(str (sql-kw k) " " (join ", " sqls))] params)) (into [(str (sql-kw k) " " (join ", " sqls))] params))
@ -1199,26 +1199,26 @@
(contains-clause? :replace-into) (contains-clause? :replace-into)
(contains-clause? :columns))) (contains-clause? :columns)))
[sqls params] [sqls params]
(reduce (fn [[sql params] [sqls' params']] (reduce
[(conj sql (fn [[sql params] x]
(if (sequential? sqls') (if (map? x)
(str "(" (join ", " sqls') ")") (let [[sqls' params']
sqls')) (reduce-sql (map #(format-expr
(if params' (into params params') params')]) (get x %
[[] []] ;; issue #366: use NULL or DEFAULT
(map (fn [m] ;; for missing column values:
(if (map? m) (if (contains? *values-default-columns* %)
(format-expr-list [:default]
(map #(get m nil))))
% cols)]
;; issue #366: use NULL or DEFAULT [(conj sql
;; for missing column values: (if (sequential? sqls')
(if (contains? *values-default-columns* %) (str "(" (join ", " sqls') ")")
[:default] sqls'))
nil)) (into* params params')])
cols)) [(conj sql (sql-kw x)) params]))
[(sql-kw m)])) [[] []]
xs))] xs)]
(into [(str (when cols-sql (into [(str (when cols-sql
(str cols-sql " ")) (str cols-sql " "))
(sql-kw k) (sql-kw k)