File size: 943 Bytes
75759c3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # data/database.py
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() |