Litestar Integration¶
sqlspec.extensions.litestar provides SQLSpecPlugin, wiring SQLSpec connection pools into Litestar's application lifespan, registering request-scoped session and connection dependencies, mounting litestar db / litestar database and litestar sessions delete-expired CLI commands, providing declarative query filter dependencies, and supplying server-side Litestar Store and ChannelsBackend implementations across supported database adapters.
Installation¶
Plugin Setup and Session Injection¶
flowchart LR
Lifespan["Litestar Lifespan (Pool Init & Close)"] --> Request["HTTP Request Middleware"]
Request --> DI["Inject db_session + Filter Dependencies"]
DI --> Handler["Route Handler / Domain Service"]
Handler --> Commit["Commit Mode (manual / autocommit)"]
Pass a single database configuration, a sequence of configurations, or a SQLSpec registry to SQLSpecPlugin and register it in Litestar(plugins=[...]):
from typing import Any
from litestar import Litestar, get
from litestar.di import NamedDependency
from sqlspec.adapters.sqlite import SqliteConfig, SqliteDriver
from sqlspec.extensions.litestar import SQLSpecPlugin
@get("/health", sync_to_thread=False)
def health_check(db_session: NamedDependency[SqliteDriver]) -> dict[str, Any]:
"""Execute a health-check query against the injected SQLite session."""
return db_session.select_one("SELECT 'ok' AS status")
plugin = SQLSpecPlugin(
SqliteConfig(
connection_config={"database": ":memory:"}, extension_config={"litestar": {"session_key": "db_session"}}
)
)
app = Litestar(route_handlers=[health_check], plugins=[plugin])
By default, a single configuration registers db_session, db_connection, and db_pool in Litestar's dependency graph, and plugin.get_config() returns that configuration. Override session_key, connection_key, or pool_key inside extension_config["litestar"] to customize parameter names.
Configuration Options¶
Configure extension_config["litestar"] (LitestarConfig) per database configuration:
| Key | Type | Default | Description |
|---|---|---|---|
tenant_extractor |
Callable[[MutableMapping[str, Any]], Any] |
- | Trusted scope callable returning a tenant identity, payload, None (no tenant from this source), or an awaitable. Requires tenant_strategy on the same configuration; called on first tenant use, never at request start. |
tenant_user_attr |
str |
'tenant_id' |
Verified direct tenant attribute or mapping key. Default: 'tenant_id'. |
tenant_memberships_attr |
str |
'tenant_ids' |
Verified membership attribute or mapping key. Default: 'tenant_ids'. |
tenant_variables_attr |
str |
'tenant_variables' |
Extra session variables attribute or mapping key. Default: 'tenant_variables'. |
tenant_jwt_claim |
str |
'tenant_id' |
Direct tenant key in verified auth claims or extras. Default: 'tenant_id'. |
tenant_path_parameter |
str or None |
'tenant_id' |
Route parameter checked against verified memberships. Default: 'tenant_id'. |
tenant_session_key |
str or None |
'tenant_id' |
Session selector checked against verified memberships. Default: 'tenant_id'. |
tenant_header |
str or None |
None |
Optional header selector checked against verified memberships. Default: None. |
migrations_path |
str or Path |
- | Directory containing this extension's migrations, or a '<dotted.module>:<subdir>' specification. Overrides the default sqlspec.extensions.<name> lookup. Setting this auto-includes the extension in migration_config["include_extensions"]. |
session_table |
bool or str |
- | Enable session table for server-side session storage. True: Use default table name ('litestar_session'); "custom_name": Use custom table name. When set, litestar extension migrations are auto-included to create the session table. If you're only using litestar for DI/connection management (not session storage), leave this unset to skip the migrations. |
connection_key |
str |
'db_connection' |
Key for storing connection in ASGI scope. Default: 'db_connection' |
pool_key |
str |
'db_pool' |
Key for storing connection pool in application state. Default: 'db_pool' |
session_key |
str |
'db_session' |
Key for storing session in ASGI scope. Default: 'db_session' |
commit_mode |
Literal['manual', 'autocommit', 'autocommit_include_redirect'] |
'autocommit' |
Transaction commit mode. Default: 'autocommit' |
enable_correlation_middleware |
bool |
True |
Enable request correlation ID middleware. Default: True |
correlation_header |
str |
X-Request-ID |
HTTP header to read the request correlation ID from when middleware is enabled. Default: X-Request-ID |
correlation_headers |
tuple[str, ...] or list[str] |
- | Additional HTTP headers to read as correlation ID fallbacks. |
auto_trace_headers |
bool |
True |
Read standard trace context headers as correlation ID fallbacks. Default: True. |
extra_commit_statuses |
set[int] |
set() |
Additional HTTP status codes that trigger commit. Default: set() |
extra_rollback_statuses |
set[int] |
set() |
Additional HTTP status codes that trigger rollback. Default: set() |
disable_di |
bool |
False |
Disable built-in dependency injection. Default: False. When True, the Litestar plugin will not register dependency providers for database connections, pools, and sessions, or the per-request handler that commits and closes request connections. Pool startup and shutdown follow manage_lifespan, which defaults to False when disable_di is True. |
manage_lifespan |
bool |
- | Register the plugin's pool lifespan handler. Default: the inverse of disable_di. When True, the Litestar plugin creates the configuration's pool on application startup, stores it in application state under pool_key, and closes it on shutdown, whether or not disable_di is set. Set to True alongside disable_di=True to keep pool lifecycle management while another DI solution provides connections and sessions. When False, the application creates and closes the pool itself; with dependency injection enabled, the plugin's providers still read the pool from application state under pool_key. |
enable_sqlcommenter_middleware |
bool |
True |
Control automatic SQLCommenter middleware registration. Default: True. When the driver's :class:~sqlspec.core.statement.StatementConfig has enable_sqlcommenter=True, the middleware is registered automatically. Set to False to explicitly disable middleware registration even when SQLCommenter is enabled on the driver config. |
manage_schema |
bool |
True |
Apply additive session-table reconciliation. Default: True. |
create_schema |
bool |
True |
Create a missing session table during managed reconciliation. Default: True. |
migration_mode |
ExtensionMigrationMode |
'reconcile' |
Extension migration strategy ('versioned' or 'reconcile'). Default: 'reconcile'. |
replica_session_key |
str |
- | Request key for a replica session. |
replica_connection_key |
str |
- | Request key for a replica connection. |
routing_session_key |
str |
- | Request key for a routing session. |
default_routing_mode |
Literal['primary', 'auto'] |
'auto' |
Default request routing mode. Default: 'auto'. |
enable_routing_middleware |
bool |
True |
Install request-scoped routing middleware. Default: True. |
routing_header |
str or None |
None |
Trusted application routing header name when explicitly enabled behind a gateway. Default: None. |
primary_pin_cookie |
str or None |
None |
Optional application primary pin cookie name. Default: None. |
primary_pin_secret |
str or bytes or None |
None |
Optional HMAC secret verifying signed primary pin cookies. Default: None. |
replica_pool_key |
str |
- | Request key for the selected replica pool. |
pagination_cursor_secret |
str or bytes |
- | Application-wide secret enabling HMAC-SHA256 signed pagination cursors. |
pagination_cursor_ttl |
int or float or dt.timedelta |
- | Default cursor expiration window in seconds or timedelta. |
pagination_cursor_encrypted |
bool |
- | Encrypt cursor payloads at rest when a cursor secret is configured. |
Multi-Database Dependency Keys¶
When an application connects to multiple databases (for example, a transactional primary database and a read-heavy analytics database), pass the list of configurations to SQLSpecPlugin([...]) with a distinct bind_key and session_key on each configuration:
from sqlspec.adapters.sqlite import SqliteConfig
from sqlspec.extensions.litestar import SQLSpecPlugin
plugin = SQLSpecPlugin([
SqliteConfig(
bind_key="primary",
connection_config={"database": ":memory:"},
extension_config={
"litestar": {"session_key": "primary", "connection_key": "primary_conn", "pool_key": "primary_pool"}
},
),
SqliteConfig(
bind_key="analytics",
connection_config={"database": ":memory:"},
extension_config={
"litestar": {"session_key": "analytics", "connection_key": "analytics_conn", "pool_key": "analytics_pool"}
},
),
])
On-Demand Session and Connection Acquisition¶
In custom guards, middleware, streaming iterators, or event hooks where standard route dependency injection is not active, SQLSpecPlugin exposes direct scope-backed session and connection accessors. ConnectionCleanupMiddleware stays outer to application middleware so inner before_send hooks evaluate commit_mode on http.response.start and release non-streaming HTTP responses on the terminal http.response.body (more_body=False) (or immediately on http.response.start if finalization raises), while streaming responses (more_body=True, Stream responses, or connections acquired after http.response.start) defer cleanup to ConnectionCleanupMiddleware when the ASGI request completes or cancels. Once released, the request session detaches its underlying connection and raises ImproperConfigurationError if accessed after teardown:
plugin.provide_db_session(key, state, scope)andplugin.provide_db_connection(key, state, scope)(when the connection already exists in ASGI scope). For an async configuration whose connection is not open yet,provide_db_sessionreturns a session that acquires it on the first awaited call, with the same tenant resolution and commit handling asprovide_db_session_async;provide_db_connectionraisesImproperConfigurationErrornaming the async accessor.plugin.provide_db_session_sync(key, state, scope)andplugin.provide_db_connection_sync(key, state, scope)(acquires a sync connection on demand if not yet present inscope; async configurations behave asprovide_db_sessionandprovide_db_connection).await plugin.provide_db_session_async(key, state, scope)andawait plugin.provide_db_connection_async(key, state, scope)(acquires an async connection on demand if not yet present inscope).
Tenant-Aware Requests¶
With driver_features={"tenant_strategy": "rls"} on a supported adapter, injected db_session and db_connection dependencies and guards=[require_tenant()] resolve the request tenant from verified authentication state, using the selector and user attribute names set once in extension_config["litestar"]. Mark public routes with opt={"tenant_bypass": True}. See Litestar Multi-Tenancy for JWT, server-side session, separate auth database, and litestar-security examples, and the Tenant Request Contract for the rules every framework shares.
Reader and routing dependencies¶
A config with replicas exposes db_replica_session, db_replica_connection, and replica_pool. Rename them with replica_session_key, replica_connection_key, and replica_pool_key. Set routing_session_key to opt into a routing session. A reader opens on first use. It does not open a primary session first.
For direct access, use get_db_replica_session(request) or provide_db_replica_session and its _sync/_async forms. The provide_db_routing_session* helpers return routing sessions. Read connection helpers use the same names with connection in place of session. Pass a config or bind key to choose the database.
Tenant middleware binds the captured TenantContextPayload around each physical checkout, including readers. SQLSpecRoutingMiddleware scopes primary pins and reads stateless hints. Check tenant access in the normal request path. See Read Replicas for fallback and freshness choices.
Automatic HTTP 404 and 409 Exception Mapping¶
During SQLSpecPlugin.on_app_init, the plugin registers two default exception handlers unless your application already defines custom handlers for those exception types:
not_found_error_handler: Mapssqlspec.exceptions.NotFoundError(such asselect_onereturning zero rows) to an HTTP404 NotFoundExceptionresponse.integrity_error_handler: Mapssqlspec.exceptions.IntegrityError(includingUniqueViolationError,ForeignKeyViolationError, andCheckViolationError) to an HTTP409 Conflictresponse.
Transaction Commit Modes¶
Configure commit_mode inside extension_config["litestar"] to control how request-scoped sessions finalize when a route handler returns:
| Commit Mode | Commits On | Rolls Back On | Best For |
|---|---|---|---|
"autocommit" (default) |
Clean HTTP 200–299 responses |
HTTP >= 300 responses (3xx, 4xx, 5xx), any raised exception (including mapped 2xx responses), or cancellation |
JSON REST APIs where every 2xx handler mutates state |
"autocommit_include_redirect" |
Clean HTTP 200–399 responses |
HTTP >= 400 responses, any raised exception (including mapped 2xx/3xx responses), or cancellation |
HTML, HTMX, and Inertia.js form handlers that commit and return 302 / 303 redirects |
"manual" |
Explicit session.commit() calls only |
Uncommitted handler work on clean return, unhandled or mapped exceptions, and request cancellations | Explicit service-layer transaction boundaries |
from sqlspec import SQLSpec
from sqlspec.adapters.sqlite import SqliteConfig
from sqlspec.extensions.litestar import SQLSpecPlugin
spec = SQLSpec()
spec.add_config(
SqliteConfig(
connection_config={"database": ":memory:"}, extension_config={"litestar": {"commit_mode": "autocommit"}}
)
)
spec.add_config(
SqliteConfig(
bind_key="manual",
connection_config={"database": ":memory:"},
extension_config={"litestar": {"commit_mode": "manual"}},
)
)
plugin = SQLSpecPlugin(sqlspec=spec)
Add extra_commit_statuses or extra_rollback_statuses in LitestarConfig when "autocommit" or "autocommit_include_redirect" requires custom commit or rollback status overrides.
On adbc, arrow_odbc, asyncpg, cockroach_asyncpg, db2, duckdb, psqlpy, snowflake, sybase, and teradata, requests running under "manual", "autocommit", or "autocommit_include_redirect" open their transaction lazily on the first write statement rather than issuing an eager BEGIN at request start, eliminating extra transaction round trips on read-only handlers.
Request Failure Handling¶
Litestar manages request connections across two distinct paths, and both forward exceptions and cancellations to the adapter's connection context exit (__aexit__):
- Injected dependencies (
db_session/db_connection): The dependency generator owns the connection context while the route handler executes. If the handler raisesBaseException, the generator exits the connection context immediately with(exc_type, exc_val, exc_tb)before Litestar renders an exception response. When an HTTP handler returns normally beforehttp.response.start, the generator hands the open context to ASGI scope so innerbefore_sendappliescommit_modeagainst the response status and exits the context immediately for non-streaming responses, deferring streaming responses (Stream) until the stream completes or cancels in the outerConnectionCleanupMiddleware. Ifasyncio.CancelledErroror an error inafter_request, response serialization, or an exception handler aborts the request beforehttp.response.start,ConnectionCleanupMiddlewarerolls back uncommitted work and exits the context. After finalization, the closed session raisesImproperConfigurationErroron further queries instead of reading a returned pool connection. - On-demand accessors (
provide_db_session_*/provide_db_connection_*): Connections live directly in ASGI scope. Whenever a handler or hook raises an exception, Litestar'safter_exceptionhook runsrecord_request_exceptionto store the exception in scope before sending the error response. Bothbefore_send(underautocommitandmanualmodes) andConnectionCleanupMiddlewarecheck this recorded exception before inspecting HTTP status codes, rolling back uncommitted writes and passing(exc_type, exc_val, exc_tb)to__aexit__.
Both unhandled exceptions and exceptions mapped to HTTP responses by Litestar exception_handlers (such as HTTPException, NotFoundError, IntegrityError, or custom handlers returning 4xx or 2xx fallback responses) record the exception via after_exception and roll back uncommitted work. By contrast, Starlette, FastAPI, and Flask treat exceptions already converted into responses by inner framework exception handlers as normal responses at the middleware boundary unless status-based rollback applies.
In "manual" mode, uncommitted handler writes roll back consistently before releasing the connection back to the pool (only adapters without session-level multi-statement transactions—such as bigquery outside explicit session transactions and non-transactional spanner snapshots—are outside DB-API session rollback).
In short, the request connection's lifetime depends on the response type:
- Normal responses: The request connection is committed or rolled back when the response starts and released after the final body frame.
- Streaming responses: The connection stays held until the stream finishes or the client disconnects, so the request session works inside a
Streambody. - Background work: A background task runs after the connection is released. Open a new session with
config.provide_session()inside the task.
A session or stream cannot be used after its connection is released; trying to raises ImproperConfigurationError.
Declarative Query Filter Providers¶
Use create_filter_dependencies with FilterConfig to generate OpenAPI-documented Litestar dependencies that parse query parameters directly into StatementFilter lists (LimitOffsetFilter, OrderByFilter, SearchFilter, BeforeAfterFilter, CursorFilter, and InCollectionFilter):
from datetime import datetime
from typing import Annotated, Any
from uuid import UUID
from litestar import Litestar, get
from litestar.params import Dependency
from sqlspec.adapters.asyncpg import AsyncpgDriver
from sqlspec.core import FilterTypes
from sqlspec.extensions.litestar.providers import (
FilterConfig,
create_filter_dependencies,
)
user_filters = create_filter_dependencies(
FilterConfig(
id_filter=UUID,
id_field="id",
sort_field="created_at",
sort_order="desc",
pagination_type="limit_offset",
pagination_size=25,
pagination_max_size=100,
search="name,email",
search_ignore_case=True,
created_at=True,
updated_at=True,
)
)
@get("/users", dependencies=user_filters)
async def list_users(
db_session: AsyncpgDriver,
filters: Annotated[list[FilterTypes], Dependency(skip_validation=True)],
) -> list[dict[str, Any]]:
return await db_session.select(
"SELECT id, name, email, created_at FROM users", *filters
)
For bidirectional keyset pagination (CursorPagination), set pagination_type="cursor" and pagination_cursor_keys="id" (or pass CursorKey specs) on FilterConfig; see Filtering and Pagination. Configure application-wide cursor signing (pagination_cursor_secret), expiration (pagination_cursor_ttl), and payload encryption (pagination_cursor_encrypted) once via LitestarConfig or SQLSpecPlugin(..., pagination_cursor_secret=..., pagination_cursor_ttl=..., pagination_cursor_encrypted=...) (falling back to SQLSPEC_PAGINATION_CURSOR_SECRET / SECRET_KEY environment variables when omitted); create_filter_dependencies(...) inherits those settings from application state automatically and derives per-endpoint signing keys without duplicating configuration per controller. A cursor secret is required: cursor requests raise ImproperConfigurationError when none resolves. Tokens are bound to the request tenant of every tenant-enabled configuration, so a token from one tenant is rejected for another. Search filters escape %, _, and / by default; set search_escape_wildcards=False in FilterConfig to opt out.
Server-Side Session Stores¶
Supported database adapters export a Litestar Store implementation under sqlspec.adapters.<adapter>.litestar (for example, AiosqliteStore, AsyncpgStore, OracleAsyncStore, or SpannerAsyncStore; see the Database Capability Matrix for per-adapter store support):
from sqlspec.adapters.aiosqlite import AiosqliteConfig
from sqlspec.adapters.aiosqlite.litestar import AiosqliteStore
config = AiosqliteConfig(connection_config={"database": ":memory:"})
store = AiosqliteStore(config)
Call await store.create_table() during application startup (or configure session_table=True in extension_config["litestar"], which auto-includes the litestar_session table in migrations) and pass the store to Litestar's ServerSideSessionConfig or stores={"sessions": store} registry.
While a request holds an open database session for the store's configuration, session writes made by the request itself (including the writes Litestar's session middleware makes when the response starts) run on that session and do not take a second connection, so a one-connection pool cannot deadlock on its own session writes. This holds however the request session is resolved: through db_session injection, inside a group of sibling dependencies, or from a sync handler running in a worker thread. No extra configuration is needed.
How the write commits depends on the commit mode:
autocommitandautocommit_include_redirect: the write joins the request's transaction. It commits with a successful response and rolls back with an error response or an unhandled exception, including on adapters whose connections autocommit by default (such as asyncpg, psqlpy, and DuckDB).manual: if the handler left uncommitted work open, the write joins it and rolls back with it when the request ends. If no transaction is open (for example, because the handler already committed), the store begins its own transaction on the request session and commits the write immediately.
If a request fails after it has released its database session, later session writes from that request are rolled back.
A store call made outside a request, such as from startup code or a CLI command, opens its own short session and commits itself. So do calls from tasks the request spawns (for example, with asyncio.create_task), calls made after a successful request has released its session, and stores bound to a different configuration. These writes are independent of the request's outcome. The BigQuery and Spanner stores always open their own session.
SQL Server, Oracle, and Arrow ODBC session stores accept schema-qualified session_table names (such as "auth.litestar_session", "[auth].[litestar_session]", or "APP.litestar_session"). The schema must already exist.
session_table (True or a custom table name) is still required to include Litestar session migrations (migration_mode="reconcile" is the default). Reconciliation converges the session table on every litestar db upgrade or sqlspec upgrade without recording new ext_litestar_* rows, preserves the table during partial downgrades, and drops it when downgrade reaches base while honoring manage_schema and create_schema (see Migrations):
| Adapter Family | Built-In Adapters | Reconcile Scope and Boundaries |
|---|---|---|
| Embedded, OLTP, and Enterprise | sqlite, aiosqlite, asyncpg, psycopg, psqlpy, cockroach_asyncpg, cockroach_psycopg, aiomysql, asyncmy, pymysql, mysqlconnector, duckdb, mssql_python, pymssql, oracledb, db2, sqlanywhere, sybase, teradata |
Creates missing session tables, adds safe missing nullable or defaulted columns, and converges the companion expires_at index (dbo-defaulted or schema-qualified on SQL Server and validated schema-qualified on Oracle). |
| Arrow ODBC | arrow_odbc (mssql, tsql, db2) |
Converges compound primary session and <table_name>_chunks tables and their companion expiry and chunk indexes across SQL Server and Db2 targets. |
| Cloud Spanner and BigQuery | spanner, bigquery |
Converges litestar_session tables and companion expiry indexes (spanner TTL/index DDL; bigquery nullable-only additive column repair on existing tables, refusing NOT NULL or defaulted column additions with MigrationError). |
| Multi-backend ADBC | adbc |
Converges session tables and companion expiry indexes across all ADBC backends with a resolved dialect. ADBC over FlightSQL needs an explicit statement_config dialect or gizmosql_backend. |
Litestar Channels Backend¶
SQLSpecChannelsBackend implements Litestar's ChannelsBackend on top of plugin.sqlspec.event_channel(config), allowing ChannelsPlugin to broadcast WebSocket and SSE messages through PostgreSQL LISTEN/NOTIFY, hybrid notify_queue, Oracle AQ, or portable poll_queue tables without a separate Redis broker:
from litestar import Litestar
from litestar.channels import ChannelsPlugin
from sqlspec.adapters.asyncpg import AsyncpgConfig
from sqlspec.extensions.litestar import SQLSpecChannelsBackend, SQLSpecPlugin
config = AsyncpgConfig(
connection_config={"dsn": "postgresql://localhost/app"},
extension_config={"events": {"backend": "notify_queue"}},
)
plugin = SQLSpecPlugin(config)
channels_backend = SQLSpecChannelsBackend(
plugin.sqlspec.event_channel(config),
channel_prefix="litestar",
poll_interval=0.2,
)
app = Litestar(
plugins=[
plugin,
ChannelsPlugin(backend=channels_backend, channels=["notifications"]),
]
)
Litestar CLI Commands — Registering SQLSpecPlugin mounts SQLSpec's migration commands under litestar db (aliased as litestar database) and adds a delete-expired maintenance command under Litestar's sessions CLI group:
Production Litestar and Dishka Architecture¶
In enterprise microservices, teams often combine Litestar's HTTP routing, OpenAPI documentation, and lifecycle management with Dishka's unified dependency container. To prevent conflicting dependency injection providers while allowing Litestar to manage database pool startup and teardown, configure SQLSpecPlugin with disable_di=True and manage_lifespan=True:
from collections.abc import AsyncIterator
import msgspec
from dishka import Provider, Scope, make_async_container, provide
from dishka.integrations.litestar import FromDishka, inject, setup_dishka
from litestar import Controller, Litestar, get
from sqlspec.adapters.asyncpg import AsyncpgConfig, AsyncpgDriver
from sqlspec.extensions.litestar import SQLSpecPlugin
class Account(msgspec.Struct):
id: int
name: str
class DatabaseProvider(Provider):
"""Provide request-scoped drivers from the shared database configuration."""
def __init__(self, config: AsyncpgConfig) -> None:
super().__init__()
self._config = config
@provide(scope=Scope.REQUEST)
async def provide_driver(self) -> AsyncIterator[AsyncpgDriver]:
async with self._config.provide_session() as session:
yield session
class AccountController(Controller):
path = "/accounts"
@get("/{account_id:int}")
@inject
async def get_account(
self, account_id: int, driver: FromDishka[AsyncpgDriver]
) -> Account:
return await driver.select_one(
"SELECT id, name FROM accounts WHERE id = :id",
id=account_id,
schema_type=Account,
)
def create_app() -> Litestar:
config = AsyncpgConfig(
connection_config={"dsn": "postgresql://localhost/app"},
extension_config={
"litestar": {"disable_di": True, "manage_lifespan": True}
},
)
container = make_async_container(DatabaseProvider(config))
app = Litestar(
route_handlers=[AccountController],
plugins=[SQLSpecPlugin(config)],
)
setup_dishka(container, app)
return app
Create the AsyncpgConfig once and pass that same instance to both SQLSpecPlugin(config) and DatabaseProvider(config) so Dishka sessions draw from the pool managed by Litestar's lifespan.
Recap¶
SQLSpecPluginmanages pool lifecycles, injectsdb_session/db_connection/db_pool, mapsNotFoundError(404) andIntegrityError(409), and registerslitestar dbandlitestar sessions delete-expiredCLI commands automatically.- Set
commit_mode,session_key,enable_correlation_middleware, andenable_sqlcommenter_middlewareinextension_config["litestar"](LitestarConfig). - When integrating with Dishka, set
disable_di=Trueandmanage_lifespan=Trueonextension_config["litestar"]. - See the Litestar Extension Reference for
SQLSpecPlugin,SQLSpecChannelsBackend,LitestarConfig, andFilterConfigsignatures.