新增数据重置功能:管理员可一键清空所有行情数据,需输入确认文字防误操作
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -193,3 +193,10 @@ def list_candles(
|
||||
return [dict(zip(cols, row)) for row in cur.fetchall()]
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@app.post("/api/v1/admin/reset-data")
|
||||
def reset_data():
|
||||
"""清空所有行情数据(仅限管理员调用)。"""
|
||||
storage.truncate_all()
|
||||
return {"status": "ok", "message": "已清空所有行情数据"}
|
||||
|
||||
@@ -152,3 +152,14 @@ def get_latest_score(ts_code: str, db_url: str = DEFAULT_DB_URL) -> Optional[dic
|
||||
return dict(row) if row else None
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def truncate_all(db_url: str = DEFAULT_DB_URL):
|
||||
"""清空所有行情数据(candles + scores),保留用户表。"""
|
||||
conn = _get_conn(db_url)
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("TRUNCATE TABLE candles, scores")
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user