Melika Kheirieh commited on
Commit
dacecff
·
1 Parent(s): e45f1b1

chore: track data/demo.db and update gitignore

Browse files
Files changed (4) hide show
  1. .gitignore +3 -1
  2. app/routers/nl2sql.py +7 -5
  3. data/demo.db +0 -0
  4. temp.py +34 -0
.gitignore CHANGED
@@ -35,9 +35,11 @@ dist/
35
  .wheels/
36
 
37
  # --- Data & databases ---
38
- data/
39
  *.sqlite
40
  *.db
 
 
41
 
42
  # --- Logs & temp files ---
43
  logs/
 
35
  .wheels/
36
 
37
  # --- Data & databases ---
38
+ data/*
39
  *.sqlite
40
  *.db
41
+ # allow demo database for the public demo
42
+ !data/demo.db
43
 
44
  # --- Logs & temp files ---
45
  logs/
app/routers/nl2sql.py CHANGED
@@ -122,7 +122,10 @@ router = APIRouter(prefix="/nl2sql")
122
  # -------------------------------
123
  DB_MODE = os.getenv("DB_MODE", "sqlite").lower() # "sqlite" or "postgres"
124
  POSTGRES_DSN = os.getenv("POSTGRES_DSN")
125
- DEFAULT_SQLITE_PATH: str = os.getenv("DEFAULT_SQLITE_DB", "data/Chinook_Sqlite.sqlite")
 
 
 
126
 
127
  # Runtime upload storage
128
  _DB_UPLOAD_DIR = os.getenv("DB_UPLOAD_DIR", "/tmp/nl2sql_dbs")
@@ -308,10 +311,9 @@ async def upload_db(file: UploadFile = File(...)):
308
  def _final_schema_preview(db_id: Optional[str], provided_preview: Optional[str]) -> str:
309
  if provided_preview and provided_preview.strip():
310
  return provided_preview
311
- if db_id:
312
- adapter = _select_adapter(db_id)
313
- return _derive_schema_preview(adapter) or ""
314
- return ""
315
 
316
 
317
  @router.get("/health")
 
122
  # -------------------------------
123
  DB_MODE = os.getenv("DB_MODE", "sqlite").lower() # "sqlite" or "postgres"
124
  POSTGRES_DSN = os.getenv("POSTGRES_DSN")
125
+ # Default demo DB used when no db_id is provided (can be full Chinook or a tiny demo DB)
126
+ DEFAULT_SQLITE_PATH: str = os.getenv(
127
+ "DEFAULT_SQLITE_PATH", "data/Chinook_Sqlite.sqlite"
128
+ )
129
 
130
  # Runtime upload storage
131
  _DB_UPLOAD_DIR = os.getenv("DB_UPLOAD_DIR", "/tmp/nl2sql_dbs")
 
311
  def _final_schema_preview(db_id: Optional[str], provided_preview: Optional[str]) -> str:
312
  if provided_preview and provided_preview.strip():
313
  return provided_preview
314
+
315
+ adapter = _select_adapter(db_id) # works for both None and explicit db_id
316
+ return _derive_schema_preview(adapter) or ""
 
317
 
318
 
319
  @router.get("/health")
data/demo.db ADDED
Binary file (24.6 kB). View file
 
temp.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+
3
+ path = "data/demo.db"
4
+ conn = sqlite3.connect(path)
5
+ cur = conn.cursor()
6
+
7
+ print(f"Inspecting: {path}\n")
8
+
9
+ # --- tables
10
+ cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
11
+ tables = [t[0] for t in cur.fetchall()]
12
+
13
+ print("=== TABLES ===")
14
+ for t in tables:
15
+ print("-", t)
16
+
17
+ # --- schema
18
+ print("\n=== SCHEMA ===")
19
+ for table in tables:
20
+ print(f"\n--- {table} ---")
21
+ cur.execute(f"PRAGMA table_info('{table}');")
22
+ for col in cur.fetchall():
23
+ print(col)
24
+
25
+ # --- sample rows
26
+ print("\n=== SAMPLE ROWS (LIMIT 5) ===")
27
+ for table in tables:
28
+ print(f"\n--- {table} ---")
29
+ cur.execute(f"SELECT * FROM {table} LIMIT 5;")
30
+ rows = cur.fetchall()
31
+ for r in rows:
32
+ print(r)
33
+
34
+ conn.close()