pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/fastapi/sqlmodel/pull/1757.patch

Optional[int] = Field(default=None, index=True) + + +sqlite_file_name = "database.db" +sqlite_url = f"sqlite+aiosqlite://github.com/{sqlite_file_name}" + +engine = create_async_engine(sqlite_url, echo=True) + + +async def init_db(): + async with engine.begin() as conn: + await conn.run_sync(SQLModel.metadata.create_all) + + +app = FastAPI() + + +@app.on_event("startup") +async def on_startup(): + await init_db() + + +async def get_session(): + async with AsyncSession(engine) as session: + yield session + + +@app.post("/heroes/", response_model=Hero) +async def create_hero(hero: Hero, session: AsyncSession = Depends(get_session)): + session.add(hero) + await session.commit() + await session.refresh(hero) + return hero + + +@app.get("/heroes/", response_model=List[Hero]) +async def read_heroes(session: AsyncSession = Depends(get_session)): + result = await session.exec(select(Hero)) + heroes = result.all() + return heroes diff --git a/mkdocs.yml b/mkdocs.yml index b89516e024..05979d5227 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -127,6 +127,7 @@ nav: - tutorial/fastapi/tests.md - Advanced User Guide: - advanced/index.md + - tutorial/async/index.md - advanced/decimal.md - advanced/uuid.md - Resources: diff --git a/sqlmodel/ext/asyncio/__init__.py b/sqlmodel/ext/asyncio/__init__.py index e69de29bb2..51b71e7e98 100644 --- a/sqlmodel/ext/asyncio/__init__.py +++ b/sqlmodel/ext/asyncio/__init__.py @@ -0,0 +1 @@ +from .session import AsyncSession as AsyncSession From 901f99b0d56df8e6c6e7aa3daa112e663d5e9122 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Thu, 12 Feb 2026 07:06:46 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tutorial/async/index.md | 2 +- docs_src/tutorial/async/tutorial001_py310.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tutorial/async/index.md b/docs/tutorial/async/index.md index 63cb26eacc..40017125d6 100644 --- a/docs/tutorial/async/index.md +++ b/docs/tutorial/async/index.md @@ -100,7 +100,7 @@ async def read_heroes(session: AsyncSession): ### Async Database Drivers -Make sure you use an asynchronous database driver. +Make sure you use an asynchronous database driver. * For **SQLite**, use `aiosqlite` with `sqlite+aiosqlite://`. * For **PostgreSQL**, use `asyncpg` with `postgresql+asyncpg://`. diff --git a/docs_src/tutorial/async/tutorial001_py310.py b/docs_src/tutorial/async/tutorial001_py310.py index 800d688803..b85fc265d0 100644 --- a/docs_src/tutorial/async/tutorial001_py310.py +++ b/docs_src/tutorial/async/tutorial001_py310.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Depends +from fastapi import Depends, FastAPI from sqlalchemy.ext.asyncio import create_async_engine from sqlmodel import Field, SQLModel, select from sqlmodel.ext.asyncio import AsyncSession pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy