.. __: https://www.postgresql.org/docs/current/multibyte.html
- .. attribute:: info
-
- TODO
+ .. autoattribute:: info
.. automethod:: fileno
The object is usually returned by `Connection.notifies()`.
+.. autoclass:: ConnectionInfo()
+
+ The object is usually returned by `Connection.info`.
+
+ .. autoproperty:: host
+ .. autoproperty:: port
+ .. autoproperty:: dbname
+ .. autoproperty:: user
+ .. autoproperty:: password
+ .. autoproperty:: options
+ .. autoproperty:: status
+ .. autoproperty:: transaction_status
+ .. automethod:: get_parameters
+ .. automethod:: parameter_status
+
+ Example of parameters are ``server_version``,
+ ``standard_conforming_string``... See :pq:`PQparameterStatus()` for
+ all the available parameters.
+
.. rubric:: Objects involved in :ref:`transactions`
.. autoclass:: Transaction()
from .errors import DataError, OperationalError, IntegrityError
from .errors import InternalError, ProgrammingError, NotSupportedError
from ._column import Column
+from .conninfo import ConnectionInfo
from .connection import BaseConnection, AsyncConnection, Connection, Notify
from .transaction import Rollback, Transaction, AsyncTransaction
from .server_cursor import AsyncServerCursor, ServerCursor
class ConnectionInfo:
+ """Allow access to information about the connection."""
+
+ __module__ = "psycopg3"
+
def __init__(self, pgconn: pq.proto.PGconn):
self.pgconn = pgconn
@property
def host(self) -> str:
+ """The host name of the database."""
return self._get_pgconn_attr("host")
@property
def port(self) -> int:
+ """The port of the database connection."""
return int(self._get_pgconn_attr("port"))
@property
def dbname(self) -> str:
+ """The name of the connected database."""
return self._get_pgconn_attr("db")
@property
def user(self) -> str:
+ """The user of the database connection."""
return self._get_pgconn_attr("user")
@property
def password(self) -> str:
+ """The password of the database connection."""
return self._get_pgconn_attr("password")
@property
def options(self) -> str:
+ """The options parameter of the database connection."""
return self._get_pgconn_attr("options")
def get_parameters(self) -> Dict[str, str]:
@property
def status(self) -> pq.ConnStatus:
+ """`pq.ConnStatus` enum representing the state of the connection."""
return pq.ConnStatus(self.pgconn.status)
@property
def transaction_status(self) -> pq.TransactionStatus:
+ """
+ `pq.TransactionStatus` enum representing the state of the transaction.
+ """
return pq.TransactionStatus(self.pgconn.transaction_status)
def parameter_status(self, param_name: str) -> Optional[str]:
+ """
+ Return a parameter setting of the connection.
+
+ Return `None` is the parameter is unknown.
+ """
res = self.pgconn.parameter_status(param_name.encode(self._pyenc))
return res.decode(self._pyenc) if res is not None else None