aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/db.py
blob: c0d0415d1eec08b8da15a3ae9ef23652fa272ba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Handle connection to auth database."""
import sqlite3
import contextlib

@contextlib.contextmanager
def connection(db_path: str):
    connection = sqlite3.connect(db_path)
    try:
        yield connection
    finally:
        connection.close()

@contextlib.contextmanager
def cursor(connection):
    cur = connection.cursor()
    try:
        yield cur
    finally:
        cur.close()