Exposing Datomic entity identities to a service or REST API

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?

  • Unless the endpoint is ephemeral, you should really not expose the entity number (see here for detailed reasons), so using the value of an identity attribute is a good way to go about this. This attribute can be of type UUID indeed, but Strings or numbers can work too.

    With Datomic, you also have the opportunity to use "self-contained" identifiers, eg Datomic lookup refs ( [:post/id "fdslkjfdskjfsl"] instead of just "fdslkjfdskjfsl" ). This comes in handy to make your route less specific than being about posts. Because of Datomic's schema flexibility (compared to say SQL tables or MongoDB collections), this benefit is especially easy to achieve. You could implement this eg by edn-encoding the lookup ref in the URL.

    链接地址: http://www.djcxy.com/p/65268.html

    上一篇: 在Datomic中注释的关系

    下一篇: 将Datomic实体标识公开给服务或REST API