Fork me on GitHub
quan xing07:07:04

How I write sql use like % in honeysql

select * from t where username like '%A%'

{:select :* :from :t :where [:like username "%A%"]} 
=> ["SELECT * FROM t WHERE username LIKE ?" "%A%"] 
I want result is ["SELECT * FROM t WHERE username LIKE '%' ? '%'" "A"]


If you map a hashmap, your transform fn receives a pair of key and value for each item. That returns a seq of pairs, that you can flatten .

(map (fn [[k v]] (...transform...) my-map)
Or with reduce you can do the same in one pass, accumulating into a flat vector, or even into the final string. Maps do not guarantee order, so you would need to either start from a sorted map
(sorted-map :select :* :from ... )
or implement an algorithm to sort the result into valid order.

Daniel Vieira15:07:41

Try [:like :username [:inline "%A%"]]

Bob B15:07:43

is this what you're after?

(s/format {:select :* :from :t :where [:like :username "%A%"]} {:inline true})
=> ["SELECT * FROM t WHERE username LIKE '%A%'"]

Michaël Salihi15:07:40

> I want result is ["SELECT * FROM t WHERE username LIKE '%' ? '%'" "A"] (modifié) Why do you want this result? If "A" input have to be dynamic so you can use (str "%" var "%").


@U90R0EPHA Not sure what you're responding to here? @U025AG2H55F is asking about the #honeysql library which converts data structures to SQL statements. If this is a static query -- %A% is fixed -- then @U037W3C7KTR is correct: [:inline "%A%"]. If it's a dynamic query -- A will vary -- then @UFBL6R4P3 is correct: [:like :username (str "%" a-var "%")] It's usually better to ask Qs about HoneySQL in #honeysql where users of that library are more likely to see it than in #beginners

👍 1

Misunderstanding, I guess? I interpret the phrasing of that question to mean they want to mimic honeysql... which I then would presume is either an intellectual exercise, or intended to avoid a dependency in small project with limited scope.


But after re-reading the question many times, I think you are probably right. :man-facepalming: @U04V70XH6 ^


No worries, I was just puzzled by your answer and initially wondered if it was meant to be a response to a different question that I'd missed in the main channel 🙂

quan xing01:08:12

thanks everyone

Tomáš Baránek19:07:11

Hi, I am sorry, probably stupid question. I stopped seeing peek definitions in my IDE – VS Code Studio with Calva installed. All is up to date but I just get info there is no definition. Thank you!


I'm not sure whether you mean the static hints (produced by LSP/clj-kondo) or dynamic stuff (based on having evaluated code into a REPL). Your best bet is to ask in #calva and provide as much detail as possible about what worked before, and what you did between then and it stopping working.

🙏 1

Might I interject to ask, have you heard of our lord and savior, #emacs?


No editor wars, please. I use VS Code after decades of using Emacs. I've used many editors over the twelve years I've been doing Clojure. There are lots of good reasons to use something other than Emacs. Let people use what they want.

🙂 1
❤️ 4