Source code for simdb.database.models.base
from typing import Dict, Any
from sqlalchemy.ext.declarative import declarative_base
[docs]
class BaseModel:
"""
Base model for ORM classes.
"""
__allow_unmapped__ = True
def __str__(self):
"""
Return a string representation of the {cls.__name__} formatted to print.
:return: The {cls.__name__} as a string for printing.
"""
raise NotImplementedError
[docs]
@classmethod
def from_data(cls, data: Dict) -> "BaseModel":
"""
Create a Model from serialised data.
:param data: Serialised model data.
:return: The created model.
"""
raise NotImplementedError
[docs]
def data(self, recurse: bool = False) -> Dict:
"""
Serialise the {cls.__name__}.
:param recurse: If True also serialise any contained models, otherwise only serialise simple fields.
:return: The serialised data.
"""
raise NotImplementedError
Base: Any = declarative_base(cls=BaseModel)