Fork me on GitHub

I’m trying to understand the use of the tx-data function in queries. The docs ( give this example: [(tx-data ?log ?tx) [[?e ?a ?v _ ?op]]] That works for me as expected. But I was hoping to be able to provide values for some of those slots, like so: [(tx-data ?log ?tx-id) [[?e :label/public-id ?v _ false]]] This gives me results I don’t understand. ?v gets bound to an entity, not a value--specifically, the entity to which I’d expect ?e to be bound. ?e gets bound to another entity (an entity which definitely does not have a :label/public-id attr) which I wouldn’t expect to be in this datom at all.


I’m a little surprised this works at all. The ?a slot here is a number (an entity id), so I would expect :label/public-id to cause the binding to never unify with anything.


I think this should work as you expect

[(datomic.api/entid $ :label/public-id) ?label-public-id-attr]
[(tx-data ?log ?tx-id) [[?e ?label-public-id-attr ?v _ false]]]


thanks, I think that will work. I agree that it’s weird that it returns anything the other way.


is there a limit on how many records i can run (fulltext on ? I have a list of 46k users and datomic seems to be dying on calling fulltext on their names

Joe Lane21:05:10

What is the full query?


{:find [[?e ...]],
   :in [$ ?lname],
   :where [[?e :ent/type "user"]
           [(fulltext $ :user/name ?lname) [[?e _ _ _]]]]}

Joe Lane21:05:14

And what happens when you remove [?e :ent/type "user"]?


wait actually... no it's fast now


i don't understand why

Joe Lane23:05:11

1. Find all entities ?e that have an :ent/type 2. Limit the ?e's to only those that have an :ent/type of "user" 3. Find entities that have a :user/name of ?lname and and then bind them to ?e 4. Join ?e's from both results to limit the result set further 5. Take all the resulting ?e's and return a collection of them

Joe Lane23:05:35

^^ That's what your first query did

Joe Lane23:05:15

You could probably flip those two :where clauses around and it would work great. The number of ?e's returned by [?e :ent/type "user"] is probably much larger than those returned by the fulltext clause.