blob: e732a0395ac0253d38313bde7ef650d82988df2c (
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
|
"""Handle connection to auth database."""
import sqlite3
import contextlib
@contextlib.contextmanager
def connection(db_path: str):
"""Create the connection to the auth database."""
conn = sqlite3.connect(db_path)
try:
yield conn
except: # pylint: disable=bare-except
conn.rollback()
finally:
conn.commit()
conn.close()
@contextlib.contextmanager
def cursor(conn):
"""Get a cursor from the given connection to the auth database."""
cur = conn.cursor()
try:
yield cur
except: # pylint: disable=bare-except
conn.rollback()
finally:
conn.commit()
cur.close()
|