transaction method
Executes a remote transaction on the given id
.
Calling this method will first download the current data for the given
id
from the server. That data is then passed to transaction to be
processed. Once the transaction completes, the result of that method is
then saved in the database under the same id
.
Should the data on the server have been modified in between reading and
writing it, a TransactionRejected exception will be thrown. In addition,
the data returned by the transaction must be either null
or have the
same DataModel.id
as id
. Otherwise, a TransactionInvalid exception
is thrown.
The params
and headers
are simply forwarded to the internal calls to
findOne and save/delete. The onBeginSuccess
and onBeginError
methods can optionally be specified to add customized data handling for
the read request. In similar fashion, the onCommitSuccess
and
onCommitError
are passed to the writing operation that commits the
transaction.
Implementation
// coverage:ignore-start
Future<T?> transaction(
String id,
TransactionFn<T> transaction, {
Map<String, dynamic>? params,
Map<String, String>? headers,
OnData<T>? onBeginSuccess,
OnDataError<T>? onBeginError,
OnData<T>? onCommitSuccess,
OnDataError<T>? onCommitError,
}) =>
Transaction(
adapter: this,
httpClientFactory: () => httpClient,
).call(
id,
transaction,
params: params,
headers: headers,
onBeginSuccess: onBeginSuccess,
onBeginError: onBeginError,
onCommitSuccess: onCommitSuccess,
onCommitError: onCommitError,
);