This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-03
Channels
- # admin-announcements (2)
- # arachne (1)
- # architecture (6)
- # boot (316)
- # cider (7)
- # cljsrn (7)
- # clojure (169)
- # clojure-argentina (3)
- # clojure-belgium (1)
- # clojure-canada (4)
- # clojure-india (1)
- # clojure-russia (39)
- # clojure-spec (27)
- # clojure-uk (55)
- # clojurescript (213)
- # css (1)
- # cursive (20)
- # datavis (2)
- # datomic (52)
- # devcards (3)
- # dirac (78)
- # emacs (20)
- # events (1)
- # funcool (3)
- # hoplon (15)
- # jobs-rus (2)
- # om (57)
- # onyx (82)
- # overtone (1)
- # re-frame (10)
- # reagent (1)
- # ring-swagger (46)
- # spacemacs (7)
- # specter (31)
- # spirituality-ethics (1)
- # sql (43)
- # test-check (1)
- # testing (4)
- # untangled (30)
I have an attribute [:foo/bar :ref :many], is there a datalog query that allows me to query for “foo” such that :foo/bar must have three specific refs?
Seems I can query: find entities that have all the related entities in my param list, or any of the params, but not a subset of the params.
To clarify, I want to write a query like “find all the clubs in which “bill” “fred” and “sue” are members.
@zentrope: can you show the two queries you mentioned that are not quite what you want? "all related entities" and "any of the params"
[[?e :class/students [:student/id “ted”]] [?e :class/students [:student/id “fred”]]
something like that.
(q [:find ?e :in $ [?students …] :where [?e :class/students ?students]] db [“ted” “fred”])
And of course finding the classes where “ted” is a student is trivial. (That’s the “any one of” the params.)
My solution is to just take the vector of names and generate clauses for each one, thus creating the “and” condition. I sort them so that query caching has a chance.
@zentrope: just an idea, add a (count ?students) and :with ?students (not sure if you need that actually), and later keep only the results which has count equal to input students
@zentrope assuming the need for exactly 3 is fixed:
(d/q '[:find ?foo :in $ [?bar1 ?bar2 ?bar3] :where
(and [?foo :foo/bar ?bar1]
[?foo :foo/bar ?bar2]
[?foo :foo/bar ?bar3])]
db ["one" "two" "three"])
anyone using http://www.terraform.io and Datomic together? @marshall, do you know if this has been done? i'm guessing it's fairly straightforward, if one uses your AMI
@robert-stuttaford: I’ve not heard of anyone using it. Is it supposed to take the place of e.g. CF?
Noob question: How do people programmatically interact with datalog? I dont want to always hard code all my queries, I'd like to parameterize it somehow. Any blogs or suggestions. Do people use macros for this. I haven't got into macros myself yet fwiw.
this might help: http://docs.datomic.com/query.html#building-queries-programmatically
also an example at the bottom of this: https://github.com/Datomic/day-of-datomic/blob/master/tutorial/building_queries.clj
I guess what I'm wondering is could a datomic query be parameterized in a function like so: (defn generic-find [data] (d/q 'data (get-db)))
@fenton: you can also use syntax quoting (`) and unquote (~) which can be more convenient: `{:find [[?ent ...]] :where [[?ent :type ~type]]}
@mlimotte: f--king cool! omg! sorry had to share my enthusiasm about finally understanding the use of this stuff! 🙂
without namespace, it's all global. the namespace helps to organize things. best practice.
@fenton, be aware that d/q
does computation to prepare queries (its first arg) and caches that work using the query value itself as a key. so if you generate them dynamically, you could be generating unnecessary work for d/q
. i recommend seeing if you can parameterise with :in
, first.
@robert-stuttaford: ok. i had some where clause 'datoms' that were being used over and over, so I pulled those out to keep it DRY. I wonder if that will cause a cache miss. Hmmm... Wonder how to tell what gets cached.
@fenton: datalog rules 🙂
rules is a noun, there, not a verb 🙂
@fenton, here's a fairly concise example (using datascript) https://github.com/robert-stuttaford/stuttaford.me/blob/master/src/stuttaford/client/components/codex.cljs#L20-L52 see it in action http://www.stuttaford.me/codex view the source of the page to see the data
note the %
in the :in
clause
@robert-stuttaford: ok, let me read and try to grok that... looks promising.
@robert-stuttaford: so cool!
Datomic 0.9.5390 is now available https://groups.google.com/d/topic/datomic/QLdZ_WePR5A/discussion
I bet a lot of folks will appreciate the use of the log API in the in-memory version of the DB.
@robert-stuttaford: Thanks! The problem is that I don’t have a fixed size. Instead, I just generate the where-clauses dynamically. The end result looks just like your version, more or less.