Complete the code to define an async function in FastAPI.
async def [1](): return {"message": "Hello"}
The function name can be any valid identifier. Here, get_data is used as a clear name for an async function.
Complete the code to await an async database query call.
result = [1] db.fetch_one(query)In async functions, you use await to wait for async calls like database queries to complete.
Fix the error in the async function declaration for a FastAPI route.
@app.get("/items") async def [1](): items = await db.fetch_all("SELECT * FROM items") return items
The function name get_items clearly indicates it handles a GET request for items, following common FastAPI naming conventions.
Fill both blanks to create a dictionary comprehension filtering async query results.
filtered = {item['id']: item for item in results if item[1] [2] 10}The comprehension filters items where the 'count' field is greater than 10, creating a dictionary keyed by 'id'.
Fill all three blanks to build an async function that queries and returns filtered data.
async def [1](): query = "SELECT * FROM users WHERE age [2] 21" results = await db.[3](query) return results
The function get_adult_users queries users older than 21 using fetch_all to get all matching records asynchronously.