Inconsistency between d/pull and d/q + pull for non-existent entities
Datomic returns a map with the :db/id
of the entity being pulled, even if the entity doesn't exist in the database. For example:
(d/pull (d/db conn) '[*] 9999999999)
=> #:db{:id 9999999999}
This behavior is somewhat confusing, especially when using d/pull
with time filters. I was expecting d/pull
to return nil
or #:db{:id nil}
if the entity wasn't created at the given point in time. However, Datomic always returns a map with the entity ID:
(d/pull (as-of (d/db conn) 1) '[*] 9999999999)
=> #:db{:id 9999999999}
Surprisingly, I see the expected behavior if I pull the entity information from a query using d/q
:
(d/q '{:find [(pull ?e [*])]
:in [?e]}
(d/db conn) 9999999999)
=> [[#:db{:id nil}]]
Is that difference in behavior expected? How can I determine if an entity existed at any point in time using d/pull
?