Spaces:
Runtime error
Runtime error
| # # auth/db.py | |
| import sqlite3 | |
| DB_PATH = "users.db" | |
| def get_connection(): | |
| return sqlite3.connect(DB_PATH) | |
| # def init_db(): | |
| # conn = get_connection() | |
| # cursor = conn.cursor() | |
| # cursor.execute(''' | |
| # CREATE TABLE IF NOT EXISTS users ( | |
| # username TEXT PRIMARY KEY, | |
| # password_hash TEXT | |
| # ) | |
| # ''') | |
| # cursor.execute(''' | |
| # CREATE TABLE IF NOT EXISTS chat_history ( | |
| # id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| # username TEXT, | |
| # message TEXT, | |
| # agent_type TEXT, | |
| # timestamp DATETIME DEFAULT CURRENT_TIMESTAMP | |
| # ) | |
| # ''') | |
| # conn.commit() | |
| # conn.close() | |
| def init_db(): | |
| conn = get_connection() | |
| cursor = conn.cursor() | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS users ( | |
| username TEXT PRIMARY KEY, | |
| password_hash TEXT | |
| ) | |
| ''') | |
| cursor.execute(''' | |
| CREATE TABLE IF NOT EXISTS chat_history ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| username TEXT, | |
| message TEXT, | |
| timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, | |
| FOREIGN KEY(username) REFERENCES users(username) | |
| ) | |
| ''') | |
| conn.commit() | |
| conn.close() | |