Fork me on GitHub
#datomic
<
2016-07-01
>
eraserhd14:07:58

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

danielstockton15:07:44

no eraserhd, don't think soi

danielstockton15:07:10

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

danielstockton15:07:37

so in a way, yes there is

eraserhd15:07:17

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

eraserhd15:07:09

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

eraserhd15:07:17

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

eraserhd15:07:29

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.

timgilbert16:07:31

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)

val_waeselynck20:07:45

@timgilbert: maybe serialize to Transit then ?