pre-commit-ci-lite[bot]
5 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
13 additions and
5 deletions
-
docs_src/sql_databases/tutorial001_an_py310.py
-
docs_src/sql_databases/tutorial001_an_py39.py
|
|
@ -14,7 +14,9 @@ class Hero(SQLModel, table=True): |
|
|
sqlite_file_name = "database.db" |
|
|
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} # needed for SQLite when using the session across threads |
|
|
connect_args = { |
|
|
|
|
|
"check_same_thread": False |
|
|
|
|
|
} # needed for SQLite when using the session across threads |
|
|
engine = create_engine(sqlite_url, connect_args=connect_args) |
|
|
engine = create_engine(sqlite_url, connect_args=connect_args) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +51,9 @@ def create_hero(hero: Hero, session: SessionDep) -> Hero: |
|
|
def read_heroes( |
|
|
def read_heroes( |
|
|
session: SessionDep, |
|
|
session: SessionDep, |
|
|
offset: int = 0, |
|
|
offset: int = 0, |
|
|
limit: Annotated[int, Query(le=100)] = 100, # safety cap to avoid returning too many rows |
|
|
limit: Annotated[ |
|
|
|
|
|
int, Query(le=100) |
|
|
|
|
|
] = 100, # safety cap to avoid returning too many rows |
|
|
) -> list[Hero]: |
|
|
) -> list[Hero]: |
|
|
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() |
|
|
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() |
|
|
return heroes |
|
|
return heroes |
|
|
|
|
|
@ -12,9 +12,11 @@ class Hero(SQLModel, table=True): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlite_file_name = "database.db" |
|
|
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} # needed for SQLite when using the session across threads |
|
|
connect_args = { |
|
|
|
|
|
"check_same_thread": False |
|
|
|
|
|
} # needed for SQLite when using the session across threads |
|
|
engine = create_engine(sqlite_url, connect_args=connect_args) |
|
|
engine = create_engine(sqlite_url, connect_args=connect_args) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +51,9 @@ def create_hero(hero: Hero, session: SessionDep) -> Hero: |
|
|
def read_heroes( |
|
|
def read_heroes( |
|
|
session: SessionDep, |
|
|
session: SessionDep, |
|
|
offset: int = 0, |
|
|
offset: int = 0, |
|
|
limit: Annotated[int, Query(le=100)] = 100, # safety cap to avoid returning too many rows |
|
|
limit: Annotated[ |
|
|
|
|
|
int, Query(le=100) |
|
|
|
|
|
] = 100, # safety cap to avoid returning too many rows |
|
|
) -> list[Hero]: |
|
|
) -> list[Hero]: |
|
|
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() |
|
|
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() |
|
|
return heroes |
|
|
return heroes |
|
|
|