# Utilities Observability, quoting, adapters, memory and the DB-API. ## Observability See [Observability](../../production/observability.md). ```{py:currentmodule} agensgraph ``` ```{py:function} add_query_logger(callback: Callable[[QueryRecord], None]) Call `callback` with a `QueryRecord` for every statement. ``` ```{py:function} remove_query_logger(callback: Callable[[QueryRecord], None]) ``` ````{py:class} QueryRecord(connection: int, statement: str, elapsed: float, rows: int, failed: bool, error: BaseException | None = None) One statement. ```{py:attribute} connection :type: int an opaque number for the connection ``` ```{py:attribute} statement :type: str as sent, without parameter values ``` ```{py:attribute} elapsed :type: float seconds until the server answered ``` ```{py:attribute} rows :type: int ``` ```{py:attribute} failed :type: bool ``` ```{py:attribute} error :type: BaseException | None ``` ```` ```{py:function} enable_tracing(tracer: Any = None) Take an OpenTelemetry span per `execute_query()`. Needs the `otel` extra. ``` ```{py:function} disable_tracing() ``` ```{py:currentmodule} agensgraph.observability ``` ```{py:function} add_notice_listener(callback: Callable[[Notice], None]) Call `callback` with a `Notice` for every notice the server sends. ``` ```{py:function} remove_notice_listener(callback: Callable[[Notice], None]) ``` ```{py:currentmodule} agensgraph ``` ````{py:class} Notice(severity: str, code: str | None, message: str, detail: str | None = None, hint: str | None = None) A notice. ```{py:attribute} severity :type: str not localised ``` ```{py:attribute} code :type: str | None the SQLSTATE ``` ```{py:attribute} message :type: str ``` ```{py:attribute} detail :type: str | None ``` ```{py:attribute} hint :type: str | None ``` ```` ## Quoting See [Identifiers](../../guide/parameters.md#identifiers). ```{py:currentmodule} agensgraph.cypher ``` ```{py:function} quote_identifier(name: str) -> str A name as an identifier, quoted unless the server would read it unchanged. ``` ```{py:function} quote_string(value: str) -> str A string literal. ``` ```{py:function} check_single_statement(statement: str) Raise `ValueError` if the text holds more than one statement. ``` ```{py:function} check_can_wrap(statement: str) Raise `ValueError` if the text holds a write clause. A hint, not a boundary. ``` ## Adapters See [Other tools](../../guide/other-tools.md#a-psycopg-connection-the-driver-did-not-make). ```{py:currentmodule} agensgraph.adapters ``` ```{py:function} register_text(context: AdaptContext | AdaptersMap, labels: LabelCache | None = None) Read graph values in the text rendering on a psycopg connection, and send values the driver's way. ``` ```{py:function} assert_oids(conn: Connection[Any]) Check the graph types' oids against a server. ``` ## Bulk loading and memory See [Bulk loading](../../data/bulk-loading.md). ```{py:currentmodule} agensgraph.bulk ``` ````{py:class} UpsertCounts(inserted: int, updated: int) What an upsert wrote. ```{py:attribute} inserted :type: int ``` ```{py:attribute} updated :type: int ``` ```` ```{py:currentmodule} agensgraph ``` ```{py:function} paused_collection() -> Generator[None] A block during which Python's cycle collector does not run. ``` ```{py:function} freeze_after_import() Move every object alive now out of the collector's way. Once, at startup. ``` ## DB-API See [Other tools](../../guide/other-tools.md#the-db-api). ```{py:currentmodule} agensgraph.dbapi ``` ```{py:function} connect(dsn: str = '', **kwargs: object) -> Connection[object] `agensgraph.connect()`, under PEP 249's name. The module also has `apilevel`, `threadsafety`, `paramstyle`, the type constructors and the exception classes. ```