14 lines
393 B
Python
14 lines
393 B
Python
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
|