Fork me on GitHub
#datomic
<
2017-04-21
>
isaac02:04:31

@stuartsierra Does coginect has a plan to support reverse index? eg. (rseq (d/datoms ....))

matthavener14:04:42

isaac: (d/datoms :vaet) ?

matthavener14:04:07

ohh.. nevermind, I see, reading it in reverse

marshall14:04:30

I believe that may be a current feature request in our customer feedback portal - I’d suggest adding your vote!

karol.adamiec14:04:49

i am trying to find a nice way of determining the last transaction time for a given query. I can get the whole DB value like so: (:db/txInstant (d/entity db (d/t->tx (d/basis-t db)))) what i really want/need though is a txInstant that relates to arbitrary query. Lets say my Q is: (d/q ’[:find [(pull ?eid [*]) ...] :where [?eid :part/type :solution]] db) How can i merge the two in a manner that is composable and efficient?? :thinking_face:

favila15:04:21

@karol.adamiec You know about the ?tx segment?

favila15:04:51

(d/q ’[:find (pull ?eid [*]) ?txinst
        :where [?eid :part/type :solution ?tx]
            [?tx :db/txInstant ?txinst]]
      db)

favila15:04:58

whew that was hard to edit

favila15:04:39

so that gives you the txinst of the [?eid :part/type :solution] datom

favila15:04:52

but you can do more elaborate things, like e.g. find the max tx of all datoms on an entity, or all datoms on an entity and any entity reachable via isComponent attrs (what (pull ?eid '[*]) would get)

karol.adamiec15:04:10

yes so i can get a list of entities with their txinstant

karol.adamiec15:04:18

like in first example of yours

karol.adamiec15:04:38

but… my query might be arbitrarily complex . pull a lot of things…

karol.adamiec15:04:57

metaphorically i want to pour my arbitrary d/q into a ‘new db’ object, and then ask that ‘new’ db what is its latest transaction….

karol.adamiec15:04:24

preferably in a general way so i do not need to amend any queries in the system…

favila15:04:08

pull loses the tx of its datoms, so you either have to keep that info in parallel or write your own pull which takes datom-like input

favila15:04:15

the latter might not be so bad. You could return [?e ?a ?v ?tx] from query, and then build maps from that directly. (no pull expression, you just mapify what you get)

favila15:04:51

the first approach looks more like this:

(d/q
  '[:find (pull ?eid [*]) (max ?tx)
    :in $ %
    :where
    [?eid :part/type :solution]
    (component-reachable ?eid _ _ _ ?tx)
    ]
  db
  '[[(component-reachable [?se] ?e ?a ?v ?tx)
     [(identity ?se) ?e]
     [?e ?a ?v ?tx]]
    [(component-reachable [?se] ?e ?a ?v ?tx)
     [?se ?sa ?sv ?tx]
     [?sa :db/isComponent true]
     [?sa :db/valueType ?type]
     [?type :db/ident :db.type/ref]
     (component-reachable ?sv ?e ?a ?v ?tx)]])

karol.adamiec15:04:32

oh, that is a wall of datalog that is way beyond me 🙂

karol.adamiec15:04:28

thx @favila , i have to mull that over and experiment in order to grasp that 🙂