42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
检查销售订单的 created_at 字段
|
||
|
|
"""
|
||
|
|
import asyncio
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
project_root = Path(__file__).parent
|
||
|
|
sys.path.insert(0, str(project_root))
|
||
|
|
sys.path.insert(0, str(project_root / "src"))
|
||
|
|
|
||
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
||
|
|
from sqlalchemy import text
|
||
|
|
from config.settings import settings
|
||
|
|
|
||
|
|
|
||
|
|
async def check():
|
||
|
|
"""检查数据库中的 created_at 字段"""
|
||
|
|
if not settings.DATABASE_URL:
|
||
|
|
print("错误:未配置数据库连接")
|
||
|
|
return
|
||
|
|
|
||
|
|
engine = create_async_engine(
|
||
|
|
settings.DATABASE_URL,
|
||
|
|
echo=True
|
||
|
|
)
|
||
|
|
|
||
|
|
async with engine.begin() as conn:
|
||
|
|
# 查询销售订单的 created_at 字段
|
||
|
|
result = await conn.execute(text("SELECT id, order_no, created_at, order_date FROM sales_orders ORDER BY id DESC LIMIT 5"))
|
||
|
|
rows = result.fetchall()
|
||
|
|
print("\n销售订单数据:")
|
||
|
|
for row in rows:
|
||
|
|
print(f"ID: {row[0]}, 订单号: {row[1]}, created_at: {row[2]}, order_date: {row[3]}")
|
||
|
|
|
||
|
|
await engine.dispose()
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
asyncio.run(check())
|