startTransaction method
Future<TransactionInfo>
startTransaction({
- required TransactionHeaders headers,
- TransactionOptions options = const TransactionOptions(),
override
Start a transaction.
Implementation
@override
Future<TransactionInfo> startTransaction(
{required TransactionHeaders headers,
TransactionOptions options = const TransactionOptions()}) async {
final Uri baseUrl = await url;
final Uri endpoint = baseUrl.replace(
pathSegments: [...baseUrl.pathSegments, 'transaction', 'start'],
);
final String body = jsonEncode({
'max_wait': options.maxWait,
'timeout': options.timeout,
'isolation_level': options.isolationLevel?.name,
});
final Response response = await post(
endpoint,
headers: {
...runtimeHttpHeadersBuilder(headers.toJson()),
'Content-Type': 'application/json',
},
body: body,
);
if (response.statusCode > 400) {
final e = PrismaClientUnknownRequestError('Bad request',
clientVersion: binaryVersion);
logEmitter.emit(PrismaLogLevel.error, e);
throw e;
}
final Map<String, dynamic> json = jsonDecode(response.body);
try {
throwGraphQLError(json['errors']);
} on Exception catch (e) {
logEmitter.emit(PrismaLogLevel.error, e);
rethrow;
}
return DataProxyTxInfo(json['id'],
endpoint: json['data-proxy']['endpoint']);
}