summaryrefslogtreecommitdiff
path: root/db/question.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/question.py
parente0ca9caf5a49981ad999b1c0c3fec69d7c4871e4 (diff)
Rearrenge rest of db actions.
Diffstat (limited to 'db/question.py')
-rw-r--r--db/question.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/db/question.py b/db/question.py
new file mode 100644
index 0000000..25f9003
--- /dev/null
+++ b/db/question.py
@@ -0,0 +1,20 @@
+from sqlalchemy.sql import text
+
+class DBQuestion:
+ def __init__(self, db):
+ self.db = db
+
+ def new(self, question, neg_ans, pos_ans ):
+ sql = "INSERT \
+ INTO questions (question, neg_answer, pos_answer) \
+ VALUES (:question, :neg_answer, :pos_answer) \
+ RETURNING id ;"
+ result = self.db.session.execute(
+ text(sql), {
+ "question":question,
+ "neg_answer":neg_ans,
+ "pos_answer":pos_ans }
+ )
+ self.db.session.commit()
+ return result.fetchone()[0]
+