Filtering Results
The filter() method in SQLiter supports various filter options to query records, and can be combined with other methods like order(), limit(), and offset() to build more complex queries:
result = db.select(User).filter(age__lte=30).limit(10).fetch_all()
It is possible to both add multiple filters in the same call, and to chain multiple filter calls together:
result = db.select(User).filter(age__gte=20, age__lte=30).fetch_all()
result = db.select(User).filter(age__gte=20).filter(age__lte=30).fetch_all()
Basic Filters
__eq: Equal to (default if no operator is specified)- Example:
name="John"orname__eq="John"
- Example:
Null Checks
__isnull: Is NULL- Example:
email__isnull=True
- Example:
__notnull: Is NOT NULL- Example:
email__notnull=True
- Example:
Comparison Operators
__lt: Less than- Example:
age__lt=30
- Example:
__lte: Less than or equal to- Example:
age__lte=30
- Example:
__gt: Greater than- Example:
age__gt=30
- Example:
__gte: Greater than or equal to- Example:
age__gte=30
- Example:
__ne: Not equal to- Example:
status__ne="inactive"
- Example:
List Operations
__in: In a list of values- Example:
status__in=["active", "pending"]
- Example:
__not_in: Not in a list of values- Example:
category__not_in=["archived", "deleted"]
- Example:
String Operations (Case-Sensitive)
__startswith: Starts with- Example:
name__startswith="A"
- Example:
__endswith: Ends with- Example:
email__endswith=".com"
- Example:
__contains: Contains- Example:
description__contains="important"
- Example:
String Operations (Case-Insensitive)
__istartswith: Starts with (case-insensitive)- Example:
name__istartswith="a"
- Example:
__iendswith: Ends with (case-insensitive)- Example:
email__iendswith=".COM"
- Example:
__icontains: Contains (case-insensitive)- Example:
description__icontains="IMPORTANT"
- Example: