-
-
Notifications
You must be signed in to change notification settings - Fork 479
feat(v3)!: Remove all SQLAlchemy modules in favor of direct advanced-alchemy imports #4340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cofin
merged 12 commits into
litestar-org:main
from
cofin:feat/v3-remove-sqlalchemy-completely
Oct 5, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b5c9826
feat(v3)!: Remove all SQLAlchemy modules in favor of direct advanced-…
cofin 579c2a2
chore: remove task rules
cofin 03a9780
fix: Remove SQLAlchemy API documentation and fix broken references
cofin 5a131cf
fix: remove sqlalchemy docs
cofin 01e449d
fix: remove SQLAlchemy test files and fix sphinx warnings
cofin 84950b5
fix: remove markdown files that shouldn't be in the repository
cofin 2d34db9
feat: restore SQLAlchemy tutorial with Advanced Alchemy imports
cofin 89f4f85
Apply suggestion from @cofin
cofin 3e2d50c
Apply suggestion from @cofin
cofin b33d632
chore(docs): correct build issues
cofin 754e30d
fully restore tutorials and usage docs
provinzkraut 63c7d98
rename examples.sqlalchemy -> examples.sqla to fix name-clash
provinzkraut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/examples/data_transfer_objects/factory/paginated_return_data.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/examples/data_transfer_objects/factory/renaming_all_fields.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/examples/data_transfer_objects/factory/response_return_data.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/examples/data_transfer_objects/factory/simple_dto_factory_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
docs/examples/pagination/using_offset_pagination_with_sqlalchemy.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
88 changes: 88 additions & 0 deletions
88
docs/examples/plugins/sqlalchemy_init_plugin/full_app_with_init_plugin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from collections.abc import AsyncGenerator | ||
from typing import Optional | ||
|
||
from advanced_alchemy.extensions.litestar import ( | ||
SQLAlchemyAsyncConfig, | ||
SQLAlchemyInitPlugin, | ||
SQLAlchemySerializationPlugin, | ||
) | ||
from sqlalchemy import select | ||
from sqlalchemy.exc import IntegrityError, NoResultFound | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column | ||
|
||
from litestar import Litestar, get, post, put | ||
from litestar.exceptions import ClientException, NotFoundException | ||
from litestar.status_codes import HTTP_409_CONFLICT | ||
|
||
|
||
class Base(DeclarativeBase): ... | ||
|
||
|
||
class TodoItem(Base): | ||
__tablename__ = "todo_items" | ||
|
||
title: Mapped[str] = mapped_column(primary_key=True) | ||
done: Mapped[bool] | ||
|
||
|
||
async def provide_transaction(db_session: AsyncSession) -> AsyncGenerator[AsyncSession, None]: | ||
try: | ||
async with db_session.begin(): | ||
yield db_session | ||
except IntegrityError as exc: | ||
raise ClientException( | ||
status_code=HTTP_409_CONFLICT, | ||
detail=str(exc), | ||
) from exc | ||
|
||
|
||
async def get_todo_by_title(todo_name: str, session: AsyncSession) -> TodoItem: | ||
query = select(TodoItem).where(TodoItem.title == todo_name) | ||
result = await session.execute(query) | ||
try: | ||
return result.scalar_one() | ||
except NoResultFound as e: | ||
raise NotFoundException(detail=f"TODO {todo_name!r} not found") from e | ||
|
||
|
||
async def get_todo_list(done: Optional[bool], session: AsyncSession) -> list[TodoItem]: | ||
query = select(TodoItem) | ||
if done is not None: | ||
query = query.where(TodoItem.done.is_(done)) | ||
|
||
result = await session.execute(query) | ||
return list(result.scalars().all()) | ||
|
||
|
||
@get("/") | ||
async def get_list(transaction: AsyncSession, done: Optional[bool] = None) -> list[TodoItem]: | ||
return await get_todo_list(done, transaction) | ||
|
||
|
||
@post("/") | ||
async def add_item(data: TodoItem, transaction: AsyncSession) -> TodoItem: | ||
transaction.add(data) | ||
return data | ||
|
||
|
||
@put("/{item_title:str}") | ||
async def update_item(item_title: str, data: TodoItem, transaction: AsyncSession) -> TodoItem: | ||
todo_item = await get_todo_by_title(item_title, transaction) | ||
todo_item.title = data.title | ||
todo_item.done = data.done | ||
return todo_item | ||
|
||
|
||
db_config = SQLAlchemyAsyncConfig( | ||
connection_string="sqlite+aiosqlite:///todo.sqlite", metadata=Base.metadata, create_all=True | ||
) | ||
|
||
app = Litestar( | ||
[get_list, add_item, update_item], | ||
dependencies={"transaction": provide_transaction}, | ||
plugins=[ | ||
SQLAlchemySerializationPlugin(), | ||
SQLAlchemyInitPlugin(db_config), | ||
], | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.