Browse Source

Docs: clarify SQLite threading and pagination limit

Add clarifying comments explaining SQLite threading configuration
and the pagination limit in the SQL databases tutorial.

No behavior changes.
pull/14845/head
Kevin Chang 5 months ago
committed by GitHub
parent
commit
5f2208b332
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      docs_src/sql_databases/tutorial001_an_py39.py

6
docs_src/sql_databases/tutorial001_an_py39.py

@ -12,9 +12,9 @@ class Hero(SQLModel, table=True):
sqlite_file_name = "database.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"
sqlite_url = f"sqlite:///{sqlite_file_name}"
connect_args = {"check_same_thread": False}
connect_args = {"check_same_thread": False} # needed for SQLite when using the session across threads
engine = create_engine(sqlite_url, connect_args=connect_args)
@ -49,7 +49,7 @@ def create_hero(hero: Hero, session: SessionDep) -> Hero:
def read_heroes(
session: SessionDep,
offset: int = 0,
limit: Annotated[int, Query(le=100)] = 100,
limit: Annotated[int, Query(le=100)] = 100, # safety cap to avoid returning too many rows
) -> list[Hero]:
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
return heroes

Loading…
Cancel
Save