
Crux Jupiter Assignment: Delete Transactions

Introduction
This is the delete
installment of the Crux tutorial.
We shall assume you have a Crux standalone node set up locally and are now comfortable with put
operations and basic datalog queries.
If this is not the case, you can find all you need to know on Earth, Pluto and Mercury. Click on a destination above to take you there.
Arrival on Jupiter
You approach Jupiter and marvel at its bands. You wish you could have seen it this close before the Great Red Spot dissipated.
As you enter the Jovian atmosphere your communications panel lights up with the now expected, but rather terse message from boundary control.
Jupiter’s boundary is controlled.
If you wish to enter, present your papers now.
The government is asking to see your flight manifest.
Space Port
It’s a turbulent ride down to the space port.
To take your mind off the colossal storm outside, you check the Crux manual for the delete
operation.
Currently there are only four transaction operations in Crux:
put
,delete
,match
andevict
.
Operation Description
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
Delete:
The
delete
operation takes a valid eid with the option to include a start and endvalid-time
.
- Time in Crux is denoted
#inst "yyyy-MM-ddThh:mm:ss"
. For example, 9:30 pm on January 2nd 1999 would be written:
#inst "1999-01-02T21:30:00"
.The document will be deleted as of the transaction time, or between the start and end
valid-time
if provided. Historical versions of the document that fall outside of thevalid-time
window will be preserved.
- A complete delete transaction has the form:
[:crux.tx/delete eid valid-time-start valid-time-end]
Read More
Assignment
You land on the raised platform and open your job ticket:
Task |
|
Company |
|
Contact |
|
Submitted |
|
Additional information |
|
Attachments |
— |
As you leave your ship, you are met by the martian Kaarlang:
Hi there, I believe you’re here to help me.
I’ve been told I need to delete my client history with today being my last day.
Is this something you can help me with?
Helios Banking Inc.
Choose your path
"Yes, we’ll work together to do this." | "I’m not sure how to even begin." |
---|

