cosmo_backend/scripts/list_celestial_bodies.py

32 lines
859 B
Python

"""
List celestial bodies from database
"""
import asyncio
from app.database import get_db
from app.models.db.celestial_body import CelestialBody
async def list_celestial_bodies():
"""List all celestial bodies"""
async for session in get_db():
try:
from sqlalchemy import select
stmt = select(CelestialBody).order_by(CelestialBody.type, CelestialBody.id)
result = await session.execute(stmt)
bodies = result.scalars().all()
print(f"\n📊 Found {len(bodies)} celestial bodies:\n")
print(f"{'ID':<20} {'Name':<25} {'Type':<10}")
print("=" * 60)
for body in bodies:
print(f"{body.id:<20} {body.name:<25} {body.type:<10}")
finally:
break
if __name__ == "__main__":
asyncio.run(list_celestial_bodies())