From 3ca197b45ca223e2d990f6fb81faae8c95bf8c4f Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 28 Sep 2024 14:47:15 -0700 Subject: [PATCH] tentative impl of VALUES statement in MySQL #544 Signed-off-by: Sean Corfield --- CHANGELOG.md | 1 + src/honey/sql.cljc | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d6dc5..a305255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * 2.6.next in progress * Performance optimizations via PRs [#545](https://github.com/seancorfield/honeysql/pull/545) and [#546](https://github.com/seancorfield/honeysql/pull/546) [@alexander-yakushev](https://github.com/alexander-yakushev). + * Address [#544](https://github.com/seancorfield/honeysql/issues/544) by adding support for MySQL's `VALUES ROW(..)` syntax. Docs TBD. * Fix [#543](https://github.com/seancorfield/honeysql/issues/543) by supporting both symbols and keywords in named parameters. * Address [#541](https://github.com/seancorfield/honeysql/issues/541) by specifying the expected result of a formatter function passed to `register-clause!` and adding the example from the README to **Extending HoneySQL**. * Getting Started updated based on feedback from Los Angeles Clojure meetup walkthrough [#539](https://github.com/seancorfield/honeysql/issues/539). diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index b8a1411..9422cb6 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -1059,7 +1059,9 @@ ")"))])))) (defn- format-values [k xs] - (let [first-xs (when (sequential? xs) (first (drop-while ident? xs)))] + (let [first-xs (when (sequential? xs) (first (drop-while ident? xs))) + row-ctr (and (sequential? xs) (contains? #{:row 'rows} (first xs))) + xs (if row-ctr (rest xs) xs)] (cond (and (ident? xs) (contains? #{:default 'default} xs)) [(str (sql-kw xs) " " (sql-kw k))] (empty? xs) @@ -1087,7 +1089,8 @@ (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)) (map? first-xs) @@ -2364,6 +2367,7 @@ (format-expr 1) (format {:select [:a [:b :c] [[:d :e]] [[:f :g] :h]]}) (format {:select [[[:d :e]] :a [:b :c]]}) + (format {:values [:row [1 2] [3 4]]}) (format-on-expr :where [:= :id 1]) (format-dsl {:select [:*] :from [:table] :where [:= :id 1]}) (format {:select [:t.*] :from [[:table :t]] :where [:= :id 1]} {})