summaryrefslogtreecommitdiff
path: root/db/answer.py
diff options
context:
space:
mode:
authorEila Väyrynen <evayryne@local>2023-12-03 13:28:36 +0200
committerEila Väyrynen <evayryne@local>2023-12-03 13:28:36 +0200
commit83eefd51d79dc2c0fa778303042c581b4691e82e (patch)
treebb957d130855e7ba798f90604468c3665a81528d /db/answer.py
parente0ca9caf5a49981ad999b1c0c3fec69d7c4871e4 (diff)
Rearrenge rest of db actions.
Diffstat (limited to 'db/answer.py')
-rw-r--r--db/answer.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/db/answer.py b/db/answer.py
new file mode 100644
index 0000000..8234963
--- /dev/null
+++ b/db/answer.py
@@ -0,0 +1,28 @@
+from sqlalchemy.sql import text
+
+class DBAnswer:
+ def __init__(self, db):
+ self.db = db
+
+ def new(self, user_id, question_id, answer):
+ sql = "INSERT \
+ INTO answers (user_id, question_id, answer ) \
+ VALUES (:user_id, :question_id, :answer);"
+ self.db.session.execute( text(sql), {
+ "question_id":question_id,
+ "user_id":user_id,
+ "answer":answer
+ } )
+ self.db.session.commit()
+
+ def get(self, user_id, question_id):
+ sql = "SELECT answer \
+ FROM answers \
+ WHERE question_id = (:question_id) AND user_id = (:user_id);"
+ result = self.db.session.execute( text(sql), {
+ 'question_id': question_id,
+ 'user_id': user_id
+ } ).fetchone()
+ return result[0] if result else -1
+
+