pub struct TransactionBuilder<Err> { /* private fields */ }Expand description
Helper to build a transaction
Implementations§
Source§impl<Err> TransactionBuilder<Err>
impl<Err> TransactionBuilder<Err>
Sourcepub fn rw(self) -> Self
pub fn rw(self) -> Self
Allow writes in this transaction
Without this, the transaction will only be allowed reads, and will error upon trying to write objects.
Sourcepub async fn run<Fun, RetFut, Ret>(self, transaction: Fun) -> Result<Ret, Err>where
Fun: 'static + FnOnce(Transaction<Err>) -> RetFut,
RetFut: 'static + Future<Output = Result<Ret, Err>>,
Ret: 'static,
Err: 'static,
pub async fn run<Fun, RetFut, Ret>(self, transaction: Fun) -> Result<Ret, Err>where
Fun: 'static + FnOnce(Transaction<Err>) -> RetFut,
RetFut: 'static + Future<Output = Result<Ret, Err>>,
Ret: 'static,
Err: 'static,
Actually execute the transaction
The transaction argument defines what will be run in the transaction. Note that due to
limitations of the IndexedDb API, the future returned by transaction cannot call .await
on any future except the ones provided by the Transaction itself. This function will
do its best to detect these cases to abort the transaction and panic, but you should avoid
doing so anyway. Note also that these errors are not recoverable: even if wasm32 were not
having panic=abort, once there is such a panic no indexed-db functions will work any
longer.
If transaction returns an Ok value, then the transaction will be committed. If it
returns an Err value, then it will be aborted.
Note that you should avoid sending requests that you do not await. If you do, it is hard
to say whether the transaction will commit or abort, due to both the IndexedDB and the
wasm-bindgen semantics.
Note that transactions cannot be nested.
Internally, this uses IDBDatabase::transaction.