Fork me on GitHub
#honeysql
<
2023-08-07
>
dekel07:08:50

I believe there’s a bug around IN clauses and inline formatting when using parameters, but I just wanted to check I’m not missing a step (or that this is explicitly not supported) before I open an issue:

;NO PARAMETERS:
(hsql/format
  {:select :* :from :some-table :where [:in :id [1 2 3]]}
  {})
=> ["SELECT * FROM some_table WHERE id IN (?, ?, ?)" 1 2 3]
(hsql/format
  {:select :* :from :some-table :where [:in :id [1 2 3]]}
  {:inline true})
=> ["SELECT * FROM some_table WHERE id IN (1, 2, 3)"] ;correct

;PARAMETERS:
(hsql/format
  {:select :* :from :some-table :where [:in :id :?ids]}
  {:params {:ids [1 2 3]}})
=> ["SELECT * FROM some_table WHERE id IN (?, ?, ?)" 1 2 3] ;correct without inline
(hsql/format
  {:select :* :from :some-table :where [:in :id :?ids]}
  {:params {:ids (seq [1 2 3])}
   :inline true})
=> ["SELECT * FROM some_table WHERE id IN (1 2 3)"] ;no commas
(hsql/format
  {:select :* :from :some-table :where [:in :id :?ids]}
  {:params {:ids [1 2 3]}
   :inline true})
=> ["SELECT * FROM some_table WHERE id IN [1, 2, 3]"] ;square brackets
(hsql/format
  {:select :* :from :some-table :where [:in :id :?ids]}
  {:params {:ids #{1 2 3}}
   :inline true})
=> ["SELECT * FROM some_table WHERE id IN #{1 3 2}"] ;set, no commas
(hsql/format
  {:select :* :from :some-table :where [:in :id :?ids]}
  {:params {:ids (map inc [1 2 3])}
   :inline true})
=> ["SELECT * FROM some_table WHERE id IN clojure.lang.LazySeq@7c42"] ;etc

p-himik08:08:15

Seems like it's intended and documented: https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.1045/doc/all-the-options?q=%3Ainline#inline > everything else is just turned into a string (by calling str)

🙌 2
dekel08:08:11

Ah, wonderful, thank you for that, I was looking for things related to in specifically