29 lines
883 B
Python
29 lines
883 B
Python
|
from datetime import datetime
|
||
|
|
||
|
from sqlalchemy.orm import mapped_column, Mapped
|
||
|
from sqlalchemy import String, func
|
||
|
|
||
|
import ulid
|
||
|
|
||
|
from .db import BaseModel
|
||
|
|
||
|
|
||
|
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)
|
||
|
password: Mapped[str] = mapped_column(String)
|
||
|
updated_at: Mapped[datetime] = mapped_column(insert_default=func.now())
|
||
|
created_at: Mapped[datetime] = mapped_column(server_onupdate=func.now())
|
||
|
|
||
|
def __repr__(self):
|
||
|
return f'UserAccount(username={self.username}, email={self.email})'
|
||
|
|
||
|
def to_json(self) -> dict:
|
||
|
return {
|
||
|
'username': self.username,
|
||
|
'email': self.email,
|
||
|
}
|