File size: 805 Bytes
909cddd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from dotenv import load_dotenv
import sqlite3

# Load environment variables
load_dotenv()

# Get database path from environment variable
db_path = os.getenv("DB_PATH", "./query_logs.db")  # Default to './query_logs.db' if not set

# Function to initialize SQLite database
def initialize_local_db():
    conn = sqlite3.connect(db_path)  # Use the DB path from .env
    cursor = conn.cursor()

    # Create table if it doesn't exist
    cursor.execute('''
    CREATE TABLE IF NOT EXISTS query_logs (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        natural_language_query TEXT,
        generated_sql TEXT,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    ''')

    conn.commit()
    cursor.close()
    conn.close()

# Initialize the database on startup
initialize_local_db()