plugins/litestar/skills/litestar-databases/SKILL.md
Build Litestar database architecture with SQLAlchemy and Piccolo ORM, including model/repository patterns, SQLAlchemy plugin selection, session lifecycle, transaction boundaries, and DTO/serialization controls. Use when implementing persistence layers, transaction handling, or ORM integration. Do not use for non-persistent in-memory workflows.
npx skillsauth add alti3/litestar-skills litestar-databasesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when persistence architecture and ORM integration are core to the task, especially SQLAlchemy plugin wiring or Piccolo DTO-based API flows.
SQLAlchemy or Piccolo) based on ecosystem and project constraints.SQLAlchemyPlugin vs SQLAlchemyInitPlugin + optional SQLAlchemySerializationPlugin).SQLAlchemyPlugin for most applications that need both app/session tooling and SQLAlchemy model serialization support.SQLAlchemyInitPlugin only when you need engine/session injection and lifecycle management but do not want automatic SQLAlchemy DTO serialization.SQLAlchemySerializationPlugin when you want automatic SQLAlchemy DTO generation for handler data and return annotations.SQLAlchemyPlugin.Litestar SQLAlchemy support includes built-in repository utilities and base model patterns:
SQLAlchemyAsyncRepository for async session workflows.UUIDBase, UUIDAuditBaseBigIntBase, BigIntAuditBaseImplementation expectations:
from litestar import Litestar
from litestar.plugins.sqlalchemy import SQLAlchemyAsyncConfig, SQLAlchemyPlugin
config = SQLAlchemyAsyncConfig(
connection_string="sqlite+aiosqlite:///app.sqlite",
create_all=True,
metadata=Base.metadata,
)
sqlalchemy = SQLAlchemyPlugin(config=config)
app = Litestar(route_handlers=[...], plugins=[sqlalchemy])
from litestar import Litestar
from litestar.plugins.sqlalchemy import (
SQLAlchemyAsyncConfig,
SQLAlchemyInitPlugin,
SQLAlchemySerializationPlugin,
)
config = SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///app.sqlite")
app = Litestar(
route_handlers=[...],
plugins=[SQLAlchemyInitPlugin(config=config), SQLAlchemySerializationPlugin()],
)
from litestar.plugins.sqlalchemy import SQLAlchemyPlugin, SQLAlchemySyncConfig
config = SQLAlchemySyncConfig(connection_string="sqlite:///app.sqlite")
plugin = SQLAlchemyPlugin(config=config)
SQLAlchemyInitPlugin provides:
before_send handler for request-lifecycle cleanup behavior.Design guidance:
SQLAlchemySerializationPlugin automatically creates SQLAlchemy DTO types for handler data and return annotations that use SQLAlchemy models (including collections), unless an explicit DTO is already provided.
Practical guidance:
Litestar supports Piccolo-centric API flows via PiccoloDTO.
Core pattern:
Table models.PiccoloDTO[Model] for request/response shaping.DTOConfig for partial updates and field exclusions.Example:
from litestar.contrib.piccolo import PiccoloDTO
from litestar.dto import DTOConfig
class PatchDTO(PiccoloDTO[Task]):
config = DTOConfig(exclude={"id"}, partial=True)
Piccolo implementation guidance:
litestar-dependency-injection for session provisioning patterns.litestar-dto and litestar-responses for safe transport shaping.litestar-testing for transactional test isolation.litestar-openapi to verify schema output after DTO/plugin changes.development
Build Litestar WebSocket endpoints with low-level websocket handlers, websocket listeners, websocket streams, dependency injection, custom websocket classes, transport-mode control, and graceful connection lifecycle handling. Use when implementing bidirectional real-time communication, reactive websocket message handling, or proactive server push over WebSockets. Do not use for server-side pub/sub fanout that is better expressed with channels alone.
tools
Test Litestar applications with TestClient, AsyncTestClient, create_test_client, websocket test helpers, dependency overrides, mocked dependencies, lifecycle-aware fixtures, and deterministic success and failure assertions. Use when adding or fixing Litestar test coverage, including exception contracts, override precedence, websocket behavior, event-bus side effects, or live-server-only response patterns. Do not use as a substitute for production observability or runtime debugging strategy.
development
Configure Litestar templating with `TemplateConfig`, Jinja/Mako/MiniJinja engines, file-or-string `Template` responses, request and CSRF-aware context, template callables, and custom engine integration. Use when implementing or fixing server-rendered HTML in Litestar. Do not use for static asset serving or pure JSON API endpoints.
development
Configure Litestar stores and the store registry for caching, server-side sessions, rate limiting, and other key-value state with explicit backend selection, bytes-safe data handling, TTL and renewal policy, namespacing, registry wiring, and lifecycle cleanup. Use when a Litestar app depends on `MemoryStore`, `FileStore`, `RedisStore`, `ValkeyStore`, or `StoreRegistry`. Do not use for relational persistence, domain repositories, or response-caching policy details that belong in database or caching-focused skills.