Files
aiData/DbKit/Test/Test.py
HuangHai b66f683dfb 'commit'
2026-01-12 07:49:18 +08:00

67 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
import logging
from DbKit.Db import Db
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
"""测试查询t_teacher_app表"""
db = Db()
async def test_find_teacher_app():
try:
# 执行查询
sql = "select * from t_teacher_app where app_name=:app_name"
params = {"app_name": "半角模型"}
logger.info(f"执行查询: {sql}")
result = await db.find(sql, params)
logger.info(f"查询结果数量: {len(result)}")
# 打印部分结果(前3条)
for i, row in enumerate(result[:3]):
logger.info(f"第{i + 1}条记录: {row}")
return result
except Exception as e:
logger.error(f"查询失败: {str(e)}", exc_info=True)
raise
async def test_sql_template():
try:
# 初始化数据库连接
await db.init_db()
# 测试获取App.getAppList模板
logger.info("尝试获取App.getAppList模板...")
sql_content = await db.get_sql("App.getAppList")
logger.info(f"成功获取App.getAppList模板,内容长度: {len(sql_content)} 字符")
logger.info(f"模板内容前100字符: {sql_content[:100]}")
# 测试分页查询
logger.info("测试分页查询...")
result = await db.paginate("App.getAppList", page_number=1, page_size=5)
logger.info(f"分页查询结果: {len(result.get('list', []))} 条记录")
except Exception as e:
logger.error(f"SQL模板测试失败: {str(e)}", exc_info=True)
raise
async def run_all_tests():
"""运行所有测试"""
logger.info("开始运行所有测试...")
# 测试SQL模板自动加载
await test_sql_template()
# 测试查询功能
await test_find_teacher_app()
logger.info("所有测试完成!")
if __name__ == '__main__':
# 运行异步测试
asyncio.run(run_all_tests())