This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-27
Channels
- # announcements (7)
- # aws (1)
- # beginners (42)
- # calva (65)
- # clj-kondo (5)
- # cljs-dev (11)
- # clojure (69)
- # clojure-australia (7)
- # clojure-dev (4)
- # clojure-europe (9)
- # clojure-gamedev (2)
- # clojurescript (2)
- # conjure (4)
- # cursive (1)
- # data-science (1)
- # datomic (8)
- # events (1)
- # fulcro (35)
- # graalvm-mobile (40)
- # introduce-yourself (1)
- # lsp (26)
- # malli (14)
- # mathematics (2)
- # missionary (5)
- # nextjournal (4)
- # off-topic (4)
- # polylith (10)
- # shadow-cljs (5)
- # test-doc-blocks (1)
- # tools-build (24)
- # tools-deps (1)
- # xtdb (12)
How are people handling updates for documents? It seems counter-intuitive to me that :xt/put
wouldn’t merge an existing entity.
You can think of it that you're not really modifying an existing document, you are adding a new version of the document. Existing documents are immutable.
In Datomic, everything is attribute/value tuples -- no documents -- so you are always adding new attribute/value tuples: it's sort of more obvious that you're not modifying existing attribute/value tuples.
There's also the whole issue of time: valid time and transaction time. So if you think of "modifying" an existing document, which version are you modifying?
If you find yourself repeatedly "modifying" the most recent version of a document, you can use a transaction function to assoc
in a new value for one or more keys.
That totally makes sense; the Datomic comparison really clarifies it for me
Coming from a SQL/RDBMS background, it's hard for me to shake off UPDATE table SET column = ? WHERE id = ?
🙂
I guess the preferred method is to query then transact or use the transaction function?
Preferred? Depends what you actually need to do in regards to time-based versions I guess.
I use match operations + retries myself since my app has low traffic, so either approach would be fast enough. I figure if I get scale and start having problems with contention, then I can switch to a tx function.
I do it via a helper function, so the document I transact looks like e.g. {:xt/id #uuid "...", :db/merge true, :user/foo "..."}
, then the helper fn queries the current version of the doc, adds a match operation to the tx, and retries a few times if the tx fails.