startTransaction method
Future<Transaction>
startTransaction({
- required TransactionHeaders headers,
- int maxWait = 2000,
- int timeout = 5000,
- TransactionIsolationLevel? isolationLevel,
override
Starts a transaction.
headers
are the headers to be sent with the request.maxWait
is the maximum amount of time to wait for the transaction to start.timeout
is the maximum amount of time to wait for the transaction to complete.isolationLevel
is 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),
};
}