25 lines
660 B
Python
25 lines
660 B
Python
from app.db.session import SessionLocal
|
|
from app.models.todo import Todo
|
|
|
|
# Create a database session
|
|
db = SessionLocal()
|
|
|
|
try:
|
|
# Create a test todo
|
|
test_todo = Todo(
|
|
title="Test Todo",
|
|
description="This is a test todo created to verify database operations",
|
|
)
|
|
db.add(test_todo)
|
|
db.commit()
|
|
db.refresh(test_todo)
|
|
print(f"Created Todo with ID: {test_todo.id}")
|
|
|
|
# Query and list all todos
|
|
todos = db.query(Todo).all()
|
|
print(f"Found {len(todos)} todos in the database:")
|
|
for todo in todos:
|
|
print(f" - {todo.id}: {todo.title} (Completed: {todo.completed})")
|
|
|
|
finally:
|
|
db.close() |