This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-08
Channels
- # announcements (4)
- # aws (1)
- # babashka (4)
- # beginners (75)
- # biff (4)
- # calva (13)
- # clojure (76)
- # clojure-android (1)
- # clojure-austin (9)
- # clojure-europe (14)
- # clojure-mexico (3)
- # clojure-nl (2)
- # clojure-norway (11)
- # clojure-uk (14)
- # clojurescript (19)
- # conjure (14)
- # cursive (30)
- # datomic (13)
- # gratitude (6)
- # hyperfiddle (71)
- # introduce-yourself (2)
- # juxt (5)
- # malli (5)
- # nbb (5)
- # nrepl (10)
- # off-topic (32)
- # re-frame (3)
- # releases (1)
- # shadow-cljs (5)
- # sql (38)
- # tools-deps (24)
- # xtdb (19)
Hi people, is there a way to retract users from database by doing only one transact? [#:db{:id 17592186045418} #:db{:id 17592186045421} #:db{:id 17592186045423}] I have their db ids but do i need to loop over this vector or can I do it in one transact?
you can put them in a vector and send in one tractions:
(d/transact conn {:tx-data [[:db/retractEntity 1]
[:db/retractEntity 2]
[:db/retractEntity 3]]})
hmm thank you
(d/transact
conn
{:tx-data [[:db/retract [:db/id 1]]
[:db/add "datomic.tx" :db/doc "remove old user"]]})
I tried this approach and it didnt work for me, didnt know about retractEntity, thank you, I will try it• :db/retract
retracts specific attributes, like [:db/retract 42 :user/name]
• :db/retractEntity
is equivalent to get all the keys (keys (d/pull db [*] 42)) => [:user/name :user/id ....]
and retract them.
• I recommend you to write tx-my-operation
, like (defn tx-retract-user [.... ])
, that returns just the array of the operation, [[:db/retract [:db/id 1]] [:db/add "datomic.tx" :db/doc "remove old user"]]
in your example
• tx-data
is always composable via (concat tx-retract-user-1 tx-retract-user-2) => tx-retract-user-1-and-2
. Then you can use (d/transact conn {:tx-data tx-retract-user-1-and-2})
Avoid to create dead-simple functions
(defn tx-retract-user [id]
[[:db/retractEntity id]
[:db/add "datomic.tx" :db/doc "remove old user"]])
Just write these tx-my-operation
if there is some complexity on it.Thank you for your response, I will try it. ☺️
@U2J4FRT2T i don't follow, you say to avoid writing simple functions, but your examples are simple functions.
do you mean to not write functions, but just write out a bunch of txs in a let, then concat them?
I think he wanted to say is that if i have complexity in code to make a separate functions to make it more simple, to split code for more simple look, please tell me if I am wrong
To make those “operations” functions for operations that i require, and not to write it all together in one
@U2J4FRT2T please tell if i got it wrong
ok, i think if you are reusing the logic in a lot of places that makes sense. i find a lot of my txs are not reused, though.
my point is just don't write a function called tx-retract-x
that do just [[:db/retract x]]
if you want to retract x
, write [[:db/retract x]]
Write functions like tx-user-exit
, that will: retract the user entity, mark its address as disabled, send one bye message for each active friend...