from flask import current_app, g import sqlalchemy from typing import Union, Optional, Literal, Type, List, Tuple import random import os from sqlalchemy import Column, JSON, String, Integer, create_engine, ForeignKey, func, ARRAY from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.orm import sessionmaker, relationship, scoped_session from werkzeug.utils import import_string environment_configuration = os.environ['CONFIGURATION_SETUP'] config = import_string(environment_configuration) engine = create_engine(config.DB_URL) session_factory = sessionmaker(bind=engine) Session = scoped_session(session_factory) 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 __init__(self, question_id, question, answer, addresses): self.question_id = question_id self.question = question self.answer = answer self.addresses = addresses 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", foreign_keys=[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 __init__(self, question_id, difficulty, hint, base_question): self.question_id = question_id self.difficulty = difficulty self.hint = hint self.all_question_relationship = base_question def __repr__(self): return f"