Fork me on GitHub
#datomic
<
2017-11-18
>
Desmond03:11:52

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

souenzzo14:11:17

maybe or + missing?

Desmond05:11:02

i didn't know about missing? - thanks for the tip

Desmond05:11:32

i have it down to 2 queries and i'm happy with that

Desmond06:11:24

ok, now its getting trickier. now i have two associations I need to count and they can both be zero.

Desmond06:11:11

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.

Desmond06:11:39

@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]))])

Desmond06:11:10

this doesn't actually work

Desmond06:11:47

the counts are wrong

Desmond06:11:02

any idea how to get this to work? at this point i don't care so much about pretty code...

val_waeselynck08:11:42

@captaingrover can you post this on SO? I think it's useful that other people see the solution

favila16:11:24

I suggest an alternative: call other functions which are ok with nils.

val_waeselynck16:11:35

@U09R86PA4 I don't see what this would consist of, could you add it as an SO answer please?

favila16:11:51

already did

Desmond05:11:34

wow. thanks for going the extra mile! i'll give this a try and respond on OS

Desmond04:11:16

how can i do this without n+1 queries?

Desmond08:11:12

wound up doing one query for questions with a count of comments and one query for questions without comments using a not-join

nickik14:11:32

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.

fabrao18:11:36

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?

fabrao18:11:32

Can anyone explain what it means?