This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-30
Channels
- # adventofcode (95)
- # announcements (17)
- # babashka (28)
- # beginners (107)
- # calva (34)
- # clj-kondo (7)
- # cljs-dev (20)
- # cljsrn (1)
- # clojure (95)
- # clojure-europe (41)
- # clojure-italy (3)
- # clojure-nl (5)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (77)
- # cursive (7)
- # data-science (1)
- # datalog (4)
- # datomic (12)
- # events (3)
- # fulcro (32)
- # graalvm (2)
- # hugsql (19)
- # introduce-yourself (4)
- # jobs (2)
- # lsp (20)
- # membrane-term (19)
- # numerical-computing (1)
- # off-topic (8)
- # pathom (3)
- # polylith (17)
- # portal (42)
- # re-frame (7)
- # reagent (32)
- # remote-jobs (1)
- # shadow-cljs (86)
- # spacemacs (3)
- # tools-deps (52)
- # uncomplicate (1)
- # xtdb (23)
hi guys, I don’t understand how hugsql is working in this case:
I have the following:
-- :name update-user! :>! :1
-- :doc updates an existing user record, sets id=id to make hugsql syntax work
UPDATE users SET
id = id
--~ (when (contains? params :name) ",name = :name")
--~ (when (contains? params :email) ",email = :email")
--~ (when (contains? params :image) ",image = :image")
--~ (when (contains? params :pass) ",pass = :pass")
--~ (when (contains? params :reset-token) ",reset_token = :reset-token")
WHERE id = :id
RETURNING name, email, image, organization_id, role, reset_token
And basically I’m doing the following:
(update-user! {:id "foobar" :name "foo" :email nil :image "kasdasfj"})
And somehow this works when there are the when clauses there but doesn’t when there aren’t@lukaszkorecki just fixzed
my question is (contains? {:foo nil} :foo) is true, so why is this working
in my own code I usually write the conditional part as --~ (when (:pass params) " pass = :pass")
instead
and if a field needs to be nullfied then I'd add a dedicated query/function for that - I (and my team) found that relying on this behavior leads to weird bugs sometimes
are there docs for how to use this?
yep, this section: https://www.hugsql.org/#using-def-sqlvec-fns
(contains? {:foo nil} :foo) is true
but it works
as if in hugsql clojure it is false