This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-07
Channels
- # babashka (7)
- # beginners (218)
- # boot (1)
- # chlorine-clover (2)
- # cider (36)
- # cljsrn (8)
- # clojure (71)
- # clojure-dev (9)
- # clojure-europe (11)
- # clojure-france (1)
- # clojure-italy (5)
- # clojure-nl (5)
- # clojure-uk (24)
- # clojurescript (9)
- # conjure (16)
- # cursive (65)
- # datomic (76)
- # devcards (21)
- # emacs (1)
- # etaoin (1)
- # figwheel-main (47)
- # fulcro (37)
- # hyperfiddle (9)
- # java (2)
- # kaocha (1)
- # malli (11)
- # music (14)
- # observability (8)
- # off-topic (32)
- # re-frame (13)
- # reagent (2)
- # reitit (5)
- # ring (3)
- # shadow-cljs (40)
- # slack-help (17)
- # spacemacs (15)
- # tools-deps (5)
- # xtdb (16)
I found a convenient way to quote the transaction function correctly:
(backtick/template (fn [ctx eid]
(let [db (crux.api/db ctx)
entity (crux.api/entity db eid)]
[[:crux.tx/put (~`custom-fn entity)]])))
https://github.com/brandonbloom/backtickOh cool, I've not seen backtick before, but this same general idea came up on the Crux Zulip the other day in regards conveniently constructing queries without all the awkward quote symbols - I'll repost this tip there!
I can also read on Zulip
Oh, that’s an awesome library.
maybe the most simple way to do function transaction is to directly associate a quoted qualified symbol to :crux.db/fn
(I did not try yet but it should work)
{:crux.db/id :product/foobar-tx-fn
:crux.db/fn `foobar-tx-fn}
we don't currently require
any symbols provided to transaction functions, because they could be anywhere in the body - and you might not want namespaced-qualified symbols requiring!
things like requiring-resolve
can be useful here - ((requiring-resolve 'your.ns/your-fn) ...)
there're a few namespaces that might currently work accidentally, but best not to rely on those 🙂
also, personal preference, but worth adding you can also use vanilla Clojure backtick here, if you haven't got too much gensym'ing to do
(clojure.core/let [user/db (crux.api/db user/ctx) ....
I am not sure that it would do what we want.
yep - you'd need to gensym the local variables using #
:
`(fn [ctx# eid#]
(let [db# (crux/db ctx#)
entity# (crux/entity db# eid#)]
...))
but then it's hard to read from the DB because a no-collision number is appended to the symbols
this version stays readable after evaluation
`(fn [~'ctx ~'eid]
(let [~'db (crux/db ~'ctx)
~'entity (crux/entity ~'db ~'eid)]
...))
IMHO, backtick/template
help reducing the typing