Fork me on GitHub
#datomic
<
2020-07-12
>
craftybones14:07:02

Hello. If I store :match/teams as a tuple, then the query will have to untuple in order to query if either team is X right? is there a better way?

craftybones14:07:04

if I stored it with a many cardinality then the query semantics get easier, however the storage semantics is wrong since I now can store multiple teams for a single match

craftybones14:07:44

the final option is :match/team-1 with the query containing an or now

craftybones14:07:47

I least like using team-1, but it is the best compromise from a storage semantic and a query semantic perspective. Which of these would you recommend? Is there an alternative I am missing?

Joe Lane18:07:42

I'm not sure what you mean by "the query semantics get easier".

craftybones18:07:14

@joe.lane - Yes. So if I have it in a tuple, my query will have to unpack the tuple and then do a check to see if either of the teams are the teams I want. I was wondering if there’s a way of matching elements within a tuple without having to unpack. Its an additional step

Joe Lane18:07:25

Is there a problem with that additional step? Is it too verbose, or too slow, etc?

Joe Lane18:07:38

FWIW I'm pretty sure you can also use tuple with your inputs to create the tuple you want to find. Then you don't need to untuple

Joe Lane18:07:23

You may even be able to just pass in the tuple pairs as inputs

Joe Lane18:07:55

(d/q '[:find (pull ?match [:match/score])
       :in $ [?teams ...]
       :where 
       [?match :match/teams ?teams]
       [?match :tourney/dates ?d]
       [(>= ?d ?start-date)]
       [(<= ?d ?end-date)]]
  the-db [[team1 team2] [team2 team1]])
;; Note, works for an arbitrary number of team tuples, you just need to permute the order of #{team1 team2} => [[team1 team2] [team2 team1]]

craftybones15:07:09

@joe.lane - absolutely works! Thanks this is what I was looking for