diff options
author | Minea Salmimaa <msalmima@local> | 2023-12-03 12:44:45 +0200 |
---|---|---|
committer | Minea Salmimaa <msalmima@local> | 2023-12-03 12:44:45 +0200 |
commit | e0ca9caf5a49981ad999b1c0c3fec69d7c4871e4 (patch) | |
tree | 6402666bec2999dda0e1e7460b91b21e17310479 /db/db.py | |
parent | 7353c51df2d074cbe01913044bda7aeef62a31b7 (diff) |
Moving quiz related db actions to separete class and file.
Diffstat (limited to 'db/db.py')
-rw-r--r-- | db/db.py | 47 |
1 files changed, 2 insertions, 45 deletions
@@ -5,12 +5,14 @@ from sqlalchemy.sql import text from app import app from db.user import DBUser +from db.quiz import DBQuiz class DB: def __init__(self): self.db = SQLAlchemy() self.db.init_app(app) self.user = DBUser(self.db) + self.quiz = DBQuiz(self.db) def question_new(self, question, neg_ans, pos_ans ): sql = "INSERT \ @@ -26,51 +28,6 @@ class DB: self.db.session.commit() return result.fetchone()[0] - def quiz_new(self, user_id): - sql = "INSERT \ - INTO questionaires (creator_id) \ - VALUES (:creator_id) \ - RETURNING id ;" - result = self.db.session.execute( text(sql), - { "creator_id":user_id } ) - self.db.session.commit() - return result.fetchone()[0] - - def quiz_add(self, quiz_id, question_id ): - sql = "UPDATE questionaires \ - SET questionset = ARRAY_APPEND(questionset, :question_id) \ - WHERE id=:quiz_id;" - self.db.session.execute(text(sql), { - "quiz_id":quiz_id, - "question_id":question_id - }) - self.db.session.commit() - - - def set_quiz_link( self, quiz_id, link ): - sql = "INSERT \ - INTO quiz_links (quiz_id, link) \ - VALUES (:quiz_id, :link)" - result = self.db.session.execute( text(sql), - { "quiz_id":quiz_id, "link":link } ) - self.db.session.commit() - - - def find_quiz_by_link( self, link ): - sql = "SELECT quiz_id \ - FROM quiz_links \ - WHERE link=:link;" - result = self.db.session.execute(text(sql), { "link":link }).fetchone() - return result[0] if result else False - - - def get_quiz_link( self, quiz_id ): - sql = "SELECT link \ - FROM quiz_links \ - WHERE quiz_id=:quiz_id;" - result = self.db.session.execute(text(sql), { "quiz_id":quiz_id }).fetchone() - return result[0] if result else result - def answer_new(self, user_id, question_id, answer): sql = "INSERT \ |