This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-12
Channels
- # aleph (6)
- # announcements (11)
- # babashka (24)
- # beginners (127)
- # calva (33)
- # chlorine-clover (5)
- # cider (7)
- # clara (9)
- # cljs-dev (54)
- # cljsrn (5)
- # clojure (61)
- # clojure-australia (8)
- # clojure-bay-area (11)
- # clojure-europe (36)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-spec (6)
- # clojure-taiwan (1)
- # clojure-uk (8)
- # clojurescript (94)
- # code-reviews (2)
- # community-development (6)
- # conjure (26)
- # core-typed (1)
- # cursive (3)
- # datahike (4)
- # datomic (14)
- # events (1)
- # graphql (1)
- # honeysql (49)
- # introduce-yourself (5)
- # jobs-discuss (15)
- # kaocha (6)
- # lsp (8)
- # malli (1)
- # meander (5)
- # nrepl (1)
- # off-topic (21)
- # other-languages (1)
- # pathom (13)
- # podcasts-discuss (1)
- # polylith (1)
- # reitit (16)
- # shadow-cljs (50)
- # spacemacs (11)
- # sql (11)
- # tools-deps (21)
- # unrepl (1)
- # vim (9)
Hi!
If I want to compose sql queries with some conditions.
I can use str
to concatenate like that but I'm sure this isn't the right way to do:
(defn retrieve-all-users-and-filter [filters]
(jdbc/execute! db [(str "SELECT id, first_name || ' ' || last_name as name, email, owner FROM users"
(when filters " WHERE first_name LIKE ?")
" ORDER BY last_name ASC, first_name ASC ") (when filters (str "%" (:search filters) "%"))]))
For more complex queries, is it interresting to use for eg. HoneySQL with Next.jdbc or is it a better solution that above with Next-jdbc?
Any clue about that?(defn retrieve-all-users-query [filters]
{:select [:id :first_name]
:from [:users]
:where [:and [:= 1 1]
filters]})
That turns out well, I am trying it. Thanks for your confirmation.
I take this opportunity to ask, what is the equivalent for a pattern matching "%string%"
Ah I think you gave the answer above, I'll try that right now!
@admin055 @emccue Stu Halloway gave a talk last night called "Better Bugs Make Better Programs", and he advocated naming Datomic queries top-level in the same way as the SQL query a few messages above 👍:skin-tone-3:
I have clj-kondo flag any public var that doesn’t have a docstring. When I start writing a function, that’s usually the first thing I do:
(defn my-cool-function
"Given <inputs>, <compute something> / return <something>.
<more long form description about the function if needed>
<any exceptional cases or caveats about usage>."
[])
and then I add arguments based on the <inputs> I described, then I sketch out the function logic in a (comment ..)
form and then “promote” it into the function body.Always interresting to hear some others workflow, thanks.