How can I ensure that the data I pulled hasn’t changed when I compute new information and save it back?
even more specifically, if you're only transacting 'current' data, you can quite simply validate that the _system_from is what you expect and that the _system_to of the record you're trying to change is still NULL/`nil` (otherwise your ASSERT needs to repeat the data itself or rely on some other versioning pattern)
Here we go this is an example of bitemporality used out of the box 😆 But I'm not sure I understand how this works; when you pull data to your app, you also grab some system time that you compare back when you transact some new data to make sure it's the same?
Yep, essentially it's the same pattern as a 'CAS', but you can avoid re-sending the whole original value
BEGIN AT SYSTEM_TIME DATE '2020-01-01';
INSERT INTO docs (_id, col1) VALUES (1, 'foo');
COMMIT;
(hardcoding the inserted system time here so the example can be static)
ASSERT EXISTS (SELECT 1 FROM docs WHERE _id = 1 AND _system_from = DATE '2020-01-01' AND _system_to IS NULL);
INSERT INTO docs (_id, col1) VALUES (1, 'foo2');Transactions with asserts
https://docs.xtdb.com/xtql/tutorials/introducing-xtql.html#_assert and https://docs.xtdb.com/reference/main/sql/txs.html#_assert
Thanks