Skip to content

0.17.1

Choose a tag to compare

@igorbenav igorbenav released this 08 Oct 03:37
· 200 commits to main since this release
1be1561

0.17.1 Summary

Added

  • Multiple Values Support for OR/NOT Filters by @igorbenav
    • Enhanced __or and __not operators to accept lists of values for the same operator
    • Enables multiple LIKE patterns, equality checks, and other operators in single filter conditions
    • Fully backward compatible with existing filter syntax
    • Comprehensive test coverage for both SQLAlchemy and SQLModel

Fixed

  • Dictionary Key Duplication in Tests by @igorbenav
    • Fixed invalid Python syntax in test files where dictionary keys were duplicated
    • Updated existing tests to use new list syntax for multiple values
    • Resolved ruff linting errors in test suite

Improved

  • Filter Documentation Enhancement by @igorbenav
    • Updated advanced filters documentation with new list syntax examples
    • Added comprehensive usage patterns for multiple value filtering
    • Enhanced examples showing mixed list and single value usage

Breaking Changes

⚠️ None - This release maintains full backward compatibility with 0.17.x

Details


Multiple Values Support for OR/NOT Filters

Description

Enhanced the filtering system to support multiple values for the same operator within __or and __not conditions. This powerful feature enables more flexible and concise filtering patterns, particularly useful for search functionality and complex queries.

Changes

  • List Value Support: Accept lists of values for any operator in OR/NOT conditions
  • Mixed Syntax: Combine lists and single values within the same filter condition
  • Backward Compatibility: Existing single-value syntax continues to work unchanged
  • Performance Optimization: Generates efficient SQL with proper OR/AND logic

Usage Examples

Multiple LIKE Patterns (OR Logic):

# Find users with names starting with Alice, Frank, or Bob
result = await crud.get_multi(
    db,
    name__or={"like": ["Alice%", "Frank%", "Bob%"]}
)
# Generates: WHERE name LIKE 'Alice%' OR name LIKE 'Frank%' OR name LIKE 'Bob%'

Multiple Equality Checks:

# Find items with specific IDs
result = await crud.get_multi(
    db,
    tier_id__or={"eq": [1, 3, 5]}
)
# Generates: WHERE tier_id = 1 OR tier_id = 3 OR tier_id = 5

Mixed List and Single Values:

# Combine multiple patterns with single conditions
result = await crud.get_multi(
    db,
    name__or={
        "like": ["Alice%", "Frank%"],  # Multiple patterns
        "startswith": "Bob",           # Single condition
        "endswith": "son"              # Single condition
    }
)
# Generates: WHERE name LIKE 'Alice%' OR name LIKE 'Frank%' 
#            OR name STARTSWITH 'Bob' OR name ENDSWITH 'son'

NOT Filtering with Multiple Values:

# Exclude multiple patterns
result = await crud.get_multi(
    db,
    name__not={"like": ["Test%", "Admin%", "System%"]}
)
# Generates: WHERE NOT (name LIKE 'Test%') AND NOT (name LIKE 'Admin%') 
#            AND NOT (name LIKE 'System%')

Case-Insensitive Searches:

# Search across multiple email domains
result = await crud.get_multi(
    db,
    email__or={"ilike": ["%gmail.com", "%yahoo.com", "%outlook.com"]}
)

Benefits

  • Cleaner Syntax: Reduce verbose filter definitions for multiple similar conditions
  • Better Performance: Single query with optimized OR/AND conditions instead of multiple queries
  • Enhanced Search: Perfect for implementing search functionality across multiple patterns
  • Type Safe: Full type checking and validation maintained
  • API Friendly: Clean REST API interface for complex filtering scenarios

Supported Operators

All existing filter operators now support list values in OR/NOT conditions:

  • Text Matching: like, ilike, startswith, endswith, contains
  • Comparison: eq, gt, lt, gte, lte, ne
  • Collections: in, not_in (for nested list scenarios)
  • Other: All existing operators maintain list support

Test Suite Improvements

Description

Fixed critical syntax errors in test files and enhanced test coverage for the new multiple values feature.

Changes

  • Syntax Fixes: Resolved duplicate dictionary key issues in test files
  • Enhanced Coverage: Added comprehensive tests for list value scenarios
  • Cross-Platform Testing: Ensured feature works consistently across SQLAlchemy and SQLModel
  • Regression Testing: Verified backward compatibility with existing filter patterns

Files Updated

  • tests/sqlalchemy/crud/test_get_multi.py - Fixed duplicate key syntax errors
  • tests/sqlmodel/crud/test_get_multi.py - Added missing OR/NOT filter tests
  • tests/sqlalchemy/crud/test_multiple_like_or.py - New comprehensive test suite
  • tests/sqlmodel/crud/test_multiple_like_or.py - SQLModel-specific test coverage

Issue Resolution

  • Fixed ruff linting errors caused by invalid Python dictionary syntax
  • Ensured consistent test coverage between SQLAlchemy and SQLModel implementations
  • Validated that new features work correctly in both ORM contexts

Documentation Enhancements

Description

Updated the advanced filtering documentation to include comprehensive examples and usage patterns for the new multiple values feature.

Changes

  • New Syntax Examples: Detailed examples of list usage in OR/NOT conditions
  • Mixed Usage Patterns: Show how to combine lists with single values
  • Real-World Scenarios: Practical examples for search and filtering use cases
  • Migration Guide: How to update existing code to take advantage of new features

Documentation Updates

  • docs/advanced/filters.md - Enhanced with new syntax examples
  • Updated code examples throughout to demonstrate list capabilities
  • Added performance considerations and best practices

What's Changed

Full Changelog: v0.17.0...v0.17.1