from datetime import datetime

try:
    from humps.main import depascalize
    from sqlalchemy import Column, DateTime
    from sqlalchemy.orm.decl_api import declared_attr
    from sqlmodel import Field, SQLModel

except ImportError:
    raise RuntimeError(
        "SQLModel is not installed. Please install it with `pip install sqlmodel pyhumps`"
    )


class Model(SQLModel):
    """
    Abstract model providing `id`, `date_created` and `date_updated` fields.
    And also automatic table naming to `snake_case`.
    """

    id: int = Field(primary_key=True)
    date_created: datetime = Field(sa_column=Column(DateTime, default=datetime.utcnow))
    date_updated: datetime = Field(sa_column=Column(DateTime, onupdate=datetime.utcnow))

    @declared_attr
    def __tablename__(cls):
        """
        Convert Pascal class name style to `snake_case`
        """
        return depascalize(cls.__name__)

humps.main.depascalize sqlalchemy.Column sqlmodel.Field
[((542, 565), 'sqlmodel.Field', 'Field', ([], {'primary_key': '(True)'}), '(primary_key=True)\n', (547, 565), False, 'from sqlmodel import Field, SQLModel\n'), ((886, 911), 'humps.main.depascalize', 'depascalize', (['cls.__name__'], {}), '(cls.__name__)\n', (897, 911), False, 'from humps.main import depascalize\n'), ((611, 652), 'sqlalchemy.Column', 'Column', (['DateTime'], {'default': 'datetime.utcnow'}), '(DateTime, default=datetime.utcnow)\n', (617, 652), False, 'from sqlalchemy import Column, DateTime\n'), ((699, 741), 'sqlalchemy.Column', 'Column', (['DateTime'], {'onupdate': 'datetime.utcnow'}), '(DateTime, onupdate=datetime.utcnow)\n', (705, 741), False, 'from sqlalchemy import Column, DateTime\n')]