about summary refs log tree commit diff
"""Handle connection to auth database."""
import warnings
from typing import Any, Callable

from flask import current_app

from gn_libs.sqlite3 import cursor, connection # pylint: disable=[unused-import]
from gn_libs.protocols import DbCursor, DbConnection # pylint: disable=[unused-import]

warnings.warn(
    f"Module '{__name__}' is deprecated. Use `gn_libs.sqlite3` instead.",
    category=DeprecationWarning,
    stacklevel=2)


def with_db_connection(func: Callable[[DbConnection], Any]) -> Any:
    """
    Takes a function of one argument `func`, whose one argument is a database
    connection.
    """
    warnings.warn(
        (f"Function '{__name__}.with_db_connection' is deprecated. "
         "Use `gn_libs.sqlite3.with_db_connection` instead."),
        category=DeprecationWarning,
        stacklevel=2)
    db_uri = current_app.config["AUTH_DB"]
    with connection(db_uri) as conn:
        return func(conn)