This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-05
Channels
- # aleph (1)
- # announcements (1)
- # babashka (6)
- # beginners (25)
- # biff (6)
- # calva (61)
- # clojure (15)
- # clojure-europe (2)
- # clojurescript (34)
- # cursive (7)
- # events (2)
- # figwheel-main (5)
- # fulcro (10)
- # gratitude (1)
- # malli (2)
- # pathom (1)
- # polylith (3)
- # portal (1)
- # re-frame (3)
- # reagent (10)
- # releases (2)
- # shadow-cljs (19)
- # spacemacs (5)
- # xtdb (2)
Can I do queries with a variable attribute name? like
(defn pull-by [node query-map]
(let [[key0 val0, :as entry0] (first query-map)]
(prn ::kv key0 val0)
(ffirst
(xt/q
(xt/db node)
'{:find [(pull ?e [*])]
:in [attr-name attr-val]
:where [[?e attr-name attr-val]]}
key0 val0))))
Nope, XT requires all attributes to be known ahead of time for query compilation. You can however just generate various queries dynamically as needed (compilation overheads are often negligible):
(defn pull-by [node query-map]
(let [[key0 val0, :as entry0] (first query-map)]
(prn ::kv key0 val0)
(ffirst
(xt/q
(xt/db node)
{:find '[(pull ?e [*])]
:in '[attr-val]
:where [['?e key0 'attr-val]]}
val0))))
❤️ 1