This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-12
Channels
- # babashka (6)
- # beginners (23)
- # calva (27)
- # cider (1)
- # clj-kondo (23)
- # cljsrn (2)
- # clojars (4)
- # clojure (90)
- # clojure-dev (8)
- # clojure-europe (1)
- # clojure-serbia (1)
- # clojure-spec (2)
- # clojurescript (9)
- # code-reviews (7)
- # core-async (1)
- # cursive (4)
- # datomic (13)
- # emacs (2)
- # hoplon (28)
- # juxt (12)
- # leiningen (1)
- # malli (22)
- # nrepl (3)
- # off-topic (51)
- # reitit (8)
- # shadow-cljs (16)
- # spacemacs (25)
- # sql (4)
- # test-check (5)
- # tools-deps (5)
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?
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
the final option is :match/team-1
with the query containing an or now
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?
@srijayanth Are you still trying to do https://clojurians.slack.com/archives/C03RZMDSH/p1594141743022500
@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
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
(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]]
@joe.lane - absolutely works! Thanks this is what I was looking for