Spaces:
Running
Running
| # 导入类型注解模块 | |
| from typing import Optional | |
| # 导入Pydantic的BaseModel类 | |
| from pydantic import BaseModel | |
| # 导入SQLAlchemy的列、整数、字符串、布尔类型 | |
| from sqlalchemy import Column, Integer, String, Boolean | |
| # 导入SQLAlchemy的declarative_base函数 | |
| from sqlalchemy.ext.declarative import declarative_base | |
| # 导入SQLAlchemy的relationship函数 | |
| from sqlalchemy.orm import relationship | |
| # 创建SQLAlchemy的Base类实例 | |
| Base = declarative_base() | |
| # 定义用户模型类,继承自Base | |
| class User(Base): | |
| # 定义表名 | |
| __tablename__ = "users" | |
| # 定义用户ID列,主键,索引 | |
| id = Column(Integer, primary_key=True, index=True) | |
| # 定义用户名列,唯一,索引 | |
| username = Column(String, unique=True, index=True) | |
| # 定义哈希密码列 | |
| hashed_password = Column(String) | |
| # 定义邮箱列,唯一,索引 | |
| email = Column(String, unique=True, index=True) | |
| # 定义禁用状态列,默认为False | |
| disabled = Column(Boolean, default=False) | |
| # 定义用户创建模型类,继承自BaseModel | |
| class UserCreate(BaseModel): | |
| # 定义用户名字段 | |
| username: str | |
| # 定义密码字段 | |
| password: str | |
| # 定义邮箱字段 | |
| email: str |