blob: 5f5475202ae84cfaebd1340f67a86428d0c8fb10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
"""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)
|