-
-
Notifications
You must be signed in to change notification settings - Fork 310
There are no performance differences, since transact!
uses db-with
internally.
Entity equality only checks if the entity ids (eid
) is the same of two given entities. It does not looks if they're from the same database or even database version. This is efficient since otherwise an entire walk on the database could happen (which could be extremely expensive)
Datascript does not provide any kind of automated handling of retracting datoms that need to be removed from a cardinality/many.
Calling transact! with something like :
[[:db/retract 63 :event/contacts 56]]
works and does retract that datom 56 for the entity id 63. This is the single datom removal. The :event/contacts keyword refers to the entity attribute that is defined as cardinality/many. The entity id in the :db/retract keyword is the 'parent' entity id that contains the list.
If you want to submit multiple retractions just group each retract statement in the outer vector:
[[:db/retract 63 :event/contacts 56][:db/retract 63 :event/contacts 55]]
This will remove two entities :db/id 55 and :db/id 56 from the cardinality/many called :event/contacts You must use vectors within a vector even in the case of a single retract statement.
See this issue 324 for more information on a real use case.
You can also have non :db/id attributes in the retract statement but they need to marked as :b/unique so as not to get an error: Lookup ref attribute should be marked as :db/unique: [:contact/email "janet.lansdale@google.com"]
[[:db/retract 63 :event/contacts [:contact/email "janet.lansdale@google.com"]] [:db/retract 63 :event/contacts [:contact/email "nina@gmail.com"]]]
Mark Bastian has some fantastic examples including retractions at the datascript/playground