Fork me on GitHub
#xtdb
<
2021-12-23
>
lepistane15:12:38

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?

refset15:12:29

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

lepistane20:12:29

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]]})

🙏 1
refset21:12:19

cool, and yes backticks get confusing because everything is namespaced. I usually avoid them unless it's necessary for a macro or something