summaryrefslogtreecommitdiff
path: root/db/question.py
diff options
context:
space:
mode:
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]
+