File size: 756 Bytes
9173642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sqlite3
from pathlib import Path

DB_PATH = Path(__file__).parent / "users.db"

def get_conn():
    conn = sqlite3.connect(DB_PATH)
    conn.row_factory = sqlite3.Row
    return conn

# on import, ensure tables exist
with get_conn() as c:
    c.execute("""

    CREATE TABLE IF NOT EXISTS users (

      id INTEGER PRIMARY KEY,

      email TEXT UNIQUE,

      name TEXT,

      hashed_password TEXT

    )""")
    c.execute("""

    CREATE TABLE IF NOT EXISTS predictions (

      id INTEGER PRIMARY KEY,

      user_id INTEGER,

      predicted REAL,

      accuracy REAL,

      algorithm TEXT,

      input_json TEXT,

      timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,

      FOREIGN KEY(user_id) REFERENCES users(id)

    )""")