2023-07-02 20:18:29 +08:00
|
|
|
from datetime import datetime
|
|
|
|
|
2023-07-03 01:03:54 +08:00
|
|
|
from sqlalchemy.orm import DeclarativeBase
|
2023-07-02 20:18:29 +08:00
|
|
|
from sqlalchemy.orm import mapped_column, Mapped
|
2023-07-04 11:50:02 +08:00
|
|
|
from sqlalchemy import String
|
2023-07-02 20:18:29 +08:00
|
|
|
|
|
|
|
import ulid
|
|
|
|
|
2023-07-03 01:03:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
class BaseModel(DeclarativeBase):
|
|
|
|
pass
|
2023-07-02 20:18:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class UserAccount(BaseModel):
|
|
|
|
__tablename__ = "user_account"
|
|
|
|
|
|
|
|
id: Mapped[str] = mapped_column(String(26), primary_key=True, insert_default=ulid.new().str)
|
|
|
|
username: Mapped[str] = mapped_column(String(20), unique=True)
|
|
|
|
email: Mapped[str] = mapped_column(String, unique=True)
|
2023-07-04 11:50:02 +08:00
|
|
|
password: Mapped[str] = mapped_column(String(60))
|
|
|
|
updated_at: Mapped[datetime] = mapped_column(default=datetime.now)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(default=datetime.now, onupdate=datetime.now)
|
2023-07-02 20:18:29 +08:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f'UserAccount(username={self.username}, email={self.email})'
|
|
|
|
|
|
|
|
def to_json(self) -> dict:
|
|
|
|
return {
|
|
|
|
'username': self.username,
|
|
|
|
'email': self.email,
|
|
|
|
}
|