diff options
Diffstat (limited to 'db_actions.py')
-rw-r--r-- | db_actions.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/db_actions.py b/db_actions.py index dc59d00..26f69df 100644 --- a/db_actions.py +++ b/db_actions.py @@ -28,3 +28,50 @@ def user_exists(nick): FROM users \ WHERE nick=(:nick);" return db.session.execute(text(sql), { "nick":nick }).scalar() + +def question_new( question, neg_ans, pos_ans ): + sql = "INSERT \ + INTO questions (question, neg_answer, pos_answer, created) \ + VALUES (:question, :neg_answer, :pos_answer, :created) \ + RETURNING id ;" + result = db.session.execute( + text(sql), { + "question":question, + "neg_answer":neg_ans, + "pos_answer":pos_ans, + "created":int(time()) } + ) + db.session.commit() + return result.fetchone()[0] + +def quiz_new(user_id): + sql = "INSERT \ + INTO questionaires (creator_id, created) \ + VALUES (:creator_id, :created) \ + RETURNING id ;" + result = db.session.execute( text(sql), + { "creator_id":user_id, "created":int(time()) } ) + db.session.commit() + return result.fetchone()[0] + +def quiz_add( quiz_id, question_id ): + sql = "UPDATE questionaires \ + SET questionset = ARRAY_APPEND(questionset, :question_id) \ + WHERE id=:quiz_id;" + db.session.execute(text(sql), { + "quiz_id":quiz_id, + "question_id":question_id + }) + db.session.commit() + +def answer_new(user_id, question_id, answer): + sql = "INSERT \ + INTO answers (user_id, question_id, answer, created) \ + VALUES (:user_id, :question_id, :answer, :created);" + db.session.execute( text(sql), { + "user_id":user_id, + "question_id":question_id, + "answer":answer, + "created":int(time()) + } ) + db.session.commit() |