-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.py
More file actions
47 lines (40 loc) · 1.53 KB
/
Copy pathget.py
File metadata and controls
47 lines (40 loc) · 1.53 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
from fastapi import APIRouter, HTTPException
from app.utils.make_meta import make_meta
from app.utils.db import get_db_connection_direct
router = APIRouter()
@router.get("/queue")
def read_queue() -> dict:
"""GET /queue: Return queue table info, schema, and most recent record."""
try:
conn = get_db_connection_direct()
cursor = conn.cursor()
# 1. Count records
cursor.execute("SELECT COUNT(*) FROM queue;")
count_row = cursor.fetchone()
record_count = count_row[0] if count_row else 0
# 2. Get table schema
cursor.execute("SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name = 'queue';")
schema = [
{
"name": row[0],
"type": row[1]
}
for row in cursor.fetchall()
]
# 3. Get most recently updated record
cursor.execute("SELECT * FROM queue ORDER BY updated DESC LIMIT 1;")
columns = [desc[0] for desc in cursor.description] if cursor.description else []
row = cursor.fetchone()
most_recent = dict(zip(columns, row)) if row and columns else None
conn.close()
return {
"meta": make_meta("success", "Queue table info"),
"data": {
"queued": record_count,
"most_recent": most_recent,
# "schema": schema
}
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))