From 753b8f6ec42aab68f99806c26663f1c3d3954355 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 9 Oct 2019 10:43:50 -0400 Subject: [PATCH] Update Postgres transaction signatures --- .../lib/angel_orm_postgres.dart | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/angel_orm_postgres/lib/angel_orm_postgres.dart b/angel_orm_postgres/lib/angel_orm_postgres.dart index 182370de..fb522bad 100644 --- a/angel_orm_postgres/lib/angel_orm_postgres.dart +++ b/angel_orm_postgres/lib/angel_orm_postgres.dart @@ -24,7 +24,13 @@ class PostgreSqlExecutor extends QueryExecutor { PostgreSQLExecutionContext get connection => _connection; /// Closes the connection. - Future close() => (_connection as PostgreSQLConnection).close(); + Future close() { + if (_connection is PostgreSQLConnection) { + return (_connection as PostgreSQLConnection).close(); + } else { + return Future.value(); + } + } @override Future> query( @@ -42,18 +48,16 @@ class PostgreSqlExecutor extends QueryExecutor { } @override - Future transaction(FutureOr Function() f) async { - if (_connection is! PostgreSQLConnection) return await f(); - var old = _connection; + Future transaction(FutureOr Function(QueryExecutor) f) async { + if (_connection is! PostgreSQLConnection) return await f(this); T result; try { logger?.fine('Entering transaction'); await (_connection as PostgreSQLConnection).transaction((ctx) async { - _connection = ctx; - result = await f(); + var tx = PostgreSqlExecutor(ctx, logger: logger); + result = await f(tx); }); } finally { - _connection = old; logger?.fine('Exiting transaction'); return result; } @@ -130,7 +134,7 @@ class PostgreSqlExecutorPool extends QueryExecutor { } @override - Future transaction(FutureOr Function() f) { + Future transaction(FutureOr Function(QueryExecutor) f) { return _pool.withResource(() async { var executor = await _next(); return executor.transaction(f);