32 lines
948 B
Python
32 lines
948 B
Python
import asyncio
|
|
import sys
|
|
import aiomysql
|
|
from dotenv import load_dotenv
|
|
load_dotenv(".env")
|
|
|
|
from config.config_db import init_db_pool, close_db_pool
|
|
|
|
async def main():
|
|
await init_db_pool()
|
|
from config.config_db import get_db_pool
|
|
pool = get_db_pool()
|
|
async with pool.acquire() as connection, connection.cursor(aiomysql.DictCursor) as cursor:
|
|
try:
|
|
await cursor.execute("SELECT * FROM users")
|
|
users = await cursor.fetchall()
|
|
print("Users count:", len(users))
|
|
for u in users:
|
|
print(u)
|
|
|
|
await cursor.execute("SELECT * FROM companies")
|
|
companies = await cursor.fetchall()
|
|
print("Companies count:", len(companies))
|
|
for c in companies:
|
|
print(c)
|
|
except Exception as e:
|
|
print("Error:", e)
|
|
await close_db_pool()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|