reconnectIfNecessary method

  1. @override
Future<bool> reconnectIfNecessary()

Implementation

@override
Future<bool> reconnectIfNecessary() async {
  try {
    await connection!.query('select true');
    return true;
  } catch (e) {
    //when the database restarts there is a loss of connection
    if ('$e'.contains('Cannot write to socket, it is closed') ||
        '$e'.contains('database connection closing')) {
      await reconnect();
      return true;
    }
    rethrow;
  }
}