Remove normalize_db_row, just use row_factory = Row.

This commit is contained in:
voussoir 2022-03-15 18:17:23 -07:00
parent ac647a37a8
commit 6867fb3011
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -115,6 +115,9 @@ class Database(metaclass=abc.ABCMeta):
def _init_sql(self): def _init_sql(self):
''' '''
Your subclass needs to set self.sql, which is a database connection. Your subclass needs to set self.sql, which is a database connection.
It is recommended to set self.sql.row_factory = sqlite3.Row so that you
get dictionary-style named access to row members in your objects' init.
''' '''
raise NotImplementedError raise NotImplementedError
@ -277,20 +280,6 @@ class Database(metaclass=abc.ABCMeta):
query = f'INSERT INTO {table} VALUES({qmarks})' query = f'INSERT INTO {table} VALUES({qmarks})'
return self.execute(query, bindings) return self.execute(query, bindings)
def normalize_db_row(self, db_row, table) -> dict:
'''
Raises KeyError if table is not one of the recognized tables.
Raises TypeError if db_row is not the right type.
'''
if isinstance(db_row, dict):
return db_row
if isinstance(db_row, (list, tuple)):
return dict(zip(self.COLUMNS[table], db_row))
raise TypeError(f'db_row should be {dict}, {list}, or {tuple}, not {type(db_row)}.')
def release_savepoint(self, savepoint, allow_commit=False) -> None: def release_savepoint(self, savepoint, allow_commit=False) -> None:
''' '''
Releasing a savepoint removes that savepoint from the timeline, so that Releasing a savepoint removes that savepoint from the timeline, so that