close method

  1. @override
Future<void> close()
override

Releases resources owned by this database.

Implementations must allow this method to be called more than once.

Implementation

@override
Future<void> close() {
  if (_insideTransaction) {
    return Future<void>.error(
      const SqlException(
        SqlErrorCode.unsupported,
        'The parent database cannot be closed inside its transaction.',
      ),
    );
  }
  final existing = _closeFuture;
  if (existing != null) return existing;

  _closing = true;
  final pool = _pool;
  final closeFuture = pool == null
      ? _serial.run(() async {
          if (ownsConnection) {
            await _runPostgres(_connection!.close, operation: 'close');
          }
        })
      : _closePool(pool);
  _closeFuture = closeFuture;
  return closeFuture;
}