feat: 完成项目助手与监控演示并修复聊天及云部署配置
This commit is contained in:
@@ -6,9 +6,9 @@ from decimal import Decimal
|
||||
import sqlite3
|
||||
|
||||
|
||||
def normalize(value):
|
||||
def normalize(value, exact_decimals=False):
|
||||
if isinstance(value, (date, datetime)): return value.isoformat()
|
||||
if isinstance(value, Decimal): return float(value)
|
||||
if isinstance(value, Decimal): return str(value) if exact_decimals else float(value)
|
||||
if isinstance(value, bytes): raise ValueError("查询包含二进制数据,请返回附件索引而非文件内容")
|
||||
return value
|
||||
|
||||
@@ -34,7 +34,7 @@ def validate_query(sql, allowed_tables, dialect):
|
||||
raise ValueError("查询使用了未授权的库表或视图")
|
||||
|
||||
|
||||
def execute(connection, sql, project_id):
|
||||
def execute(connection, sql, project_id, exact_decimals=False):
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.engine import URL
|
||||
kind = connection.get("type")
|
||||
@@ -84,7 +84,7 @@ def execute(connection, sql, project_id):
|
||||
db.exec_driver_sql(f"SET SESSION MAX_EXECUTION_TIME = {seconds*1000}")
|
||||
rows = db.execute(text(sql), {"project_id": project_id}).mappings().fetchmany(max_rows+1)
|
||||
if len(rows)>max_rows: raise ValueError(f"查询结果超过 {max_rows} 行,请缩小范围")
|
||||
return [{k:normalize(v) for k,v in row.items()} for row in rows]
|
||||
return [{k:normalize(v, exact_decimals) for k,v in row.items()} for row in rows]
|
||||
except ValueError:
|
||||
raise
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user