Fork me on GitHub
#datomic
<
2016-05-06
>
Lambda/Sierra00:05:02

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

imaximix13:05:59

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

bvulpes16:05:05

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

harold18:05:58

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?

harold18:05:14

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.

harold18:05:49

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

harold18:05:54

But that's all I know.

harold18:05:20

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

harold18:05:34

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: https://github.com/Datomic/day-of-datomic/blob/master/tutorial/provenance.clj#L61

harold18:05:14

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

harold18:05:20

I'll give it a whack.

Ben Kamphaus18:05:17

(d/q '[:find ?e
       :in $ ?a ?v
       :where
       [?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).

harold18:05:47

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

Ben Kamphaus22:05:54

@fenton: http://docs.datomic.com/javadoc/datomic/Datom.html — an you use :e, :a, :v, :tx, :added etc. from Clojure instead of usual Java interop.

fenton22:05:42

is this idomatic...is there a way to query for available functions?

brian_mingus23:05:51

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

fenton23:05:12

@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]
etc.

Ben Kamphaus23:05:06

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

fenton23:05:28

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: http://docs.datomic.com/identity.html

fenton23:05:49

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