feat:更新数据表结构
This commit is contained in:
13
service/subject_service.py
Normal file
13
service/subject_service.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from models.library import Subject
|
||||
|
||||
|
||||
async def get_subject_by_name(db: AsyncSession, subject: str) -> int:
|
||||
stmt = select(Subject).where(Subject.name == subject)
|
||||
subject = (await db.execute(stmt)).scalar_one_or_none()
|
||||
if not subject:
|
||||
raise ValueError("Subject not found")
|
||||
|
||||
return subject.id
|
||||
Reference in New Issue
Block a user