This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-23
Channels
- # announcements (1)
- # babashka (13)
- # cherry (12)
- # cider (6)
- # clj-kondo (3)
- # cljs-dev (28)
- # clojure (77)
- # clojure-europe (25)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-uk (5)
- # clojurescript (31)
- # conjure (7)
- # cursive (12)
- # data-science (9)
- # datalevin (5)
- # datomic (8)
- # hyperfiddle (21)
- # jobs (7)
- # kaocha (19)
- # malli (26)
- # matrix (3)
- # releases (1)
- # shadow-cljs (42)
- # squint (95)
- # testing (2)
- # vim (14)
- # wasm (1)
Hey everyone,
Is it possible to retract all entities/attributes that satisfy some condition?
for example, :person/name :preson/age
• retract all persons under the age x
• retract all persons that their name not in ["a" "b"]
i can’t figure out how to do it without query all persons first? (sounds like a bad performance as well)
Thanks 🙏
Hmm, doesn’t it just mean that it would run on the transactor? I would need to query all persons and filter the ones I want first, right? In addition, for every retract that i would need i’ll have to create a new function?
Datomic is data oriented, to retract data is to add transaction data that contains :db/retract for each fact you want to be removed. So, to generate that data you would use a function that queries the database for your condition and build the transaction data from that result into the :db/retract you would require. https://docs.datomic.com/cloud/tutorial/retract.html has some more information.

BTW:
It is possible to make a query return a tx-data
(d/transact conn
(d/q '[:find ?retract ?id
:where
[(ground :db/retractEntity) ?retract]
[?id :user/age ?age]
[(< ?age 21)]]))
It is more fun than useful. But most of my database migrations were written like this.I want to elaborate this question regarding consistency for the use case of "delete all employees that have been banned", where "ban" is a boolean attribute.
I can query all of the employees and verify their "ban" field, and then send a transact query to retractEntity of them all. What if between the query that i have executed and the transact that I have sent, some employee has been updated from "true" to "false", i.e, the transaction should not retract him, but it would.
I understand cas
and how it can help us with updating attributes, and also the retract
API for attributes (based on a value), but it seems like retractEntity
is missing a key concept of filtering / matching to assure consistency.
Wheres in a RDBM you would execute the update with the query atomically "delete .. where ban=true"