Fork me on GitHub

Is there a way to make datomic entities unique across multiple attributes, instead of just a single one?


no eraserhd, don't think soi


Datomic does not provide a mechanism to declare composite uniqueness constraints; however, you can implement them (or any arbitrary functional constraint) via transaction functions.


so in a way, yes there is


Hrmm. But you can’t, say, make a :db.unique/identity attribute which is a component.


I’m still reading docs, but I’m guessing these can’t handle the upsert case?


Oh, I see, it’s like a stored procedure, and you call it to do the thing, it’s not like a hook.


OK, so I see it’s not really possible to enforce uniqueness on multiple fields. The transaction function thing only works if everyone uses the transaction function, and it doesn’t add the ability to do lookup refs on multiple fields. That sound right?

Ben Kamphaus15:07:39

that’s correct, true of transaction functions in general and really how you should think about anything in Datomic. “security only works if people use the API / query layer I define” “domain specific transactional constraints only work if people use the transaction functions"

Ben Kamphaus15:07:29

that said, there are other strategies people use for composite keys - i.e. a string concat field, etc. — but then you have to be careful with how you handle the composite key munging and alignment between the key and field it refers to in the transaction and query strategies you use.


Hi al, anyone have best practices for working with datomic data from plain JavaScript (rather than ClojureScript)? Most of the EDN->JSON libraries I’ve seen don’t seem to handle namespaced keywords very well (they drop the namespace bit)


@timgilbert: maybe serialize to Transit then ?