2: Put Transactions with XTDB – Pluto Assignment
This is the second part of the XTDB tutorial. The Earth instalment looked at setting up a simple XTDB standalone node and a very simple
You need to get XTDB running before you can use it.
Arrival on Pluto
As you enter the Plutonian atmosphere, a message pops up on your communication panel:
Welcome to the dwarf planet Pluto. You are entering privately governed space. If you do not have the correct papers, entry will be denied. We hope you enjoy your stay.
Have a nice day.
- Anarchic Directorate of Pluto
The government of Pluto is asking to see your flight manifest.
Choose your path:
As you circle the dwarf planet to land, you have a quick read of your XTDB manual. You know you will be using the
put operation a lot for this assignment and although you used the operation to add your manifest before you left, you think it is a good idea to brush up on your knowledge.
Currently there are only four transaction operations in XTDB: put, delete, match and evict.
put (Writes a version of a document)
delete (Deletes a version of a document)
match (Stops a transaction if the precondition is not met.)
evict (Removes a document entirely)
put transaction is used to write versions of a document (doc).
Each document must be in Extensible Data Notation (edn) and must contain a unique :xt/id value. However, beyond those two requirements you have the flexibility to add whatever you like to your documents because XTDB is schemaless.
Along with the document (doc), put has two optional additional arguments:
valid-time (The time at which the entry will be valid from.)
valid-time (The time at which the entry will be valid until.)
This means that you can query back through the database, you can use valid-time arguments to see the state of the database at a different time.
Time in XTDB is denoted
#inst "yyyy-MM-ddThh:mm:ss". For example, 9:30 pm on January 2nd 1999 would be written:
A complete put transaction has the form:
[::xt/put doc valid-time-start valid-time-end]
- XTDB manual Read More
You are happy with what you have read, and in anticipation of your first assignment you define the standalone node.
You land on the surface of the dwarf planet. As you do, the job ticket for this assignment is unlocked.
Tombaugh Resources Ltd.
We need help setting up a new recording system for our mine. I have enclosed a list of the commodities we deal with. Please send someone soon because we already have a week’s worth of unrecorded stocktakes.
You make your way over to the mines on the next shuttle. On your way you decide to get a head start and put the commodities into XTDB.
Since it takes six hours for each transaction to reach your XTDB node on Earth from here, it is a good idea to batch up all the commodities in a single transaction.
You arrive at the mine and are met by the CEO, Reginald Glogofloon, a 150 year old Plutonian.
Hello, I’m glad you’re here.
I would like you to fill in our last weeks worth of data on our commodities. We need to be able to look back at a given day and see what our stocks were for auditing purposes.
The stock for each day must be submitted at 6pm Earth time (UTC) for your banks records.
Are you able to do that for me?
- R. Glogofloon
Choose your path:
You remember that with XTDB you have the option of adding a
valid-time. This comes in useful now as you enter the weeks worth of stock takes for Plutonium.
You notice that the amount of Nitrogen and Methane has not changed which saves you some time:
The CEO is impressed with your speed, but a little skeptical that you have done it properly.
You gain their confidence by showing them the entries for Plutonium on two different days:
As a parting gift to them you create an easy ingest function so that if they needed to add more commodities to their stock list they could do it fast.
Tombaugh Resources Ltd. are happy that this will be simple enough to use. They thank you for the extra help and you head back to your ship.
You are back at your ship and check your communications panel. There is a new assignment waiting for you:
Congratulations on completing your first assignment.
We would like you to go to Mercury, the hub of the trade world. Their main trade center has a new IT department and want you to show them how to query XTDB"
- Helios Banking Inc.
It’s a long flight so you refuel, and update your manifest. You have been awarded a new badge, so you add this to your manifest.
You enter the countdown for lift off to Mercury. See you soon.
This repo is mounted by: Clojure