Skip to content

Commit

Permalink
Merge pull request #562 from alexander-yakushev/opt
Browse files Browse the repository at this point in the history
More small optimizations
  • Loading branch information
seancorfield authored Jan 17, 2025
2 parents 4f5b0ed + 30a0497 commit 3beaa6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

* 2.6.next in progress
* Support expressions in `WITH` clauses via PR [#563](https://github.com/seancorfield/honeysql/pull/563) [@krevedkokun](https://github.com/krevedkokun).
* 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).
* Make SQL Server dialect auto-lift Boolean values to parameters since SQL Server has no `TRUE` / `FALSE` literals.
* Fix bug in `DEFAULT` values clause (that omitted some values).
Expand Down
63 changes: 32 additions & 31 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@
Hyphens at the start or end of a string should not be touched."
[s]
(str/replace s #"(\w)-(?=\w)" "$1 "))
(cond-> s
(str/includes? s "-") (str/replace #"(\w)-(?=\w)" "$1 ")))

(defn- namespace-_
"Return the namespace portion of a symbol, with dashes converted."
Expand Down Expand Up @@ -1176,17 +1177,17 @@
x))
xs)))
[sqls params]
(reduce (fn [[sql params] [sqls' params']]
[(conj sql
(if (sequential? sqls')
(str "(" (join ", " sqls') ")")
sqls'))
(into params params')])
(reduce (fn [[sql params] x]
(if (sequential? x)
(let [[sqls' params'] (format-expr-list x)]
[(conj sql
(if (sequential? sqls')
(str "(" (join ", " sqls') ")")
sqls'))
(into* params params')])
[(conj sql (sql-kw x)) params]))
[[] []]
(map #(if (sequential? %)
(format-expr-list %)
[(sql-kw %)])
xs'))
xs')
sqls (if row-ctr (map #(str "ROW" %) sqls) sqls)]
(into [(str (sql-kw k) " " (join ", " sqls))] params))

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

0 comments on commit 3beaa6b

Please # to comment.