replikativ/datahike

Support for aliases

Opened this issue · 4 comments

Describe the feature you would like to request

Datomic supports aliases in the form of:

[:db/add :user/id :db/ident :user/primary-email]

It is part of Datomic best practices:
https://docs.datomic.com/on-prem/best-practices.html#use-aliases

Describe the solution you would like

A Datomic compatible solution should be the only way.

Describe alternatives you've considered

None.

Just looking into the code... This could mean some larger changes... or... a hacky solution.

In Datomic an entity can have many idents. This doesn't play well with how the schema and indexes are currently stored.

That sounds like it is better to wait with this issue until we attack issue #532. This will also require some more thoughts about the schema treatment, but is an actual bug. Maybe we can piggy-back a solution for aliases with that issue or at least it might take a little less effort. But I think I know what you mean - there is probably a considerate amount of changes required, and besides, it might also be tricky to get a solution that is compatible with older datahike versions.

Aliases in Datomic are just idents that point to the same attribute entity.
Meaning with attribute refs active, aliases should already work.

Is the long-term plan with Datahike to only use attribute refs?

Not yet at least.

Have you tried transacting an db/ident datom into a reference database? I would expect there are some safeguards against that at the moment or that the ident gets overwritten. There might also be issues with the mappings that serve as caches for the translation between attribute and its reference value.
But if the larger changes you were talking about are to make aliases available for databases without references enabled, I do not think it makes too much sense putting the work into that. It seems quite unnatural to me to do that anyway. For datomic compatibility, it makes more sense to use the references, because otherwise some queries will also show different results.

We definitely should make attribute refs the default though to avoid confusions in the future.