修复:PostgreSQL 语法适配 + UUID 自动生成
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m11s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m11s
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
所有子图的数据操作都用这个,避免重复代码
|
||||
"""
|
||||
import json
|
||||
import uuid
|
||||
from typing import Any, List, Dict, Optional
|
||||
from dataclasses import dataclass, asdict
|
||||
|
||||
@@ -53,7 +54,10 @@ class BaseRepository:
|
||||
async def insert(self, entity: BaseEntity) -> str:
|
||||
"""插入单个实体,返回 ID"""
|
||||
data = entity.to_dict()
|
||||
data.pop('id', None) # 如果 id 是自增的
|
||||
|
||||
# 确保有 ID
|
||||
if not data.get('id'):
|
||||
data['id'] = str(uuid.uuid4())
|
||||
|
||||
if not data:
|
||||
raise ValueError("实体数据为空")
|
||||
@@ -71,7 +75,7 @@ class BaseRepository:
|
||||
async with self.conn.cursor() as cur:
|
||||
await cur.execute(sql, values)
|
||||
row = await cur.fetchone()
|
||||
return row[self.id_column] if row else None
|
||||
return row[self.id_column] if row else data['id']
|
||||
|
||||
async def update(self, entity_id: str, data: Dict[str, Any]) -> bool:
|
||||
"""更新实体"""
|
||||
|
||||
Reference in New Issue
Block a user