This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-24
Channels
- # announcements (26)
- # babashka (9)
- # beginners (63)
- # calva (2)
- # chlorine-clover (22)
- # cider (2)
- # cljsrn (8)
- # clojure (36)
- # clojure-europe (36)
- # clojure-italy (5)
- # clojure-nl (76)
- # clojure-spec (9)
- # clojure-uk (8)
- # clojurescript (39)
- # conjure (24)
- # cursive (19)
- # data-science (1)
- # datascript (10)
- # datomic (1)
- # emacs (2)
- # events (5)
- # figwheel-main (9)
- # fulcro (21)
- # graalvm (1)
- # helix (5)
- # jobs (1)
- # jobs-discuss (1)
- # kaocha (1)
- # leiningen (4)
- # meander (2)
- # off-topic (22)
- # re-frame (16)
- # reitit (3)
- # rewrite-clj (75)
- # rum (1)
- # sci (51)
- # shadow-cljs (110)
- # tools-deps (16)
- # vrac (9)
- # xtdb (23)
I want todo a count on the number of prices in a database, this works fine using (count ?prices) except when there are none then I get no data returned from the query how can i handle this so 0 is returned ?
Not sure how to achieve that within the query itself, but you could wrap the query in an or expression:
(or (my-query db) 0)
I think the issue with that is the query returns multiple fields, I always want the other fields only the aggregate to be 0 and not remove the other data
Ah I think I misunderstood your original question. Could you post an example of the query?
(d/q '[:find ?e ?i ?n ?slug (count ?eid2)
:keys eid id product/name product/slug ?prices
:in $ ?product-id
:where
[?e :product/id ?i]
[?eid2 :price/product ?prices]
[?e :product/name ?n]
[?e :product/slug ?slug]] @conn product-id)
That's what i currently have, I can split it out in this situation but Its something that would be good to know how to achieve
Is that ?eid2
supposed to fetch all prices in the DB? It doesn't seem to be related to any other clause in the query. If so, I'd just do a separate query for it (queries are cheap, don't need to join them into one big one). Otherwise, if you want to fetch something that may or may not exist (but want to ensure it's absence does not remove it from the result set), you want to pull that info, not query it. A pull would work like a maybe
, but a where clause works like a must
.