Suppose we interact with an XTDB v2 server over HTTP using the following:
;; Require `xtdb.api` as `xt`, `xtdb.client` as `xtc`
(def http-node-url "http://localhost:3000") ; as example
(def submit
(with-open [node (xtc/start-client http-node-url)]
(partial xt/submit-tx node)))
(def q
(with-open [node (xtc/start-client http-node-url)]
(partial xt/q node)))
A document can be created:
(submit [[:put-docs {:into :user}
{:xt/id 123
:version 1
:email "foo@bar.com"}]])
And can be retrieved:
(q '(from :user [*]))
;; Returns `[{:version 1, :email "foo@bar.com", :xt/id 123}]
Next, I tried to update the document using the example code from the docs:
(submit [[:update {:table :user
:bind [{:email $email}, version],
:set {:version (+ version 1)}}
{:email "foo@bar.com"}]])
This returns an error: “Unable to resolve symbol: $email in this context”
Unlike :put-docs
, :update
should be quoted:
(submit ['[:update {:table :user
:bind [{:email $email}, version],
:set {:version (+ version 1)}}
{:email "foo@bar.com"}]])
Upon querying the :user
table once more, the update is confirmed successful:
(q '(from :user [*]))
; Returns `[{:version 2, :email "foo@bar.com", :xt/id 123}]`
Clj-kondo complained about the $email
and version
symbols, at which point I figured the :update
vector should be quoted.
Not sure if the docs should be updated. Just a bit of feedback.