Kaarlang gives you his client history so you can sync up your Crux node.
(crux/submit-tx
node [[:crux.tx/put {:crux.db/id :kaarlang/clients
:clients [:encompass-trade]}
#inst "2110-01-01T09"
#inst "2111-01-01T09"]
[:crux.tx/put {:crux.db/id :kaarlang/clients
:clients [:encompass-trade :blue-energy]}
#inst "2111-01-01T09"
#inst "2113-01-01T09"]
[:crux.tx/put {:crux.db/id :kaarlang/clients
:clients [:blue-energy]}
#inst "2113-01-01T09"
#inst "2114-01-01T09"]
[:crux.tx/put {:crux.db/id :kaarlang/clients
:clients [:blue-energy :gold-harmony :tombaugh-resources]}
#inst "2114-01-01T09"
#inst "2115-01-01T09"]])
;;=> #:crux.tx{:tx-id 0, :tx-time #inst "2020-06-18T15:55:00.894-00:00"}
To get a good visual aid, you show Kaarlang how to view his client history.
This way you both can see when the clients are deleted.
You use the option :with-docs?
to show the content of the doc.
(crux/entity-history
(crux/db node #inst "2116-01-01T09")
:kaarlang/clients
:desc
{:with-docs? true})
#_#_
=> [{:crux.tx/tx-time #inst "2020-06-18T15:57:28.900-00:00",
:crux.tx/tx-id 1,
:crux.db/valid-time #inst "2114-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "d4bca6c78409d9d40ee42319a8aec32bffad9030",
:crux.db/doc
{:crux.db/id :kaarlang/clients,
:clients [:blue-energy :gold-harmony :tombaugh-resources]}}
{:crux.tx/tx-time #inst "2020-06-18T15:57:28.900-00:00",
:crux.tx/tx-id 1,
:crux.db/valid-time #inst "2113-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "000e5b775b55d06f0bddc77d736184284aa1e4e9",
:crux.db/doc {:crux.db/id :kaarlang/clients, :clients [:blue-energy]}}
{:crux.tx/tx-time #inst "2020-06-18T15:57:28.900-00:00",
:crux.tx/tx-id 1,
:crux.db/valid-time #inst "2111-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "cd71551fe21219db59067ce7483370fdebaae8b0",
:crux.db/doc
{:crux.db/id :kaarlang/clients, :clients [:encompass-trade :blue-energy]}}
{:crux.tx/tx-time #inst "2020-06-18T15:57:28.900-00:00",
:crux.tx/tx-id 1,
:crux.db/valid-time #inst "2110-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "5ec42ea653288e01e1a9d7d2068b4658416177e0",
:crux.db/doc {:crux.db/id :kaarlang/clients, :clients [:encompass-trade]}}]
The result shows the names of the clients that have been assigned to Kaarlang since he started at the company in 2110.
Next you delete the whole history of clients buy choosing a start and end valid-time
that spans his entire employment time.
(crux/submit-tx
node [[:crux.tx/delete :kaarlang/clients #inst "2110-01-01" #inst "2116-01-01"]])
;;=> #:crux.tx{:tx-id 1, :tx-time #inst "2020-06-18T15:59:38.323-00:00"}
Using the same method as before you show Kaarlang the effect of this operation.
(crux/entity-history
(crux/db node #inst "2116-01-01T09")
:kaarlang/clients
:desc
{:with-docs? true})
#_#_
=> [{:crux.tx/tx-time #inst "2020-06-18T15:59:38.323-00:00",
:crux.tx/tx-id 2,
:crux.db/valid-time #inst "2115-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "0000000000000000000000000000000000000000",
:crux.db/doc nil}
{:crux.tx/tx-time #inst "2020-06-18T15:59:38.323-00:00",
:crux.tx/tx-id 2,
:crux.db/valid-time #inst "2114-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "0000000000000000000000000000000000000000",
:crux.db/doc nil}
{:crux.tx/tx-time #inst "2020-06-18T15:59:38.323-00:00",
:crux.tx/tx-id 2,
:crux.db/valid-time #inst "2113-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "0000000000000000000000000000000000000000",
:crux.db/doc nil}
{:crux.tx/tx-time #inst "2020-06-18T15:59:38.323-00:00",
:crux.tx/tx-id 2,
:crux.db/valid-time #inst "2111-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "0000000000000000000000000000000000000000",
:crux.db/doc nil}
{:crux.tx/tx-time #inst "2020-06-18T15:59:38.323-00:00",
:crux.tx/tx-id 2,
:crux.db/valid-time #inst "2110-01-01T09:00:00.000-00:00",
:crux.db/content-hash #crux/id "0000000000000000000000000000000000000000",
:crux.db/doc nil}
{:crux.tx/tx-time #inst "2020-06-18T15:59:38.323-00:00",
:crux.tx/tx-id 2,
:crux.db/valid-time #inst "2110-01-01T00:00:00.000-00:00",
:crux.db/content-hash #crux/id "0000000000000000000000000000000000000000",
:crux.db/doc nil}]
Kaarlang is impressed it is that easy. You point out that there are no longer any documents attached to the transactions.
I am grateful that you took the time to show me this.
Today is a sad day for me as I have very much enjoyed my time here.
Although, I was expecting to hear from a friend before I left. There is a very important message that I am waiting for.
Speaking from the heart
You remember the secret note in your pocket and pass it to Kaarlang.
The Secret Note
Kaarlang reads the note.
He looks at you with the a peculiar facial expression.
This is the note I was waiting for.
It has information about the a top secret stellar transport shuttle.
If you are interested in a great adventure, the shuttle comes once every hundred years or so to take a select few to a nearby star system. The system is home to a mysterious hyper-intelligent form of life.
I’m sure there would be a place for you if you were willing to help out. The passengers on the shuttle have the right to be forgotten. We need someone that can remove the passengers data from the solar system.
What do you think?