31 lines
953 B
Python
31 lines
953 B
Python
|
|
#!/usr/bin/env python
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import asyncio
|
||
|
|
import sys
|
||
|
|
sys.path.insert(0, 'ruoyi-fastapi-backend')
|
||
|
|
|
||
|
|
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
|
||
|
|
from urllib.parse import quote_plus
|
||
|
|
|
||
|
|
DB_URL = f'mysql+asyncmy://cpy_admin:{quote_plus("Tgzz2025+")}@localhost:3307/ruoyi-fastapi'
|
||
|
|
|
||
|
|
async def test():
|
||
|
|
from sqlalchemy import text
|
||
|
|
|
||
|
|
engine = create_async_engine(DB_URL, echo=False)
|
||
|
|
AsyncSession = async_sessionmaker(engine, expire_on_commit=False)
|
||
|
|
|
||
|
|
async with AsyncSession() as db:
|
||
|
|
# 查询最新的5个入库单
|
||
|
|
result = await db.execute(text("""
|
||
|
|
SELECT receipt_id, receipt_no, create_time
|
||
|
|
FROM warehouse_receipt
|
||
|
|
ORDER BY receipt_id DESC LIMIT 5
|
||
|
|
"""))
|
||
|
|
rows = result.fetchall()
|
||
|
|
print("Latest receipts:")
|
||
|
|
for row in rows:
|
||
|
|
print(f" ID={row[0]}, No={row[1]}, Time={row[2]}")
|
||
|
|
|
||
|
|
asyncio.run(test())
|