datahike

https://datahike.io/, Join the conversation at https://discord.com/invite/kEBzMvb, history for this channel is available at https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/datahike
2021-06-08T03:51:46.045400Z

I've got an entity, and I want to update it. What's the common pattern for handling this? Do you diff the old entity and the new one, so you can figure out which datoms to retract? Do you just retract the entire entity and replace it?

kkuehne 2021-06-08T07:59:30.045900Z

Yes, you need to know which entity to update, so you need to get the :db/id and then you can just transact new facts to an entity like so (d/transact conn [{:db/id 123 :email "new-email@foo.bar"}]) . The old values are automatically retracted and moved to the historical index if you have it enabled so can query that as well if you need to.

2👍
2021-06-08T13:12:18.046400Z

That's really helpful, I assumed that transact was more of a merge-like operation. I'll play around at the repl, but this certainly makes updates easy.

kkuehne 2021-06-08T18:55:39.046600Z

Yeah, there are some handy features in there I had to discover myself again when I used it in a customer project, e.g. reverse lookups on transactions.

2021-06-08T20:49:44.046800Z

If you want to retract some keys and assert others, then you may have to retract the individual facts though, right? i.e. you're updating entity 1 to have :some/key1 retracted and :some/key2 asserted.

whilo 2021-06-10T18:12:04.047300Z

Yes, that is how you normally do it.

kkuehne 2021-06-08T07:59:30.045900Z

Yes, you need to know which entity to update, so you need to get the :db/id and then you can just transact new facts to an entity like so (d/transact conn [{:db/id 123 :email "new-email@foo.bar"}]) . The old values are automatically retracted and moved to the historical index if you have it enabled so can query that as well if you need to.

2👍
2021-06-08T13:12:18.046400Z

That's really helpful, I assumed that transact was more of a merge-like operation. I'll play around at the repl, but this certainly makes updates easy.

kkuehne 2021-06-08T18:55:39.046600Z

Yeah, there are some handy features in there I had to discover myself again when I used it in a customer project, e.g. reverse lookups on transactions.

2021-06-08T20:49:44.046800Z

If you want to retract some keys and assert others, then you may have to retract the individual facts though, right? i.e. you're updating entity 1 to have :some/key1 retracted and :some/key2 asserted.