38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
# AI_CHANGELOG
|
|
# - 2026-02-19 | Prompt: 小程序 MVP 全链路验证 | 新增 /api/xcx-test 接口,从 test."xcx-test" 表读取 ti 列第一行
|
|
|
|
"""
|
|
小程序 MVP 验证接口
|
|
|
|
从 test_zqyy_app 库的 test."xcx-test" 表读取数据,
|
|
用于验证小程序 → 后端 → 数据库全链路连通性。
|
|
"""
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from app.database import get_connection
|
|
|
|
router = APIRouter(prefix="/api/xcx-test", tags=["小程序MVP"])
|
|
|
|
|
|
@router.get("")
|
|
async def get_xcx_test():
|
|
"""
|
|
读取 test."xcx-test" 表 ti 列第一行。
|
|
|
|
用于小程序 MVP 全链路验证:小程序 → API → DB → 返回数据。
|
|
"""
|
|
conn = get_connection()
|
|
try:
|
|
with conn.cursor() as cur:
|
|
# CHANGE 2026-02-19 | 读取 test schema 下的 xcx-test 表
|
|
# 表名含连字符,必须用双引号包裹
|
|
cur.execute('SELECT ti FROM test."xcx-test" LIMIT 1')
|
|
row = cur.fetchone()
|
|
finally:
|
|
conn.close()
|
|
|
|
if row is None:
|
|
raise HTTPException(status_code=404, detail="无数据")
|
|
|
|
return {"ti": row[0]}
|