docs(readme): async + Pydantic v2 quickstart, override LIST and POST examples#7
Merged
Merged
Conversation
- Add 'Async quickstart (SQLAlchemy 2.x + Pydantic v2)' section with AsyncBaseViewset, ConfigDict(from_attributes=True) schema, and startup-driven Base.metadata.create_all on async_engine. - Add 'Overriding list and create_element' section showing how to subclass AsyncBaseViewset to implement case-insensitive search + whitelist ordering on LIST and input normalization + IntegrityError -> 409 on POST. - Note caveats: register() patches item annotation to response_model; signatures and the 'item' body parameter must be preserved; keep one schema for request and response (or pre-validate inside the handler). - Mention graceful sync fallback when async DB-API driver is missing (in line with 1.2.1 fix).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds two new sections to the README that target the most common questions after the 1.2.x release:
AsyncBaseViewsetexample using the lazydb_confhelpers (Base,async_engine,get_async_session) and a Pydantic v2 schema withConfigDict(from_attributes=True). Tables are created on FastAPI startup viaasync_engine.begin() / run_sync(Base.metadata.create_all).listandcreate_element\u2014 shows how to subclassAsyncBaseViewsetto implement custom LIST (case-insensitivesearch+ whitelistorder_by) and custom POST (input normalization, mappingIntegrityErrorto HTTP 409).Highlights
model_config = ConfigDict(from_attributes=True),model_dump(exclude_unset=True)).register()contract: keep method names and theitembody parameter, register() rewritesitemannotation toresponse_model, so reusing one schema for request + response is the safe default.aiosqlite/asyncpg/aiomysql) is not installed.Verification
AsyncBaseViewsetsource and_RegisterMixin.register.tests/test_viewsets_with_adapters.py::TestAsyncBaseViewsetWithAdapter.