app.utils ========= .. py:module:: app.utils .. autoapi-nested-parse:: Utils used throughout the whole application. Module Contents --------------- .. py:function:: opt_call(func: collections.abc.Callable[[TParam], TReturn], arg: TParam | None) -> TReturn | None Optional chaining for function calls. :param func: Function to call if arg is not None :param arg: Argument to pass to func :return: Result of func or None .. py:function:: not_none(value: not_none.T | None, error_msg: str) -> not_none.T Returns value if not none or raises exception. :param value: Value to check. :param error_msg: Message to throw. :return: The none-none value. .. py:function:: not_none_or(value: not_none_or.T | None, default_value: not_none_or.T) -> not_none_or.T Nullish coalescence - `??` operator. Returns `value` if not `None`. Else, returns `default_value`. .. py:function:: duplicates(list: duplicates.list[duplicates.T]) -> set[duplicates.T] Returns set of duplicate items. .. py:function:: safe_generate_implementation_node(node_id: str, impl: openqasm3.ast.Program | str) -> app.model.CompileRequest.ImplementationNode Generate an ImplementationNode without raising an error. This is used when an error occurred to get the implementation during failure. :param node_id: the id used in the frontend :param impl: the implementation to use .. py:function:: add_status_response_to_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, status: app.model.StatusResponse.StatusResponse) -> None :async: Add the :class:`~app.model.StatusResponse.StatusResponse` to the database :param engine: Database to insert the :class:`~app.model.StatusResponse.StatusResponse` in :param status: The :class:`~app.model.StatusResponse.StatusResponse` to add to the database .. py:function:: update_status_response_in_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, new_state: app.model.StatusResponse.StatusResponse) -> None :async: Update the :class:`~app.model.StatusResponse.StatusResponse` in the database by replacing the row. .. py:function:: get_status_response_from_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID) -> app.model.StatusResponse.StatusResponse | None :async: Get the instance of :class:`~app.model.StatusResponse.StatusResponse` with the given uuid from the database :param engine: Database engine to get the :class:`~app.model.StatusResponse.StatusResponse` from :param uuid: UUID of the :class:`~app.model.StatusResponse.StatusResponse` to retrieve :return: The :class:`~app.model.StatusResponse.StatusResponse` if found, otherwise None .. py:function:: add_result_to_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID, results: str | list[app.model.CompileRequest.ImplementationNode]) -> None :async: Add a result to the database for the given uuid :param engine: Database engine to add the result to :param uuid: UUID of the process state this result belongs :param result: List of :class:`~app.model.CompileRequest.ImplementationNode` to add as results