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

Class _ConnectionFairy

lib/sqlalchemy/pool/base.py:1195–1524  ·  view source on GitHub ↗

Proxies a DBAPI connection and provides return-on-dereference support. This is an internal object used by the :class:`_pool.Pool` implementation to provide context management to a DBAPI connection delivered by that :class:`_pool.Pool`. The public facing interface for this class

Source from the content-addressed store, hash-verified

1193
1194
1195class _ConnectionFairy(PoolProxiedConnection):
1196 """Proxies a DBAPI connection and provides return-on-dereference
1197 support.
1198
1199 This is an internal object used by the :class:`_pool.Pool` implementation
1200 to provide context management to a DBAPI connection delivered by
1201 that :class:`_pool.Pool`. The public facing interface for this class
1202 is described by the :class:`.PoolProxiedConnection` class. See that
1203 class for public API details.
1204
1205 The name "fairy" is inspired by the fact that the
1206 :class:`._ConnectionFairy` object's lifespan is transitory, as it lasts
1207 only for the length of a specific DBAPI connection being checked out from
1208 the pool, and additionally that as a transparent proxy, it is mostly
1209 invisible.
1210
1211 .. seealso::
1212
1213 :class:`.PoolProxiedConnection`
1214
1215 :class:`.ConnectionPoolEntry`
1216
1217
1218 """
1219
1220 __slots__ = (
1221 "dbapi_connection",
1222 "_connection_record",
1223 "_echo",
1224 "_pool",
1225 "_counter",
1226 "__weakref__",
1227 "__dict__",
1228 )
1229
1230 pool: Pool
1231 dbapi_connection: DBAPIConnection
1232 _echo: log._EchoFlagType
1233
1234 def __init__(
1235 self,
1236 pool: Pool,
1237 dbapi_connection: DBAPIConnection,
1238 connection_record: _ConnectionRecord,
1239 echo: log._EchoFlagType,
1240 ):
1241 self._pool = pool
1242 self._counter = 0
1243 self.dbapi_connection = dbapi_connection
1244 self._connection_record = connection_record
1245 self._echo = echo
1246
1247 _connection_record: Optional[_ConnectionRecord]
1248
1249 @property
1250 def driver_connection(self) -> Optional[Any]: # type: ignore[override] # mypy#4125 # noqa: E501
1251 if self._connection_record is None:
1252 return None

Callers 2

checkoutMethod · 0.85
_finalize_fairyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected