This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-30
Channels
- # aleph (39)
- # announcements (5)
- # babashka (7)
- # beginners (14)
- # biff (1)
- # clj-kondo (7)
- # clojure (38)
- # clojure-chicago (3)
- # clojure-europe (3)
- # clojure-norway (1)
- # clojurescript (8)
- # cursive (17)
- # data-science (6)
- # defnpodcast (3)
- # emacs (4)
- # figwheel-main (1)
- # honeysql (2)
- # hyperfiddle (2)
- # malli (20)
- # missionary (24)
- # off-topic (27)
- # reagent (4)
- # scittle (11)
- # shadow-cljs (51)
- # spacemacs (1)
- # xtdb (2)
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.Try [:like :username [:inline "%A%"]]
is this what you're after?
(s/format {:select :* :from :t :where [:like :username "%A%"]} {:inline true})
=> ["SELECT * FROM t WHERE username LIKE '%A%'"]
> 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
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 🙂
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.
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.