Fork me on GitHub
#datomic
<
2017-01-03
>
wei03:01:52

when you call (into {} some-entity-map), why isn’t :db/id part of the resulting map? just wondering if there’s a good reason, before I make an entity->map helper that does copy the :db/id

kwladyka09:01:04

What do you use to store timestamp with timezone?

len11:01:03

java.util.Date does not contain timezone info, so if you are using :db.type/instant you will need to store the timezone in a different datom

pesterhazy11:01:59

I'm looking into set intersection query ("give me all products with features a, b AND c")

pesterhazy11:01:49

Is there a more elegant way than programmatically generating queries?

robert-stuttaford11:01:05

@pesterhazy entity ref collections are sets; i’d try filtering over all entities with :cat.product/features and doing set intersections with clojure.set/intersection on the set of entities for the slugs

robert-stuttaford11:01:18

something like this

robert-stuttaford11:01:36

(let [slugs    ...
      db       ...
      ent-fn   #(d/entity db %)
      features (into []
                     (comp (map (fn [slug]
                                  [:cat.feature/slug slug]))
                           (map ent-fn))
                     slugs)]
  (into []
        (comp (map ent-fn)
              (filter #(seq (clojure.set/intersection (:cat.product/features %) features))))
        (d/datoms db :aevt :cat.product/features)))

robert-stuttaford12:01:18

you can make dynamic datalog queries, and it should cache its own pre-processing on the result of your make-intersection-q for each of the n values for future use. you might instead want to produce a value for http://docs.datomic.com/clojure/#datomic.api/query, which puts args and datalog syntax into a single structure

thegeez12:01:51

@pesterhazy perhaps build up a rule for the AND-ing of the slugs?

thegeez12:01:01

(let [rule [(into '[(slug-and [?e])] (map #(vector '?e :cat.feature/slug %) feature-slugs))]]
  (d/q
   '{:find [?e]
   :in [$ %]
   :where [(slug-and ?e)]}
   db
   rule))

pesterhazy12:01:11

ah dynamically generating a rule, interesting!

pesterhazy12:01:17

@robert-stuttaford wouldn't your solution be slower, as it has to generate the feature set for each product?

pesterhazy12:01:06

> you might instead want to produce a value for http://docs.datomic.com/clojure/#datomic.api/query, which puts args and datalog syntax into a single structure

pesterhazy12:01:10

what do you mean by that?

pesterhazy12:01:40

ah there's a difference between q and query

pesterhazy12:01:16

very interesting stuff

robert-stuttaford12:01:46

possibly, @pesterhazy - i suppose it would!

val_waeselynck12:01:54

@pesterhazy dynamic conjunction can be achieved using double negation and dynamic disjunction in Datalog

robert-stuttaford12:01:06

@val_waeselynck is there a code sample that illustrates your idea?

pesterhazy12:01:35

De Morgan's law?

val_waeselynck12:01:37

@robert-stuttaford working on it 🙂 not sure it's possible in this case because of the constraint that not-join must operate on one data source

robert-stuttaford12:01:13

my autodidactism bites again. never did CS -pout-

val_waeselynck12:01:45

but i don't think this one will work out of the box

val_waeselynck12:01:07

because of the fact that not-join works only on one data source

pesterhazy12:01:07

I'm in the same boat Robert

val_waeselynck12:01:58

the following may work

val_waeselynck12:01:16

not sure about the performance though 🙂

val_waeselynck13:01:01

This is not the first time I see something like this come up - should probably be part of some best practices / tips and tricks section of the Datomic docs

val_waeselynck13:01:09

If this does not work-out performance-wise, then yeah, probably either generate a query or rule, or call a function in-query which performs the EAVT traversal, or a combination of both 🙂

pesterhazy13:01:41

mind if I write a blog post summarising your approach?

val_waeselynck13:01:34

@pesterhazy no problem whatsoever 🙂

uwo15:01:18

has anyone written a library for using pull syntax on local data structures?

wei20:01:26

thanks, makes sense. wondering about the justification for not including it.

pesterhazy21:01:06

@wei, the db/id is not really an attribute of the entity

pesterhazy21:01:05

although it is shown when you print the entity

pesterhazy21:01:22

I suppose you could (-> entity pr-str read-string)? 🙂