Fork me on GitHub
#datomic
<
2017-07-23
>
ckaratza09:07:30

Hello I am currently evaluating datomic and using the java API šŸ˜® . One use case I am trying to solve is to retrieve a specific set of transactions for an entity. After getting the transactions ids which are non continuous I clumsily retrieve the actual tx data via the log api by applying a short range of one based on the transaction id (txRange(x, x+1)). Is there a more elegant way of achieving the same result?

robert-stuttaford13:07:25

@ckaratza in Clojure, itā€™s not clumsy šŸ™‚ (first (d/tx-range (d/log (d/connect "URI")) t (inc t)))

hmaurer14:07:00

@robert-stuttaford isnā€™t it possible to retrieve the tx data directly in the datalog query anyway?

ckaratza16:07:34

@hmaurer how could you change this to include the datums `[:find ?tx ?e :in $ ?id ?owner ?revision :where [?e :appRegistry/id ?id] [?e :appRegistry/owner ?owner] [?e :appRegistry/revisionNumber ?revision] [?e ?tx]]`

hmaurer16:07:57

@ckaratza ah wait, you want all the datoms for a particular transaction?

ckaratza16:07:25

šŸ™‚ yes

hmaurer16:07:46

in that case Iā€™m not sure you can do it efficiently in Datalog. @robert-stuttaford can you please confirm?

hmaurer16:07:53

There is no index helping you for this

hmaurer16:07:23

The log is probably the way to go, as you did

ckaratza16:07:53

let me try thic: `[:find ?tx ?a ?v ?e :in $ ?id ?owner ?revision :where [?e :appRegistry/id ?id] [?e :appRegistry/owner ?owner] [?e :appRegistry/revisionNumber ?revision] [?e ?a ?v ?tx]]`

hmaurer16:07:32

Ah, this should work, because you have extra filters on ?e

hmaurer16:07:56

but if you tried [?e ?a ?v ?tx] alone I think it would warn you that the query would lead to a full DB scan

hmaurer16:07:07

What are you trying to do exactly?

hmaurer16:07:18

As in, what is the problem you are trying to solve / question you are trying to answer?

ckaratza17:07:04

I want to reconstruct the commands executed to build an entity

hmaurer17:07:28

Are you familiar with Datomicā€™s ā€œhistoryā€ database?

ckaratza17:07:31

lets say I have an entity revision and I want to display its chronicle

ckaratza17:07:02

yes I execute the query in this db and as i saw now it returns the datoms

ckaratza17:07:25

they are not grouped by as I want but thy come back

ckaratza17:07:42

so what happens now is I get all datoms flat and I need to group them by txid

hmaurer17:07:59

@ckaratza you can probably group them after getting back the result from the query then

ckaratza17:07:53

yeap that's the easy part šŸ™‚ thanx a lot for the directions!

ckaratza17:07:08

@hmaurer I also added the ?added part to find out if its an assertion or retraction

hmaurer17:07:36

@ckaratza happy I could be helpful šŸ™‚