Spaces:
Runtime error
Runtime error
File size: 1,269 Bytes
eeb0f9c |
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# # 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()
|