mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-05-24 14:33:26 +00:00
fix: base and mixin models
This commit is contained in:
parent
3db5df492e
commit
5d31ae0fdc
|
@ -1,25 +0,0 @@
|
|||
import uuid
|
||||
|
||||
import sqlalchemy
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
|
||||
|
||||
class BaseMixin:
|
||||
@declared_attr
|
||||
def id(cls):
|
||||
return sqlalchemy.Column(
|
||||
UUID(as_uuid=True),
|
||||
primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
unique=True,
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
@declared_attr
|
||||
def created_at(cls):
|
||||
return sqlalchemy.Column(sqlalchemy.DateTime, server_default=sqlalchemy.sql.func.now())
|
||||
|
||||
@declared_attr
|
||||
def updated_at(cls):
|
||||
return sqlalchemy.Column(sqlalchemy.DateTime, server_default=sqlalchemy.sql.func.now())
|
|
@ -1,4 +1,4 @@
|
|||
from .base_sqlalchemy import Base
|
||||
from .base_sqlalchemy import Base, IdCreatedUpdatedBaseMixin
|
||||
from .token import Token
|
||||
|
||||
__all__ = ["Base", "Token"]
|
||||
__all__ = ["Base", "Token", "IdCreatedUpdatedBaseMixin"]
|
||||
|
|
|
@ -1,5 +1,36 @@
|
|||
import uuid
|
||||
|
||||
import sqlalchemy
|
||||
import sqlalchemy.dialects.postgresql
|
||||
import sqlalchemy.ext.declarative
|
||||
import sqlalchemy.orm
|
||||
|
||||
|
||||
class Base(sqlalchemy.orm.DeclarativeBase):
|
||||
"""Base class for all models."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class IdCreatedUpdatedBaseMixin(Base):
|
||||
@sqlalchemy.ext.declarative.declared_attr
|
||||
def uuid(cls):
|
||||
return sqlalchemy.Column(
|
||||
sqlalchemy.dialects.postgresql.UUID(as_uuid=True),
|
||||
primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
unique=True,
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
@sqlalchemy.ext.declarative.declared_attr
|
||||
def created_at(cls):
|
||||
return sqlalchemy.Column(sqlalchemy.DateTime, server_default=sqlalchemy.sql.func.now())
|
||||
|
||||
@sqlalchemy.ext.declarative.declared_attr
|
||||
def updated_at(cls):
|
||||
return sqlalchemy.Column(sqlalchemy.DateTime, server_default=sqlalchemy.sql.func.now())
|
||||
|
||||
@sqlalchemy.ext.declarative.declared_attr.directive
|
||||
def __tablename__(cls) -> str:
|
||||
return cls.__name__.lower()
|
||||
|
|
Loading…
Reference in New Issue
Block a user