Fork me on GitHub
Matheus Moreira07:01:50

Hello, datomickers! Newbie question: is it good practice to use Datomic entity ids as identifiers shared with the application in a similar way that we use surrogates primary keys on relational databases?


You probably should create application level ids if you are sharing them with any external place


Like other systems or even having them in URL routes or similar


You don't control :db/id. In some cases, like migrations/restores, it can change, so you should not use it in things like URL's

Matheus Moreira12:01:48

I see. But Datomic doesn’t have anything like a long sequence generator, right?


random UUIDs are usually good


if you really need a sequence, you could create a tx fn to do it and use an attribute with nohistory


but usually opaque identifiers are best

Matheus Moreira13:01:22

Yes, I think that an UUID is enough, really. My context here is that I am trying to model using Datomic the (relational) db model of the app that I maintain, and some of its tables has this weird combination of auto-increment long key plus an UUID. Thinking about it now, the pair doesn’t make much sense, the UUID would be enough. I think that the long key exists because of some legacy stuff.


If you end up needing both, you can use a unique tuple

Matheus Moreira16:01:04

I just started maintaining this system, I think that both keys are unnecessary… I would drop the long key and keep only the UUID if I started it in Clojure/Datomic. 🙂


I have a question about tuples; Say that I have a category with tags, and these tags are component/many of this category. Now, I’d like to add a composite (tuple) key to this tag entity that says `[tagName, category]` is unique, but there is no explicit relation from tag -> category. Do I have to reverse this relation / lose the component-ness to add this composite key?


Yes, or you can update this value yourself as a denormalization


Ie make it a heterogeneous tuple value instead of a composite one


I'll try that! The relation never changes in my case, so duping the relation the other way around is not too bad. Was hoping for something automatic, so it wouldn't get out of sync. but oh well


If I'm deploying an api service using datomic.lambda.api-gateway/ionize can I start a long running listener (like a kafka consumer) in the handler I pass in?


I haven't personally done so, but I'm pretty sure you can


Excellent! Many thanks