From 83eefd51d79dc2c0fa778303042c581b4691e82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eila=20V=C3=A4yrynen?= Date: Sun, 3 Dec 2023 13:28:36 +0200 Subject: Rearrenge rest of db actions. --- db/question.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 db/question.py (limited to 'db/question.py') 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] + -- cgit v1.2.3