-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Req] Optionally use Transaction if supported #582
Comments
Yeah, this is quite annoying. You can probably make things easier today by doing: let stuffs = |d: &Dataset| -> Result<()> { ... };
if /* transactions are supported */ {
let txn = d.start_transaction()?;
stuffs(&txn)?;
txn.commit()?;
} else {
stuffs(&d)?;
} I don't know if adding Another possibility would be to check for We could also add something like: enum TransactionMode {
/// Require the driver to support "efficient" transactions.
Normal,
/// Allow "emulated" (probably slower) transactions, if the driver supports them.
Forced,
/// Return a no-op `Transaction` if the driver doesn't support transactions,
/// which always succeeds on `commit` and fails on `rollback`.
/// These don't offer any ACID guarantees!
Yolo,
} |
Yeah, the function thing is nice because of deref. That's why I was thinking, "We're doing the operations on the inner dataset anyway, so it might be ok to add methods there". I was thinking we can error out on the commit without active transaction, but you're right, we won't catch it in compile time. So maybe the idea you have given about
For this, another way might be to add We can have |
Forgot to mention, but I'll do the implementation for this once we get to a reasonable idea we think is going to work. |
Would it be possible to use transaction if supported, else use normal dataset.
Considering the output dataset being able to use any driver user wants, I want to speed up the writing process when I can. If the output is to
gpkg
file I'd like to use transaction, if it's toshp
then the code I have will fail. So I'm hoping for something that can work on both cases.The Idea I have is, considering the code for
Transaction::commit
uses the internalDataset
, we can probably add thecommit
method on theDataset
and do something like this:Currently, You have to do something like this:
You can't use
if let ... {} else {}
pattern, as you can't borrowd
mutably onstart_transaction()
and on theelse
block at the same time. And due to rust's type system, you can't replaced: Dataset
withtxn: Transaction
to do the same thing (although you can with deref).But basically to write a code that works with drivers that support transaction and drivers that don't, I think the first pattern I suggested feels like the best way to do it, as the code is internally calling
commit
on theDataset
anyway.gdal/src/vector/transaction.rs
Lines 48 to 58 in 5d886ab
The text was updated successfully, but these errors were encountered: