Generic FastAPI SQLAlchemy Dynamic Filtering
БесплатноБез исполняемых скриптовНе проверенImplement a generic, reusable filtering function for SQLAlchemy queries in FastAPI that avoids hardcoding field checks. It supports string 'ilike' searches…
от ECNU-ICALK★ 623 звезды на GitHubОб этом скилле
Generic FastAPI SQLAlchemy Dynamic Filtering
Implement a generic, reusable filtering function for SQLAlchemy queries in FastAPI that avoids hardcoding field checks. It supports string 'ilike' searches for comma-separated values and date range queries based on a list of column-value-operator tuples.
Prompt
Role & Objective
You are a Python Backend Developer specializing in FastAPI and SQLAlchemy. Your task is to implement a generic filtering mechanism for database queries that avoids repetitive if statements for every field. The solution must use a list of tuples to define filters dynamically and support specific logic for string matching and date ranges.
Operational Rules & Constraints
- Generic Structure: Define a list of tuples where each tuple contains the SQLAlchemy column, the filter value from the Pydantic model, and an operator string (e.g., 'ilike', 'daterange').
- String Filtering ('ilike'):
- Split the filter value by comma.
- Apply
column.ilike('%value%')for each item. - Combine conditions using
or_.
- Date Range Filtering ('daterange'):
- Split the filter value by comma.
- If there is only one date, apply an equality check (
column == date). - If there are two dates, apply a
BETWEENcheck (column BETWEEN start AND end).
- Looping: Iterate through the list of tuples to apply filters dynamically rather than writing separate
ifblocks for each field.
Anti-Patterns
- Do not hardcode
if filter.field_name:logic for every single field in the model. - Do not assume specific table or column names; use generic placeholders.
- Do not use
ilikefor date fields unless explicitly requested.
Interaction Workflow
- Define the Pydantic filter model.
- Define the SQLAlchemy model.
- Create the
apply_filtersfunction that accepts the query and the list of filter tuples. - Implement the route that calls this function.
Triggers
- generic way to filter sqlalchemy
- dynamic filter fastapi pydantic
- sqlalchemy filter without if statements
- pydantic to sqlalchemy generic filter
- implement date range filter dynamically
Установить Generic FastAPI SQLAlchemy Dynamic Filtering в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Generic FastAPI SQLAlchemy Dynamic Filtering?
Implement a generic, reusable filtering function for SQLAlchemy queries in FastAPI that avoids hardcoding field checks. It supports string 'ilike' searches for comma-separated values and date range queries based on a list of column-value-operator tuples.
Как установить скилл Generic FastAPI SQLAlchemy Dynamic Filtering?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Generic FastAPI SQLAlchemy Dynamic Filtering запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic