Fork me on GitHub
#xtdb
<
2020-05-31
>
mac18:05:29

Hey all, is it possible to parameterise the attributes in a query? I have found examples of how to parameterise the values using :args but this approach apparently does not work with attributes.

jarohen18:05:55

Hey @U09UV3WP6 - I'm afraid Crux doesn't generally support dynamic attributes in queries using args. That said, so long as it's not directly dependent on user input (to avoid injection attacks) you can dynamically generate the query itself using Clojure's standard functions - the query itself is a data structure. eg rather than '{:find [?e] :where [?e :attr "attr"]} you can move the quote inside the data structure, quoting everything except the attribute:

(let [attr ...] 
  {:find '[?e] :where ['?e attr "attr"]}
which may be sufficient for your use-case?

mac18:05:06

Got it, I think that will work nicely.

mac21:05:58

Yeah that worked great, thanks.

jarohen08:06:49

great 🙂 you're welcome