Files
DoubaoTeam/dao/student.py
T

25 lines
601 B
Python
Raw Normal View History

from schemas.student import *
from core.database import get_db
from models.student import *
2026-09-21 17:51:33 +08:00
from sqlalchemy.orm import Session
def create_students(d: dict, db: Session):
stu = Student(**d)
try:
db.add(stu)
# 把 SQL 发给数据库执行
db.flush()
# 根据 id 生成学生编号
if not stu.student_no:
stu.student_no = f"STU{stu.id:04d}"
db.commit()
db.refresh(stu)
return stu
except Exception as e:
db.rollback()
print(f"插入学生失败: {e}")
return None
2026-09-21 21:09:38 +08:00
# def updet_students():