This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-18
Channels
- # beginners (84)
- # boot (21)
- # cider (12)
- # cljs-dev (13)
- # cljsrn (3)
- # clojure (169)
- # clojure-dusseldorf (2)
- # clojure-gamedev (6)
- # clojure-germany (1)
- # clojure-russia (15)
- # clojure-serbia (4)
- # clojure-spec (16)
- # clojure-uk (4)
- # clojurescript (51)
- # core-async (1)
- # datomic (23)
- # emacs (16)
- # figwheel (1)
- # fulcro (60)
- # hoplon (8)
- # lein-figwheel (3)
- # leiningen (1)
- # luminus (4)
- # lumo (43)
- # off-topic (4)
- # re-frame (17)
- # rum (37)
- # shadow-cljs (21)
- # test-check (13)
- # vim (14)
so i have a database with questions and comments that belong to those questions. i want to query for the questions’ attributes as well as the number of associated comments. using a join and the count aggregate works fine when there are comments but of course doesn’t work when there are zero comments because there is nothing to count
ok, now its getting trickier. now i have two associations I need to count and they can both be zero.
now i'm trying to do it with 4 queries but that means i need to be able to identify the case where both associations are not there. i tried (and (not-join...) (not-join...))
but that doesn't seem to be a legal use of and
.
@captaingrover my take at it: https://gist.github.com/vvvvalvalval/5547d8b46414b955c88f
@U06GS6P1N thanks that is very helpful. im having trouble figuring out how to extend it to count two optional associations however. in particular i'm struggling with how to use the where
clause. this is what i have (warning - awkward code):
(def query '[:find (sum ?comment-weight) (sum ?affirmation-weight) ?text ?time ?source-identifier ?q
:with ?uniqueness
:where
[?q :question/text ?text]
[?q :question/time ?time]
[?q :question/source-identifier ?source-identifier]
(or-join [?q ?uniqueness ?comment-weight ?affirmation-weight]
(and [?comment :comment/question ?q]
[?affirmation :affirmation/question ?q]
['((identity ?comment) (identity ?affirmation)) ?uniqueness]
[(ground 1) ?comment-weight]
[(ground 1) ?affirmation-weight])
(and [?comment :comment/question ?q]
[(identity ?comment) ?uniqueness]
[(ground 1) ?comment-weight]
[(ground 0) ?affirmation-weight])
(and [?affirmation :affirmation/question ?q]
[(identity ?affirmation) ?uniqueness]
[(ground 1) ?affirmation-weight]
[(ground 0) ?comment-weight])
(and [(identity ?q) ?uniqueness]
[(ground 0) ?comment-weight]
[(ground 0) ?affirmation-weight]))])
any idea how to get this to work? at this point i don't care so much about pretty code...
@captaingrover can you post this on SO? I think it's useful that other people see the solution
@captaingrover you seemed in a hurry, so I took the liberty of asking a question on SO and answering myself 🙂 https://stackoverflow.com/questions/47417009/datomic-aggregations-counting-related-entities-without-losing-results-with-zero/47417128#47417128 HTH
@U09R86PA4 I don't see what this would consist of, could you add it as an SO answer please?
@U09R86PA4 alright I see it now
wound up doing one query for questions with a count of comments and one query for questions without comments using a not-join
Hi all. I am confused. Maybe somebody can help me. I have a java project and I would like to use the java query DSL. I have the newst version of datomic pro on the classpath but 'import datomic.*;' doesn't work.
Hello all, today I´m using mysql database for selling system that use 30-40 clients simultaneously. This concurrency is controled by ring web app. What do you think changing the database to Datomic? I saw that the limit for free version is 2 peer connection. What is it means? Two ip´s connected?
@captaingrover you seemed in a hurry, so I took the liberty of asking a question on SO and answering myself 🙂 https://stackoverflow.com/questions/47417009/datomic-aggregations-counting-related-entities-without-losing-results-with-zero/47417128#47417128 HTH