class_docstr: Abstraction for querying databases with user-supplied connection objects.
class_docstr_tok: ["Abstraction","for","querying","databases","with","user-supplied","connection","objects","."]
docstr: Normalise a connection object such that we have the query executor.
docstr_tok: ["Normalise","a","connection","object","such","that","we","have","the","query","executor","."]
code: def _normalise_cursor(self, conn: ConnectionOrCursor) -> Cursor:
      """Normalise a connection object such that we have the query executor."""
      if (
          self.driver_name == "sqlalchemy"
          and type(conn).__name__ == "Engine"
      ):
          self.can_close_cursor = True
          if conn.driver == "databricks-sql-python":  # type: ignore[union-attr]
              # take advantage of the raw connection to get arrow integration
              self.driver_name = "databricks"
              return conn.raw_connection().cursor()  # type: ignore[union-attr, return-value]
          else:
              # sqlalchemy engine; direct use is deprecated, so prefer the connection
              return conn.connect()  # type: ignore[union-attr, return-value]
  
      elif hasattr(conn, "cursor"):
          # connection has a dedicated cursor; prefer over direct execute
          cursor = (
              cursor() if callable(cursor := conn.cursor) else cursor
          )
          self.can_close_cursor = True
          return cursor
  
      elif hasattr(conn, "execute"):
          # can execute directly (given cursor, sqlalchemy connection, etc)
          return conn  # type: ignore[return-value]
  
      raise TypeError(
          f"Unrecognised connection {conn!r}; unable to find 'execute' method"
      )
  
imports: from __future__ import annotations
  import re
  import sys
  from importlib import import_module
  from inspect import Parameter, signature
  from typing import TYPE_CHECKING, Any, Iterable, Literal, Sequence, TypedDict, overload
  from polars.convert import from_arrow
  from polars.exceptions import InvalidOperationError, UnsuitableSQLError
  from polars.utils.deprecation import issue_deprecation_warning
label_desc: Use image node_id 6 for calling the ConnectionExecutor obj's underlying member method code with example usage: obj._normalise_cursor(conn) and returns: conn, conn, cursor, conn