typedb-driver
typedb-driver copied to clipboard
Make Write and Read transactions distinguishable at compile-time
Problem to Solve
Suppose you're writing a function that takes a Transaction parameter, that you know needs to write to the DB, and would like the compilation to fail if you accidentally pass it a transaction that could be read-only.
Current Workaround
Use Transaction
/ TypeDBTransaction
and write correct code.
Proposed Solution
@dmitrii-ubskii has proposed the following structure for the Rust driver:
pub struct Read;
pub struct Write;
pub struct Transaction<Type>; // Read or Write
It's achievable, but requires buy-in from the rest of the architecture, as those generics are infectious.
Additional Information
In Java we'd have used subclasses - TypeDBTransaction.Write
and TypeDBTransaction.Read
.