Fork me on GitHub
#datomic
<
2021-01-19
>
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?

tatut08:01:09

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

tatut08:01:23

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

souenzzo12:01:54

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

3
Matheus Moreira12:01:48

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

tatut12:01:28

random UUIDs are usually good

3
tatut12:01:13

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

tatut12:01:44

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.

favila13:01:02

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. 🙂

thumbnail11:01:06

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?

favila13:01:03

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

favila13:01:37

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

thumbnail14:01:18

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

rcrupp22:01:58

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?

Tuomas19:01:23

I haven't personally done so, but I'm pretty sure you can https://forum.datomic.com/t/kafka-consumer-as-an-ion/823

rcrupp20:01:28

Excellent! Many thanks