MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / Connection

Class Connection

asyncpg/connection.py:43–2080  ·  view source on GitHub ↗

A representation of a database session. Connections are created by calling :func:`~asyncpg.connection.connect`.

Source from the content-addressed store, hash-verified

41
42
43class Connection(metaclass=ConnectionMeta):
44 """A representation of a database session.
45
46 Connections are created by calling :func:`~asyncpg.connection.connect`.
47 """
48
49 __slots__ = ('_protocol', '_transport', '_loop',
50 '_top_xact', '_aborted',
51 '_pool_release_ctr', '_stmt_cache', '_stmts_to_close',
52 '_stmt_cache_enabled',
53 '_listeners', '_server_version', '_server_caps',
54 '_intro_query', '_reset_query', '_proxy',
55 '_stmt_exclusive_section', '_config', '_params', '_addr',
56 '_log_listeners', '_termination_listeners', '_cancellations',
57 '_source_traceback', '_query_loggers', '__weakref__')
58
59 def __init__(self, protocol, transport, loop,
60 addr,
61 config: connect_utils._ClientConfiguration,
62 params: connect_utils._ConnectionParameters):
63 self._protocol = protocol
64 self._transport = transport
65 self._loop = loop
66 self._top_xact = None
67 self._aborted = False
68 # Incremented every time the connection is released back to a pool.
69 # Used to catch invalid references to connection-related resources
70 # post-release (e.g. explicit prepared statements).
71 self._pool_release_ctr = 0
72
73 self._addr = addr
74 self._config = config
75 self._params = params
76
77 self._stmt_cache = _StatementCache(
78 loop=loop,
79 max_size=config.statement_cache_size,
80 on_remove=functools.partial(
81 _weak_maybe_gc_stmt, weakref.ref(self)),
82 max_lifetime=config.max_cached_statement_lifetime)
83
84 self._stmts_to_close = set()
85 self._stmt_cache_enabled = config.statement_cache_size > 0
86
87 self._listeners = {}
88 self._log_listeners = set()
89 self._cancellations = set()
90 self._termination_listeners = set()
91 self._query_loggers = set()
92
93 settings = self._protocol.get_settings()
94 ver_string = settings.server_version
95 self._server_version = \
96 serverversion.split_server_version_string(ver_string)
97
98 self._server_caps = _detect_server_capabilities(
99 self._server_version, settings)
100

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…