@@ -9,34 +9,50 @@ Future<Response> fetch(Request _) async {
99
1010 final client = Client (dbUrl);
1111 await client.connect ();
12- final result = await client.transaction (
13- 'transaction' ,
14- transaction,
15- TransactionOptions (isolationLevel: IsolationLevel .serializable),
16- );
17- await client.end ();
12+ try {
13+ final result = await client.transaction (
14+ 'transaction' ,
15+ transaction,
16+ TransactionOptions (isolationLevel: IsolationLevel .serializable),
17+ );
18+ await client.end ();
1819
19- return Response (
20- [
21- result.command == CommandType .select,
22- 'warnings = ${result .warnings }' ,
23- '''
20+ return Response (
21+ [
22+ result.command == CommandType .select,
23+ 'warnings = ${result .warnings }' ,
24+ '''
2425rowDescription =
2526 columnCount = ${result .rowDescription ?.columnCount }
2627 columns =
2728${result .rowDescription ?.columns .map ((e ) => ' name = ${e .name }' ).join ('\n ' )}
2829 ''' ,
29- result.query.resultType,
30- ...result.rows.map (rowToPrettyString),
31- ].join ('\n\n ' ),
32- );
30+ result.query.resultType,
31+ ...result.rows.map (rowToPrettyString),
32+ ].join ('\n\n ' ),
33+ );
34+ } on TransactionError catch (e) {
35+ await client.end ();
36+
37+ return Response ('''
38+ ${e .name }
39+ ${e .cause }
40+ ${e .cause .name }
41+ ${e .cause .cause }
42+ ${e .cause .message }
43+ ${e .cause .fields }
44+ ${e .message }
45+ $e
46+ ''' );
47+ }
3348}
3449
3550Future <QueryObjectResult <dynamic >> transaction (Transaction transaction) async {
3651 await transaction.queryObject (
3752 'UPDATE public."User" '
3853 r'SET username=$1 '
39- "WHERE last_name='user'" ,
54+ "WHERE last_name='user'"
55+ 'AND y = z' ,
4056 ["'user${transaction .hashCode }'" ],
4157 );
4258 await Future .delayed (const Duration (seconds: 10 ));
0 commit comments