iSoFe commited on
Commit
14568c2
·
verified ·
1 Parent(s): 8a77a0a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -544,6 +544,32 @@ SEARCH_HTML = """<!DOCTYPE html>
544
  </html>"""
545
 
546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  @app.get("/", response_class=HTMLResponse)
548
  def index():
549
  return HTMLResponse(INDEX_HTML)
 
544
  </html>"""
545
 
546
 
547
+ @app.get("/api/debug")
548
+ def debug(p: str = Query(...)):
549
+ db_path = get_db_path(p)
550
+ if not db_path:
551
+ return JSONResponse({"error": "محافظة غير موجودة"})
552
+ conn = sqlite3.connect(db_path)
553
+ # All tables
554
+ tables = conn.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()
555
+ tables = [t[0] for t in tables]
556
+ result = {"tables": tables}
557
+ if tables:
558
+ t = tables[0]
559
+ # Columns
560
+ cols = conn.execute(f"PRAGMA table_info([{t}])").fetchall()
561
+ result["columns"] = [c[1] for c in cols]
562
+ # Sample row
563
+ row = conn.execute(f"SELECT * FROM [{t}] LIMIT 1").fetchone()
564
+ if row:
565
+ result["sample"] = dict(zip(result["columns"], row))
566
+ # Count
567
+ count = conn.execute(f"SELECT COUNT(*) FROM [{t}]").fetchone()
568
+ result["total_rows"] = count[0]
569
+ conn.close()
570
+ return JSONResponse(result)
571
+
572
+
573
  @app.get("/", response_class=HTMLResponse)
574
  def index():
575
  return HTMLResponse(INDEX_HTML)