Which of the following best explains why databases persist data?
Think about what happens to data when the computer or app is turned off.
Databases save data permanently so it is not lost when the app or server stops. This is called persistence.
Consider a FastAPI app connected to a database. What happens to the data stored in the database if the server restarts?
Think about the purpose of persistent storage.
Databases store data on disk or other permanent storage, so data stays safe even if the server restarts.
Which FastAPI code snippet correctly saves data to a database so it persists?
from fastapi import FastAPI from sqlalchemy.orm import Session from models import Item app = FastAPI() @app.post('/items/') async def create_item(item: Item, db: Session): # Save item to database ...
Look for the standard SQLAlchemy methods to add and save data.
In SQLAlchemy, use add() to add an object and commit() to save changes persistently.
Given a FastAPI app that saves user data to a database, what will be the output of fetching users after restarting the app?
from fastapi import FastAPI from sqlalchemy.orm import Session from models import User app = FastAPI() @app.get('/users/') async def read_users(db: Session): return db.query(User).all()
Think about whether data saved before restart is still there.
Since the data is saved persistently in the database, it remains available after app restart.
Review this FastAPI code snippet. Why does the data disappear after restarting the app?
from fastapi import FastAPI app = FastAPI() items = [] @app.post('/items/') async def add_item(name: str): items.append(name) return {'items': items}
Think about where the data is saved and what happens when the app restarts.
Data stored in a Python list exists only while the app runs. Restarting clears memory, so data is lost.