store what fields get persisted in trait metadata

rather than checking columns in the db

makes things more explicit
This commit is contained in:
Min RK
2023-08-08 14:52:27 +02:00
parent d9154681eb
commit 45102b248b
4 changed files with 21 additions and 168 deletions

View File

@@ -458,58 +458,6 @@ class Service(Base):
"""
return db.query(cls).filter(cls.name == name).first()
def _check_data_only_column(self, column_name: str) -> bool:
"""Check if a column is not a ForeignKey or in a
relationship.
Args:
column_name (str): ame of the column
Returns:
bool: returns `True` if the column is data-only,
returns `False` otherwise.
"""
if hasattr(self, column_name):
column = getattr(Service, column_name)
if hasattr(column, 'foreign_keys'):
return len(column.foreign_keys) == 0
else:
return False
else:
return False
def update_column(self, column_name: str, value: any) -> bool:
"""Update the value of a non-ForeignKey column.
Args:
column_name (str): Name of the column
value (any): New value
Returns:
bool: returns `True` if the column is updated,
returns `False` otherwise.
"""
if self._check_data_only_column(column_name):
setattr(self, column_name, value)
return True
else:
return False
def get_column(self, column_name: str):
"""Get non-ForeignKey, non-relationship column
Args:
column_name (str): Name of the column
Returns:
The value of requested column, None if it is
a foreign key or it does not exist.
"""
if self._check_data_only_column(column_name):
return getattr(self, column_name)
else:
return None
class Expiring:
"""Mixin for expiring entries