AIP-160 Filter Parser with SeaORM Support
A Rust implementation of Google AIP-160 filtering standard with SeaORM integration.
Features
- Full AIP-160 Support - Parse Google AIP-160 filter expressions
- Type Safe - Strongly typed AST and error handling
- Zero Boilerplate - No trait implementation required!
- Well Tested - Comprehensive test coverage
- SeaORM Integration - Convert filters directly to SeaORM conditions
Installation
[]
# Basic parsing only
= "0.1"
# With SeaORM support
= { = "0.1", = ["sea-orm"] }
Quick Start
Basic Parsing
use parse_filter;
SeaORM Integration with Automatic Type Conversion
use ;
use *;
async
✨ Zero-Config Automatic Type Conversion
The library automatically detects column types from your Entity and applies appropriate SQL casts!
No manual configuration needed - just pass your Entity type to to_condition():
// PostgreSQL with UUID - automatic casting!
// Just use string values - they're automatically cast to the right type!
let filter = parse_filter?;
let condition = filter.?; // Automatically casts to UUID!
find.filter.all.await?;
Supported automatic conversions:
String→UUID(for UUID columns)String→TIMESTAMP/TIMESTAMPTZ(for timestamp columns)String→DATE(for date columns)String→TIME(for time columns)String→ENUM(for PostgreSQL enum columns)Number→INTEGER/FLOAT(based on database column type)
The library reads your Entity's column definitions and generates the appropriate SQL CAST expressions automatically!
Supported Filter Syntax
Comparison Operators
| Operator | Description | Example |
|---|---|---|
= |
Equal | name = "John" |
!= |
Not equal | status != "inactive" |
> |
Greater than | age > 18 |
>= |
Greater than or equal | age >= 18 |
< |
Less than | age < 65 |
<= |
Less than or equal | age <= 65 |
: |
Contains/Has | email : "@gmail.com" |
Logical Operators
| Operator | Description | Example |
|---|---|---|
AND |
Logical AND | active = true AND age > 18 |
OR |
Logical OR | status = "active" OR status = "pending" |
NOT |
Logical NOT | NOT deleted = true |
( ) |
Grouping | (a = 1 OR a = 2) AND b = 3 |
Value Types
| Type | Example |
|---|---|
| String | "value" or 'value' |
| Number | 42, 3.14, -10, 1e5 |
| Boolean | true, false |
| Null | null |
💡 Example Filters
# Simple equality
name = "John Doe"
# Numeric comparison
age > 18 AND age < 65
# Multiple conditions
active = true AND age > 18 AND verified = true
# OR conditions
status = "active" OR status = "pending"
# Grouped expressions
(status = "active" OR status = "pending") AND age > 18
# Contains/substring matching
email : "@example.com"
# NOT operator
NOT deleted = true
# Complex query
(active = true OR status = "trial") AND age >= 18 AND email : "@company.com"
How It Works
The library automatically converts snake_case field names to PascalCase Column names:
"created_at" → Column::CreatedAt
"user_id" → Column::UserId
"is_active" → Column::IsActive
Architecture
┌─────────────┐
│ Filter Text │ "age > 18 AND active = true"
└──────┬──────┘
│ parse_filter()
▼
┌─────────────┐
│ AST │ Filter { expression: And(...) }
└──────┬──────┘
│ to_condition::<Column>()
▼
┌─────────────┐
│ Condition │ SeaORM Condition
└─────────────┘
Google AIP-160 Compliance
- ✅ Comparison operators (=, !=, <, <=, >, >=)
- ✅ Logical operators (AND, OR, NOT)
- ✅ Grouping with parentheses
- ✅ String, number, boolean, and null values
- ✅ Has/contains operator (:)
- ⚠️ Partial: Function calls (not yet implemented)
License
MIT or Apache-2.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.