transaction method
Implementation
@override
Future<ChalonaResponse> transaction(TransactionFn fn) async {
var connection = await _connect();
dynamic r;
r = await connection.runTx((tr) async {
return await fn(PsqlTransaction(tr));
});
await connection.close();
if (r is ChalonaResponse) {
return r;
}
// no hay datos
if (r.isEmpty) {
return ChalonaResponse(
source: {'ok': true, 'msg': 'no-results', 'data': {}});
}
// es un mapa de datos, con ok, msg y data
if (r.length == 1 && r.first.containsKey('ok')) {
return ChalonaResponse(source: r.first);
}
// es una lista de datos
return ChalonaResponse(source: {
'ok': true,
'msg': '',
'data': {'result': r}
});
}