from flask import current_app, g import sqlalchemy from sqlalchemy import Column, JSON, String, Integer, create_engine, ForeignKey, func from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.orm import sessionmaker, relationship from config import DB_URL engine = create_engine(DB_URL) Session = sessionmaker(bind=engine) Base = declarative_base() class AllQuestions(Base): __tablename__ = "all_questions" question_id = Column(Integer, primary_key=True, nullable=False) question = Column(String) answer = Column(String) addresses = Column(String) def __repr__(self): return f"" class HiddenAnswer(Base): __tablename__ = "category_hidden_answer" question_id = Column(Integer, ForeignKey("all_questions.question_id"), primary_key=True) difficulty = Column(Integer) hint = Column(JSON) all_question_relationship = relationship("AllQuestions", primaryjoin="HiddenAnswer.question_id==AllQuestions.question_id", lazy="joined", uselist=False) question = association_proxy("all_question_relationship", "question") answer = association_proxy("all_question_relationship", "answer") addresses = association_proxy("all_question_relationship", "addresses") def __repr__(self): return f"