diff options
author | Frederick Muriuki Muriithi | 2022-12-19 13:27:14 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-12-21 06:13:41 +0300 |
commit | e9a79f35b316d67d7f88b78cec46a35f5529d96e (patch) | |
tree | c636b35f8b206c22959867e02010127d9843736d /gn3 | |
parent | 9fc7ab5701aaef66ec6fc47e10a2b6421e23f83f (diff) | |
download | genenetwork3-e9a79f35b316d67d7f88b78cec46a35f5529d96e.tar.gz |
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.
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/auth/db.py | 5 |
1 files changed, 3 insertions, 2 deletions
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: |