Schema-aware OData filter builder.
Translates snake_case Elixir field names to camelCase API field names
using schema module field mappings, and builds valid OData $filter expressions.
Simple keyword syntax
For equality conditions combined with and:
OData.new()
|> OData.filter(User, department: "Engineering", account_enabled: true)
# => $filter=department eq 'Engineering' and accountEnabled eq trueBuilder syntax
For complex filters with different operators:
alias GraphApi.OData.Filter
filter =
Filter.new(User)
|> Filter.where(:display_name, :starts_with, "A")
|> Filter.where(:account_enabled, :eq, true)
|> Filter.or_where(:department, :eq, "Sales")
OData.new() |> OData.filter(filter)Supported operators
:eq,:ne— equality / inequality:gt,:lt,:ge,:le— comparison:starts_with,:ends_with,:contains— string functions:in— collection membership:is_nil— null check (usetrueforeq null,falseforne null)
Summary
Functions
Builds a filter string from simple keyword conditions (all AND-ed with eq).
Creates a new filter builder for the given schema module.
Adds an OR condition to the filter.
Converts the filter builder to an OData filter string.
Adds an AND condition to the filter.
Types
Functions
Builds a filter string from simple keyword conditions (all AND-ed with eq).
Used by OData.filter/3. Each key is a snake_case field name, each value
is compared with eq.
Examples
Filter.from_keywords(User, department: "Engineering", account_enabled: true)
#=> "department eq 'Engineering' and accountEnabled eq true"
Creates a new filter builder for the given schema module.
Adds an OR condition to the filter.
Examples
Filter.new(User)
|> Filter.where(:department, :eq, "Engineering")
|> Filter.or_where(:department, :eq, "Sales")
Converts the filter builder to an OData filter string.
Examples
Filter.new(User)
|> Filter.where(:display_name, :starts_with, "A")
|> Filter.where(:account_enabled, :eq, true)
|> Filter.to_string()
#=> "startsWith(displayName,'A') and accountEnabled eq true"
Adds an AND condition to the filter.
Examples
Filter.new(User)
|> Filter.where(:display_name, :eq, "Alice")
|> Filter.where(:account_enabled, :eq, true)