get column parity implemented
This commit is contained in:
parent
bb19158aa0
commit
75fad013c0
14
database.py
14
database.py
@ -60,13 +60,18 @@ class DBConnector:
|
||||
return rows
|
||||
|
||||
def _column_parity(self, columns: list[str] | set[str]) -> set[str]:
|
||||
"""If the listed columns are not in the database, add them."""
|
||||
"""If the listed columns are not in the database, add them.
|
||||
|
||||
:param columns: The columns we expect are in the database.
|
||||
:return: The list of columns in the database after querying."""
|
||||
cols = set(columns)
|
||||
existing = self._get_cols()
|
||||
needs = cols.difference(existing.intersection(cols))
|
||||
query = f"ALTER TABLE {DB_TABLE} {', '.join([f'ADD COLUMN {c}' for c in needs])}"
|
||||
self._query(query)
|
||||
return self._get_cols()
|
||||
if len(needs) > 0:
|
||||
query = f"ALTER TABLE {DB_TABLE} {', '.join([f'ADD COLUMN {c}' for c in needs])}"
|
||||
self._query(query)
|
||||
existing = self._get_cols()
|
||||
return existing
|
||||
|
||||
def _query(self, sql) -> list[dict]:
|
||||
"""Basic function for running queries.
|
||||
@ -114,6 +119,7 @@ class DBConnector:
|
||||
|
||||
:param kwargs: Values to write for each database; specify each column separately!
|
||||
:returns: The row you just added."""
|
||||
self._column_parity(set(kwargs.keys()))
|
||||
values = []
|
||||
for val in kwargs.keys():
|
||||
values.append(kwargs[val])
|
||||
|
Loading…
x
Reference in New Issue
Block a user