Merge branch 'develop' into opt

This commit is contained in:
Sean Corfield 2025-01-16 23:52:40 +00:00 committed by GitHub
commit 1681764830
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View file

@ -1,6 +1,7 @@
# Changes # Changes
* 2.6.next in progress * 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 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). * 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

@ -944,7 +944,7 @@
(map (map
(fn [[x expr & tail :as with]] (fn [[x expr & tail :as with]]
(let [[sql & params] (format-with-part x) (let [[sql & params] (format-with-part x)
non-query-expr? (or (ident? expr) (string? expr)) non-query-expr? (not (map? expr))
[sql' & params'] (if non-query-expr? [sql' & params'] (if non-query-expr?
(format-expr expr) (format-expr expr)
(format-dsl expr)) (format-dsl expr))

View file

@ -221,7 +221,26 @@
:from [:hits :stuff] :from [:hits :stuff]
:where [:= :EventDate :ts_upper_bound]}) :where [:= :EventDate :ts_upper_bound]})
["WITH ? AS ts_upper_bound, stuff AS (SELECT * FROM songs) SELECT * FROM hits, stuff WHERE EventDate = ts_upper_bound" ["WITH ? AS ts_upper_bound, stuff AS (SELECT * FROM songs) SELECT * FROM hits, stuff WHERE EventDate = ts_upper_bound"
"2019-08-01 15:23:00"])))) "2019-08-01 15:23:00"])))
(testing "Use expression in a WITH clause"
(is (= (format
{:with [[:s [:sum :bytes]]]
:select [:s]
:from [:table]})
["WITH SUM(bytes) AS s SELECT s FROM table"]))
(is (= (format
{:with [[:v [:raw "m['k']"]]]
:select [:v]
:from [:table]})
["WITH m['k'] AS v SELECT v FROM table"]))
(is (= (format
{:with [[:cond [:and [:= :a 1] [:= :b 2] [:= :c 3]]]]
:select [:v]
:from [:table]
:where :cond})
["WITH (a = ?) AND (b = ?) AND (c = ?) AS cond SELECT v FROM table WHERE cond" 1 2 3]))))
(deftest insert-into (deftest insert-into
(is (= (format {:insert-into :foo}) (is (= (format {:insert-into :foo})