litestar-data-services

Implements Litestar service layers, repositories, filters, and pagination across SQLAlchemy and sqlspec stacks.

Updated Aug 17, 2026
One-click install
npx skills add https://github.com/renjianguo666/litecms --skill litestar-data-services-renjianguo666
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: litestar-data-services
Source: https://github.com/renjianguo666/litecms/tree/main/.agents/skills/litestar-data-services
Command: npx skills add https://github.com/renjianguo666/litecms --skill litestar-data-services-renjianguo666

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building data access in Litestar apps often leads to SQL leaking into route handlers, hand-rolled pagination parameters, and inconsistent repository patterns. This Skill enforces a clean service boundary with stack-appropriate filters, pagination envelopes, and DTO conversion. ## Core Features & Use Cases - Per-stack service patterns: Choose between advanced-alchemy's SQLAlchemyAsyncRepositoryService, sqlspec's SQLSpecAsyncService, or raw SQLAlchemy with async_sessionmaker based on the project's existing persistence stack. - Declarative filters and pagination: Use create_filter_dependencies and OffsetPagination for advanced-alchemy, or LimitOffsetFilter and OrderByFilter for sqlspec, instead of hand-rolled query params. - Use Case: When adding a paginated user listing endpoint, the Skill guides you to declare filter dependencies on the Controller, call list_and_count on the service, and return a typed OffsetPagination[User] envelope via to_schema. ## Quick Start Ask the AI to implement a Litestar CRUD service with filters and pagination for a given model using the project's existing data stack.

Frequently Asked Questions about litestar-data-services

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add pagination to a Litestar list endpoint?

With advanced-alchemy, declare create_filter_dependencies on the Controller, call list_and_count on the service, and return to_schema with the filters to get an OffsetPagination envelope. With sqlspec, inject LimitOffsetFilter and OrderByFilter and pass them to the driver call.

What is SQLAlchemyAsyncRepositoryService in advanced-alchemy?

SQLAlchemyAsyncRepositoryService is an opinionated async service base class providing CRUD methods like get, list_and_count, create, update, upsert, and to_schema. Subclass it and set repository_type to a SQLAlchemyAsyncRepository to get a full data-access surface without writing SELECT statements.

advanced-alchemy vs sqlspec: which should I use for Litestar services?

Use advanced-alchemy when you want an ORM repository service with audit fields, filters, and pagination built in. Use sqlspec when you want explicit SQL, 15+ database adapters, or Arrow-native result streams for analytics workloads.

Can I use create_filter_dependencies with raw SQLAlchemy?

No, create_filter_dependencies comes from advanced-alchemy's Litestar extension. With raw SQLAlchemy you must apply .limit() and .offset() on Core statements manually and compute totals with a separate count query.

When should I write hand-written SQL inside a repository service?

Drop to hand-written SQLAlchemy for multi-table aggregate joins, window functions, recursive CTEs, or vendor-specific features like Postgres JSONB operations. Keep the query inside the service class and never push raw SQL into Controllers.