This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-03
Channels
- # adventofcode (1)
- # beginners (76)
- # boot (88)
- # cider (63)
- # clojure (357)
- # clojure-austin (2)
- # clojure-berlin (8)
- # clojure-brasil (8)
- # clojure-nl (1)
- # clojure-russia (22)
- # clojure-spec (17)
- # clojure-uk (47)
- # clojurescript (67)
- # cursive (45)
- # datascript (3)
- # datomic (45)
- # dirac (7)
- # emacs (3)
- # funcool (2)
- # hoplon (26)
- # jobs (2)
- # jobs-discuss (11)
- # luminus (6)
- # off-topic (243)
- # om (40)
- # om-next (7)
- # onyx (23)
- # overtone (1)
- # portland-or (2)
- # protorepl (11)
- # re-frame (55)
- # reagent (58)
- # rum (12)
- # sql (4)
- # test-check (12)
- # untangled (25)
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
@wei probably because :db/id
is not part of the keySet()
: http://docs.datomic.com/javadoc/datomic/Entity.html#keySet--
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
I'm looking into set intersection query ("give me all products with features a, b AND c")
Here's what I could come up with: https://gist.github.com/pesterhazy/1e0ce9f18035b1693ee9e55241b23be6
Is there a more elegant way than programmatically generating queries?
@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
something like this
(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)))
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
@pesterhazy perhaps build up a rule for the AND-ing of the slugs?
(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))
ah dynamically generating a rule, interesting!
@robert-stuttaford wouldn't your solution be slower, as it has to generate the feature set for each product?
> 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
what do you mean by that?
ah there's a difference between q and query
very interesting stuff
possibly, @pesterhazy - i suppose it would!
@pesterhazy dynamic conjunction can be achieved using double negation and dynamic disjunction in Datalog
i like @thegeez ‘s idea
@val_waeselynck is there a code sample that illustrates your idea?
De Morgan's law?
@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
@pesterhazy yeah essentially
my autodidactism bites again. never did CS -pout-
but i don't think this one will work out of the box
because of the fact that not-join
works only on one data source
I'm in the same boat Robert
the following may work
not sure about the performance though 🙂
Nice!!
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
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 🙂
mind if I write a blog post summarising your approach?
@pesterhazy no problem whatsoever 🙂
@stuartsierra thanks!
@wei, the db/id is not really an attribute of the entity
although it is shown when you print the entity
I suppose you could (-> entity pr-str read-string)
? 🙂