datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
Matheus Moreira 2021-01-19T07:47:50.025Z

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?

tatut 2021-01-19T08:47:09.025300Z

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

tatut 2021-01-19T08:47:23.025500Z

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

souenzzo 2021-01-19T12:08:54.026Z

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

1
Matheus Moreira 2021-01-19T12:16:48.026200Z

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

tatut 2021-01-19T12:25:28.029100Z

random UUIDs are usually good

1
tatut 2021-01-19T12:29:13.029500Z

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

tatut 2021-01-19T12:29:44.029700Z

but usually opaque identifiers are best

Matheus Moreira 2021-01-19T13:48:22.030100Z

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.

favila 2021-01-19T13:51:02.030700Z

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

Matheus Moreira 2021-01-19T16:49:04.033200Z

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

tatut 2021-01-19T08:47:09.025300Z

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

tatut 2021-01-19T08:47:23.025500Z

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

2021-01-19T11:50:06.025900Z

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?

souenzzo 2021-01-19T12:08:54.026Z

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

1
Matheus Moreira 2021-01-19T12:16:48.026200Z

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

stuartrexking 2021-01-19T12:19:17.027500Z

I considered that. What I ended up doing was using tuples for session key / value pairs.

tatut 2021-01-19T12:25:28.029100Z

random UUIDs are usually good

1
tatut 2021-01-19T12:29:13.029500Z

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

tatut 2021-01-19T12:29:44.029700Z

but usually opaque identifiers are best

Matheus Moreira 2021-01-19T13:48:22.030100Z

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.

favila 2021-01-19T13:51:02.030700Z

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

favila 2021-01-19T13:52:03.031700Z

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

favila 2021-01-19T13:52:37.032700Z

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

2021-01-19T14:37:18.032900Z

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

Matheus Moreira 2021-01-19T16:49:04.033200Z

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

rcrupp 2021-01-19T22:37:58.037400Z

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?

Tuomas 2021-01-20T19:41:23.042Z

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

rcrupp 2021-01-20T20:13:28.045100Z

Excellent! Many thanks