| |
|
|
| import sqlite3 |
| from core.settings import settings |
|
|
| class Database: |
|
|
| def __init__(self): |
| self.conn = sqlite3.connect(settings.DATABASE_PATH, check_same_thread=False) |
| self._create_tables() |
|
|
| def _create_tables(self): |
| cursor = self.conn.cursor() |
| cursor.execute(""" |
| CREATE TABLE IF NOT EXISTS questions ( |
| id TEXT PRIMARY KEY, |
| statement TEXT, |
| options TEXT, |
| correct_answer TEXT, |
| explanation TEXT, |
| topic TEXT, |
| difficulty INTEGER |
| ) |
| """) |
| cursor.execute(""" |
| CREATE TABLE IF NOT EXISTS answers ( |
| id INTEGER PRIMARY KEY AUTOINCREMENT, |
| question_id TEXT, |
| correct BOOLEAN, |
| timestamp DATETIME DEFAULT CURRENT_TIMESTAMP |
| ) |
| """) |
| self.conn.commit() |