Fork me on GitHub
#xtdb
<
2023-07-17
>
Samuel Ludwig14:07:09

running into an error when im trying to parameterize a key in the :where clause of an XTDBv2 datalog query evaluating this results in a status: 400 error (full err message in thread)

;; Breakies :'^(
(defn find-by [conn k v]
  (xt/q conn
        ['{:find [contact]
           :in [k v]
           :where [($ :contact [{k v
                                 :xt/* contact}])]}
         k v]))

(find-by xtdb-conn :xt/id 17)
whereas hard-coding the key returns fine
(defn find-by-id [conn v]
  (xt/q conn
        ['{:find [contact]
           :in [v]
           :where [($ :contact [{:xt/id v
                                 :xt/* contact}])]}
         v]))

(find-by-id xtdb-conn 17)
are parameterized keys not kosher? or is there something else I'm doing wrong?

Samuel Ludwig14:07:46

Full error message:

; Error in thread Thread[nREPL-session-3331506f-6cbc-4440-99c8-d4ee44272f94,5,main]
; Execution error (ExceptionInfo) at juxt.clojars-mirrors.hato.v0v8v2.hato.middleware/exceptions-response (middleware.clj:149).
; status: 400

jarohen14:07:39

yep, afraid we won't be supporting parameterised keys in v2 either. try something like this?

(defn find-by [conn k v]
  (xt/q conn
        [{:find '[contact]
          :in '[v]
          :where [(list '$ :contact [{k 'v, :xt/* 'contact}])]}
         v]))

Samuel Ludwig14:07:08

ahhhh okay, I really thought I was missing something- that helps a lot, thank you!

🙏 2