from typing import Optional, List from sqlalchemy.orm import Session, joinedload from ..models.question_model import QuestionModel from .base_store import BaseStore class QuestionStore(BaseStore[QuestionModel]): """ 题目存储类,继承自BaseStore 提供题目相关的特定操作 """ def __init__(self, db: Session): super().__init__(db, QuestionModel) def get_by_subject(self, subject: str) -> List[QuestionModel]: """根据学科获取题目列表""" return self.db.query( self.model).filter(self.model.subject == subject).all() def get_by_type(self, type: str) -> List[QuestionModel]: """根据题型获取题目列表""" return self.db.query(self.model).filter(self.model.type == type).all() def get_by_difficulty(self, difficulty: int) -> List[QuestionModel]: """根据难度获取题目列表""" return self.db.query( self.model).filter(self.model.difficulty == difficulty).all() def get_questions_with_options(self) -> List[QuestionModel]: """获取包含选项信息的题目列表""" return self.db.query(self.model).options(joinedload( self.model.options)).all() def get_questions_with_knowledge_points(self) -> List[QuestionModel]: """获取包含知识点信息的题目列表""" return self.db.query(self.model).options( joinedload(self.model.knowledge_points)).all()