Fork me on GitHub

that's right, you have to specify which refs you want to follow


Hello, I've been playing around with datomic, and I've stumbled upon the following link . My question is: Can the pull syntax be used with queries against clojure collections?


imaximix: nope. pull works with entities specifically, which are a db-only artifact.


Can I search, historically, for a retracted entity which once had a value for a unique attribute, but no longer does?

Ben Kamphaus18:05:01

@harold: yep, I believe you should be able to do it using a query against a history db. Have you attempted anything yet?


I have a history query thing, but I need an entity ref to feed into it.

Ben Kamphaus18:05:15

a “retracted entity” is kind of a confusing category to ask about since entities are not intrinsically reified in the underlying datom model. Facts are asserted or retracted, all facts are about an entity, all facts about an entity may be retracted, but the entity’s existence is not otherwise a fact that can be asserted or retracted. If that makes sense.


Say I knew that at some point in the past there was an entity e with value v for attribute a.


But that's all I know.


Now I'd like to find the eid associated with that entity.


and it no longer has value v for attribute a, because the entity was retracted.

Ben Kamphaus18:05:56

enter and shift enter, ugh

Ben Kamphaus18:05:47

so all facts, assertiosn or retractions are in a history db, and you can limit to retractions with a fifth position of false in a :where clause.

Ben Kamphaus18:05:19

some queries against history (not an exact match for what you’re asking but maybe helpful) in the day of datomic provenance example:


Nice! Didn't think of false in the fifth position.


I'll give it a whack.

Ben Kamphaus18:05:17

(d/q '[:find ?e
       :in $ ?a ?v
       [?e ?a ?v]]
  (d/history db))
@harold that should return every entity that ever had that ?a ?v (as query parameters) asserted or retracted for it, could put in [?e ?a ?v _ false] as :where clause instead to limit to retractions (untested as of yet, just building query off expectations).


Yup! Just hit on something similar. Thank you! I am off and running.

Ben Kamphaus22:05:54

@fenton: — an you use :e, :a, :v, :tx, :added etc. from Clojure instead of usual Java interop.


is this there a way to query for available functions?


@fenton (map ns-publics (all-ns))


@brian_mingus: crashed my repl! lol!

Ben Kamphaus23:05:32

@fenton: you mean what you can call on a datom in clojure? supports nth, juxt (with keywords), destructuring.

Ben Kamphaus23:05:41

((juxt :e :a :v :tx :added) datom)
[0 10 :db.part/db 13194139533312 true]

(let [[e a v tx added] datom] [e a v tx added])
[0 10 :db.part/db 13194139533312 true]

Ben Kamphaus23:05:06

then it’s just values in Clojure you can do w/e with.


anyone have issues with uniqueness...when i transact two items quickly in sequence, seems to violate the uniqueness of that attribute?

Ben Kamphaus23:05:08

Unique value or identity? Identity will upsert rather than raise an exception.

Ben Kamphaus23:05:30

It's upserting, if you query the resulting db only one entity will have that attr/value, more here:


@bkamphaus: ok...thank you again! simple_smile