Connection
A managed database connection drawn from the pool.
Usage
Connection(
backend,
connection_id,
)Connections track their own state (idle, active, closed) and expose that state through read-only properties. Use get_connection() to obtain one; call close() when finished.
Parameters
backend: BackendName-
Which database backend this connection targets.
connection_id: ConnectionId-
The pool-assigned unique identifier.
See Also
Attributes
| Name | Description |
|---|---|
| backend | The database backend this connection targets. |
| connection_id | The pool-assigned unique identifier for this connection. |
| is_closed | Whether the connection has been permanently closed. |
| is_idle | Whether the connection has no in-flight queries. |
backend
The database backend this connection targets.
backend: BackendName
This is the backend name passed at construction time and does not change over the connection’s lifetime. Useful for dispatching backend-specific SQL dialect adjustments.
See Also
connection_id
The pool-assigned unique identifier for this connection.
connection_id: ConnectionId
Appears in log output and health-check reports. Two connections never share an ID within the same process, even after one has been closed and garbage-collected.
See Also
is_closed
Whether the connection has been permanently closed.
is_closed: bool
A closed connection cannot be reused. Attempting to execute a query on a closed connection raises ConnectionClosedError.
See Also
is_idle
Whether the connection has no in-flight queries.
is_idle: bool
Computed from the internal transaction counter, so this is always consistent even if queries are being submitted from another thread. An idle connection can be safely returned to the pool or closed.
See Also
Methods
| Name | Description |
|---|---|
| close() | Close the connection and return it to the pool. |
close()
Close the connection and return it to the pool.
Usage
close()After calling close(), is_closed returns True and any further operations on this connection raise ConnectionClosedError.