Richard Searle

home

Unexpected attribute handling when querying datomic txReport

12 Oct 2013

Perform queries with results indicated 
Peer.q("[:find ?value :in $ :where [_ :db/doc ?value]]",tx.get(Connection.TX_DATA)); //returns []
Peer.q("[:find ?value  :in $ :where [_ :db/doc ?value]]",db); //returns values
Peer.q("[:find ?value  :in $ :where [_ 61 ?value]]",tx.get(Connection.TX_DATA)); //returns values
Peer.q("[:find ?value  :in $ :where [_ 61 ?value]]",db); //returns values
 
So :db/doc is mapped to 61 for a query against the database but not when referencing the txReport.
This initially looks rather strange but is a direct consequence of how Datomic is implemented. 
:db/doc is merely an entity stored in the database, just like any other entity. It is not a special constant, baked into the implementation.
The txReport value does not contain the entity and thus cannot perform the mapping to attribute id. 
 
 
Set up the test
uri = "datomic:mem://hello";
Peer.createDatabase(uri);
datom = Util.list("db/add",
                  Peer.tempid("db.part/user"),
                  "db/doc",
                  "hello world");     
queue = conn.txReportQueue();
conn.transact(Util.list(datom)); 
db = conn.db();
tx=queue.poll();