disconnect method

Future<void> disconnect()

Closes the active database connection.

If no connection is active, this method does nothing gracefully. Sets the internal _connection reference to null.

{@tool example}

await reader.connect();
// ... use reader ...
await reader.disconnect();

{@end-tool}

@return A Future that completes when the connection is closed or if it was already closed.

Implementation

Future<void> disconnect() async {
  // Use `?.` for safe invocation if _connection is already null.
  await _connection?.close();
  _connection = null; // Ensure reference is cleared
  _logger.info('Disconnected from database');
}