Skip to content

Conversation

@cofin
Copy link
Member

@cofin cofin commented Dec 15, 2025

Summary

Add NullFilter and NotNullFilter classes for filtering database queries where columns are NULL or NOT NULL, with full framework integration for FastAPI and Litestar.

The Problem

Users need to filter database queries for records where a column IS NULL or IS NOT NULL. While the builder API had where_is_null() and where_is_not_null() methods, there were no corresponding filter classes for use with the framework providers, and no convenient aliases matching common SQL builder conventions.

The Solution

  • Add NullFilter and NotNullFilter classes to sqlspec/core/filters.py
  • Export both from sqlspec/core/__init__.py
  • Add null_fields and not_null_fields config options to FastAPI and Litestar providers
  • Add where_null() and where_not_null() builder aliases for consistency

Key Features

  • NullFilter: Generates WHERE column IS NULL clauses
  • NotNullFilter: Generates WHERE column IS NOT NULL clauses
  • FastAPI/Litestar Integration: Configure via null_fields and not_null_fields in FilterConfig
  • Builder Aliases: where_null() and where_not_null() for consistency with other builders
  • Zero-parameter Pattern: No bind values needed (IS NULL takes no arguments)

Add NullFilter and NotNullFilter classes for filtering database queries
where columns are NULL or NOT NULL, with framework integration for
FastAPI and Litestar.

- NullFilter generates WHERE column IS NULL clauses
- NotNullFilter generates WHERE column IS NOT NULL clauses
- FastAPI/Litestar providers support via null_fields/not_null_fields config
- Builder API adds where_null() and where_not_null() aliases
- 13 comprehensive unit tests added
Remove where_null and where_not_null aliases since where_is_null
and where_is_not_null already exist in the builder API.
@cofin cofin merged commit daca7b2 into main Dec 15, 2025
9 of 10 checks passed
@cofin cofin deleted the feat/null-filter branch December 15, 2025 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants