Fork me on GitHub
#datomic
<
2024-05-02
>
Lidor Cohen11:05:16

Hello everyone 👋 What would you say the best way to mimic a flexible map type in attribute for insertion and query purposes? Insertion - I'd like to be able to insert a map to the attribute, when overlapping keys values will be overrided (not newly created) query - I'd like to be able to pull the entire map without specifing each key

bhurlow21:05:16

it sounds like you want a datomic entity which may or may not have certain keys

bhurlow21:05:50

not quite sure what a map to the attribute is referring to, but in Datomic that would more commonly be a ref to another entity instead of a serialized map

Lidor Cohen18:05:54

We want to have "dynamic" keys. So we did a ref to an entity that hold a "key" and a "value" and tried to use unique/identity on the "key" attribute + parent-id to get it to not create the same key twice for the same parent and override the value, but unique/identity doesn't do an upsert on a tuple type but just throws a unique constraint violation.

favila04:05:00

Possibly cardinality-many heterogenous tuple of key + value with insertions and deletions managed by transaction functions, and an entity predicate to ensure key uniqueness for good measure. If tuple is too limiting of value type, could use entities instead for each map entry

favila04:05:49

If amount of data is small and can be mostly opaque to datomic, consider just an edn/json string or nippy/fressian bytes type

favila04:05:14

Atomic merging can be implemented by transaction functions