MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / __init__

Method __init__

lib/sqlalchemy/engine/base.py:130–173  ·  view source on GitHub ↗

Construct a new Connection.

(
        self,
        engine: Engine,
        connection: Optional[PoolProxiedConnection] = None,
        _has_events: Optional[bool] = None,
        _allow_revalidate: bool = True,
        _allow_autobegin: bool = True,
    )

Source from the content-addressed store, hash-verified

128 _nested_transaction: Optional[NestedTransaction]
129
130 def __init__(
131 self,
132 engine: Engine,
133 connection: Optional[PoolProxiedConnection] = None,
134 _has_events: Optional[bool] = None,
135 _allow_revalidate: bool = True,
136 _allow_autobegin: bool = True,
137 ):
138 """Construct a new Connection."""
139 self.engine = engine
140 self.dialect = dialect = engine.dialect
141
142 if connection is None:
143 try:
144 self._dbapi_connection = engine.raw_connection()
145 except dialect.loaded_dbapi.Error as err:
146 Connection._handle_dbapi_exception_noconnection(
147 err, dialect, engine
148 )
149 raise
150 else:
151 self._dbapi_connection = connection
152
153 self._transaction = self._nested_transaction = None
154 self.__savepoint_seq = 0
155 self.__in_begin = False
156
157 self.__can_reconnect = _allow_revalidate
158 self._allow_autobegin = _allow_autobegin
159 self._echo = self.engine._should_log_info()
160
161 if _has_events is None:
162 # if _has_events is sent explicitly as False,
163 # then don't join the dispatch of the engine; we don't
164 # want to handle any of the engine's events in that case.
165 self.dispatch = self.dispatch._join(engine.dispatch)
166 self._has_events = _has_events or (
167 _has_events is None and engine._has_events
168 )
169
170 self._execution_options = engine._execution_options
171
172 if self._has_events or self.engine._has_events:
173 self.dispatch.engine_connect(self)
174
175 # this can be assigned differently via
176 # characteristics.LoggingTokenCharacteristic

Callers

nothing calls this directly

Calls 5

_should_log_infoMethod · 0.80
engine_connectMethod · 0.80
raw_connectionMethod · 0.45
_joinMethod · 0.45

Tested by

no test coverage detected