From e9a79f35b316d67d7f88b78cec46a35f5529d96e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 19 Dec 2022 13:27:14 +0300 Subject: auth: Add default row_factory to sqlite3 * gn3/auth/db.py: For easier setting up of objects after querying, set the default row_factory object that allows indexing by database field name. --- gn3/auth/db.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gn3') diff --git a/gn3/auth/db.py b/gn3/auth/db.py index e0e009c..256940d 100644 --- a/gn3/auth/db.py +++ b/gn3/auth/db.py @@ -1,7 +1,7 @@ """Handle connection to auth database.""" import sqlite3 import contextlib -from typing import Any, Iterator, Protocol +from typing import Any, Callable, Iterator, Protocol import traceback @@ -47,9 +47,10 @@ class DbCursor(Protocol): ... @contextlib.contextmanager -def connection(db_path: str) -> Iterator[DbConnection]: +def connection(db_path: str, row_factory: Callable = sqlite3.Row) -> Iterator[DbConnection]: """Create the connection to the auth database.""" conn = sqlite3.connect(db_path) + conn.row_factory = row_factory try: yield conn except sqlite3.Error as exc: -- cgit v1.2.3