startTransaction method
Future<Transaction>
startTransaction({
- required TransactionHeaders headers,
- int maxWait = 2000,
- int timeout = 5000,
- TransactionIsolationLevel? isolationLevel,
override
Starts a transaction.
headersare the headers to be sent with the request.maxWaitis the maximum amount of time to wait for the transaction to start.timeoutis the maximum amount of time to wait for the transaction to complete.isolationLevelis the isolation level to be used for the transaction.
Implementation
@override
Future<Transaction> startTransaction({
required TransactionHeaders headers,
int maxWait = 2000,
int timeout = 5000,
TransactionIsolationLevel? isolationLevel,
}) async {
await start();
final endpoint = await _serverEndpoint();
final response = await fetch(
endpoint.resolve('/transaction/start'),
method: 'POST',
headers: headers,
body: {
'max_wait': maxWait,
'timeout': timeout,
if (isolationLevel != null) 'isolation_level': isolationLevel.name,
},
);
final result = await response.json();
return switch (result) {
{'id': final String id} => Transaction(id),
{'errors': final Iterable errors} => throw Exception(errors),
_ => throw Exception(result),
};
}