Fork me on GitHub
#datomic
<
2024-01-10
>
favila17:01:26

With datomic-pro 1.0.6610, we were accidentally passing a (large) map to d/pull like (d/pull db pull-expr large-map). Not only did this not explode, it actually caused a memory leak via datomic.db/caching-normalize, which is a memoize object which was holding on to each large-map.

Rodrigo Mejia Sanchez23:01:37

Hello, I have two attributes that are part of an entity that I’d like to enforce that they get updated together; you shouldn’t be able to update just one by itself. As an example, a person has a legal name, if their legal name changes, I’d like to also enforce a change to :person/name-change-document that points to another entity that has information about the document that person submitted in order to change their legal name.

(def schema [{:db/ident :person/legal-name
              :db/cardinality :db.cardinality/one
              :db/valueType :db.type/string}
             {:db/ident :person/name-change-document
              :db/cardinality :db.cardinality/one
              :db/valueType :db.type/ref}])
I’ve tried using https://docs.datomic.com/cloud/schema/schema-reference.html#required-attributes, but this seems to enforce that the entity always has these two values, not that a transaction must specify them both to update an entity. I’ve also thought about using a tuple of [:person/legal-name :person/name-change-document] but then I found that navigating refs inside tuples is very cumbersome. I’m also aware that this may be possible using ions, but I’d like to find if there’s an alternate way before I delve into creating and maintaining ions. Is there an idiomatic way in Datomic to enforce this or something like this?

silian00:01:57

Hmm, interesting. I would think that name-change-document should be its own attribute, with a ref to person entity. Then you have some logic that updates legal-name as part of the name-change-document transaction. Just some thoughts.

Linus Ericsson11:01:36

I think you should consider enforcing this check as part of creating the transaction-data server(client) side. Maybe there is some way to ensure this in the transactor, but I think this is more of a business logic concern which therefore should be enforced in the server (not transactor).

Rodrigo Mejia Sanchez15:01:07

Both good points, I was thinking about enforcing it in my business logic, but wanted to explore all options before doing so. Thanks y’all for the input!