This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-23
Channels
- # announcements (29)
- # babashka (6)
- # beginners (55)
- # biff (4)
- # clj-kondo (5)
- # clojure (162)
- # clojure-austin (2)
- # clojure-europe (38)
- # clojure-nl (1)
- # clojure-norway (9)
- # clojure-sweden (2)
- # clojure-uk (10)
- # clojuredesign-podcast (5)
- # clojurescript (7)
- # conjure (8)
- # core-async (4)
- # cursive (34)
- # datahike (13)
- # datomic (9)
- # fulcro (5)
- # holy-lambda (2)
- # honeysql (1)
- # hugsql (3)
- # hyperfiddle (22)
- # jobs (5)
- # london-clojurians (1)
- # malli (2)
- # matrix (3)
- # off-topic (32)
- # pedestal (26)
- # polylith (18)
- # reitit (5)
- # releases (1)
- # ring (29)
I've got some questions arising from trying to understand how biff/submit-tx
works (apologies if my way of referring to things is a bit rough (/ non-standard?)):
1. https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L702-L710: what is the point of the destructuring of ctx
? The function body is simply (bxt/submit-tx ctx biff-tx)
. Is anything done with the destructured retry
and node
? I see the same thing with https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L673-L690 as well.
2. is com.biffweb/biff-tx->xt
at https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L673 used? I see that com.biffweb/submit-tx
calls com.biffweb.impl.xtdb/submit-tx
, which then calls its own separate biff-tx->xt
function
I'm providing the code inline here for easy viewing:
;; com.biffweb
(defn biff-tx->xt ;; L673-690
"Converts the given Biff transaction into an XT transaction.
The elements of biff-tx may be maps (in which case they are treated as Biff
operations) or vectors (in which case they are treated as XT operations). For
example:
[{:db/doc-type :user
:xt/id #uuid \"...\"
:user/name \"example\"}
[:xtdb.api/put {:xt/id #uuid \"...\"}]]
biff-tx may optionally be a function which takes ctx and returns a Biff
transaction.
See ."
[{:keys [biff/now biff/db biff/malli-opts] :as ctx} biff-tx]
(bxt/biff-tx->xt ctx biff-tx))
;; ...
(defn submit-tx ;; L702-710
"High-level wrapper over xtdb.api/submit-tx. See biff-tx->xt.
If retry is true, the transaction will be passed to submit-with-retries."
[{:keys [biff.xtdb/retry biff.xtdb/node]
:or {retry true}
:as ctx}
biff-tx]
(bxt/submit-tx ctx biff-tx))
1. It's for documentation--e.g. if you look at the docstring in your editor, it'll presumably show the function arguments like so:
; com.biffweb/submit-tx
; ([{:keys [biff.xtdb/retry biff.xtdb/node], :or {retry true}, :as ctx} biff-tx])
; High-level wrapper over xtdb.api/submit-tx. See biff-tx->xt.
;
; If retry is true, the transaction will be passed to submit-with-retries.
(that's how it looks with my editor setup anyway). Same goes for the auto-generated API docs on the website: https://biffweb.com/docs/api/xtdb/#submit-tx
2. It's not used anywhere else in com.biffweb
or in the starter app, but it's there in case anyone wants to use it. com.biffweb
is the public API for the Biff library code; anything in the com.biffweb.impl.*
namespaces isn't meant to be used by library consumers/application developers (no guarantee there won't be breaking changes). Mainly that function is probably useful for people to experiment with in the repl, so you can take a Biff transaction and see the regular XTDB transaction that it gets turned into.