I’m confused about how to expose the identity of a Datomic entity to a service or API.
Suppose I have a REST API endpoint
/api/post/<id>
where <id>
identifies some blog post (a blog post entity).
With a relational database backend I might have <id>
be of some serial integer type stored in a column named id
in a table named post
.
Since Datomic doesn’t have tables (entities) in the same sense, and its entity IDs are unique database-wide I wonder how this is usually done with Datomic?
- Should the entity identifier be exposed directly? According to the documentation an entity identifier is database-unique, so that would work. But the documentation doesn’t specify what the type of an entity identifier is, so perhaps not. (If it is a
java.lang.Long
can it be negative?) - Or should a UUID or squuid attribute (
:post/id
) be exposed instead? Further down in the same documentation it says ‘It is often important to have a globally unique identifier for an entity. Where such identifiers do not already exist in the domain, you can use a unique identity attribute with a value type of :db.type/uuid’. Is that it? Is it generally required to add an attribute like:post/id
to all such entities?