Skip to content

Commit

Permalink
tentative impl of VALUES statement in MySQL #544
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Corfield <sean@corfield.org>
  • Loading branch information
seancorfield committed Sep 28, 2024
1 parent 48edb03 commit 3ca197b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 6 additions & 2 deletions src/honey/sql.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]} {})
Expand Down

0 comments on commit 3ca197b

Please sign in to comment.