Fork me on GitHub
#xtdb
<
2022-09-10
>
Jesse07:09:34

Hi all! I have been using XTDB for a while now and it is amazing. Now I'm trying to use the history capabilities. Basically I want to display the edit history of some documents along with which user made the edit (users are entities in the db) and the option to view the document at a time in the history. Is it possible to fetch the history of a document in XTDB, and perhaps to attach some metadata to transactions (to track who made the edit)? Any pointer are welcome, thanks!

malcolmsparks07:09:54

Hi Jesse. Thanks for your kind words. Yes, the API function is entity-history. See https://docs.xtdb.com/clients/clojure/#_entity_history

malcolmsparks07:09:52

You can add transaction metadata by creating a separate document describing who made the edit and linking it from the document you're putting.

malcolmsparks07:09:44

If you're putting multiple docs in the same tx, one thing you can do is use a transaction function to add a 'metadata' document. The tx-id is available when you're in a transaction function, so you can add it as an attribute to your metadata document. That way, you can query a metadata document back, given a transaction id.

Jesse08:09:56

Clear, that will work fine 👌 Falling in love with XTDB. Just having a hard time finding the right info sometimes, thanks for the help!

malcolmsparks07:09:00

Let us know if you need any further help.

Dustin Getz11:09:10

can xtdb branch like git?

refset21:09:16

Hey @U09K620SG, as Malcolm said - no, not currently. What kind of use-cases most interest you? Testing? Multi-master replication?

refset21:09:10

There is the with-tx API, which could simulate what you're showing here, I think

Dustin Getz21:09:52

Conor at Roam Research was interested in a multiplayer SVG editor with undo/redo where the history was tracked in a database - that was the origin of my question

Dustin Getz21:09:08

Other than that yeah, experimental UI stuff

refset22:09:11

Oh cool, SVG is great. I'm a big Inkscape fan too. I've been playing with https://github.com/babashka/scittle a fair bit lately to generate SVGs dynamically

malcolmsparks11:09:08

No. Although that would be cool. 🙂