mcps / test /test_supabase_read.py
airsltd's picture
update
4b2a02f
import os
from airs.base import Base
from dotenv import load_dotenv
# 加载环境变量
load_dotenv()
def test_read_tasks():
print("正在初始化 Base 类...")
base_instance = Base()
print("Base 类初始化完成。")
try:
print("正在尝试从 'tasks' 表读取数据...")
# 直接使用 Supabase 客户端查询
response = base_instance.supabase.table('tasks').select('*').execute()
if response.data:
print("成功读取数据:")
for task in response.data:
print(task)
return {"success": True, "tasks": response.data}
else:
print("未读取到数据或发生未知错误。")
return {"success": False, "error": response.error.message if response.error else "No data or unknown error"}
except Exception as e:
print(f"读取数据时发生错误: {e}")
return {"success": False, "error": str(e)}
if __name__ == "__main__":
result = test_read_tasks()
print("\n测试结果:")
print(result)