datavorous commited on
Commit
cf11cba
·
verified ·
1 Parent(s): f805d2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -334,16 +334,14 @@ async def get_dpp_questions(
334
  if not os.path.exists(db_path):
335
  raise HTTPException(status_code=404, detail="DPP file not found.")
336
 
337
- # Connect to the database synchronously
338
- conn = sqlite3.connect(db_path)
339
- conn.row_factory = sqlite3.Row
340
- cursor = conn.cursor()
341
- cursor.execute("SELECT * FROM selected_questions")
342
- questions = cursor.fetchall()
343
- conn.close()
344
 
345
  if not questions:
346
  raise HTTPException(status_code=404, detail="No questions found in the DPP.")
 
347
  return {"dpp": dpp_name, "questions": [dict(q) for q in questions]}
348
 
349
  # Main application runner
 
334
  if not os.path.exists(db_path):
335
  raise HTTPException(status_code=404, detail="DPP file not found.")
336
 
337
+ # Connect to the database asynchronously
338
+ async with aiosqlite.connect(db_path) as db:
339
+ cursor = await db.execute("SELECT * FROM selected_questions")
340
+ questions = await cursor.fetchall()
 
 
 
341
 
342
  if not questions:
343
  raise HTTPException(status_code=404, detail="No questions found in the DPP.")
344
+
345
  return {"dpp": dpp_name, "questions": [dict(q) for q in questions]}
346
 
347
  # Main application runner