This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-23
Channels
- # adventofcode (21)
- # announcements (4)
- # babashka (35)
- # beginners (36)
- # calva (76)
- # cider (16)
- # clj-kondo (24)
- # clj-on-windows (12)
- # clojure (70)
- # clojure-europe (7)
- # clojure-nl (13)
- # clojure-spec (3)
- # clojure-uk (3)
- # clojurescript (34)
- # conjure (11)
- # cursive (22)
- # datomic (30)
- # deps-new (2)
- # emacs (36)
- # fulcro (28)
- # gratitude (4)
- # honeysql (16)
- # hugsql (8)
- # introduce-yourself (6)
- # jobs (1)
- # malli (4)
- # missionary (6)
- # off-topic (129)
- # other-languages (34)
- # polylith (3)
- # reagent (9)
- # reitit (27)
- # releases (13)
- # remote-jobs (1)
- # reveal (1)
- # shadow-cljs (2)
- # tools-build (3)
- # tools-deps (18)
- # web-security (7)
- # xtdb (4)
Why does this query break?
(xt/q (xt/db xt-node) '{:find [(pull e [*])]
:in [attr value]
:where [[e attr value]]}
:ns/id
"123")
ST
{:problems
({:path [:where :triple :a],
:pred xtdb.codec/valid-id?,
:val attr,
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/triple],
:in [:where 0 1]}
{:path [:where :not],
:pred clojure.core/seq?,
:val [e attr value],
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/not],
:in [:where 0]}
{:path [:where :not-join],
:pred clojure.core/seq?,
:val [e attr value],
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/not-join],
:in [:where 0]}
{:path [:where :or],
:pred clojure.core/seq?,
:val [e attr value],
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/or],
:in [:where 0]}
{:path [:where :or-join],
:pred clojure.core/seq?,
:val [e attr value],
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/or-join],
:in [:where 0]}
{:path [:where :range],
:pred
(clojure.core/= (clojure.core/count %) 1),
:val [e attr value],
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/range],
:in [:where 0]}
{:path [:where :rule],
:pred clojure.core/list?,
:val [e attr value],
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/rule],
:in [:where 0]}
{:path [:where :pred :pred],
:pred clojure.core/seq?,
:val e,
:via
[:xtdb.query/query
:xtdb.query/where
:xtdb.query/term
:xtdb.query/pred],
:in [:where 0 0]}),
:spec :xtdb.query/query,
:value
{:find [(pull e [*])],
:in [attr value],
:where [[e attr value]]}}
It seems that i can't pass attribute
keyword as an argument with :in?
There are ways to make this query by quoting differently but i expected this to work?
Am i missing something?Unfortunately XT doesn't support variable attributes like that, and funnily enough it was discussed briefly just few days ago in this channel https://clojurians.slack.com/archives/CG3AM2F7V/p1639937504405000 🙂 There is a small note in the docs here (which perhaps needs to be more prominent) https://docs.xtdb.com/language-reference/1.20.0/datalog-queries/#datascript-differences If you really need something clever in this space though, then you can achieve it like this: https://gist.github.com/refset/93135adcbf41fccab9b641638ab10997
Thanks! i dont think i need anything complex, i think first link/suggestion would serve the purpose because i want to have it parameterized. The problem is i don't know how to make it work. this was giving me problems
(defn foo [attribute]
'{:find [(pull e [*])]
:into [?entity-id]
:where [[e ~attribute ?entity-id]]})
so i ended up with
(defn foo [attribute]
{:find '[(pull e [*])]
:into '[?entity-id]
:where [['e attribute ?entity-id]]})