View Source Supabase.PostgREST.FilterBuilder (supabase_postgrest v0.2.0)
Manages filtering logic for queries.
This module allows you to define conditions that restrict the data returned by the query. Filters can include equality checks, range conditions, pattern matching, and more. These operations translate into query parameters that control the subset of data fetched or manipulated.
Summary
Functions
Applies an "AND" condition to a query, allowing multiple conditions on different columns. This can also be scoped to a foreign table if specified.
Applies an "OR" condition to a query, combining multiple conditions on different columns where at least one condition must be met. This can also be scoped to a foreign table.
Only relevant for jsonb, array, and range columns. Match only rows where every element appearing in column is contained by value.
Only relevant for jsonb, array, and range columns. Match only rows where column contains every element appearing in value.
Match only rows where column is equal to value.
Match only rows which satisfy the filter. This is an escape hatch - you hould use the specific filter methods wherever possible.
Adds a 'greater than' filter to the query, specifying that the column's value must be greater than the specified value.
Adds a 'greater than or equal to' filter to the query, specifying that the column's value must be greater than or equal to the specified value.
Adds an 'ilike' filter to the query, allowing for case-insensitive pattern matching (SQL ILIKE).
Match only rows where column matches all of patterns case-insensitively.
Match only rows where column matches any of patterns case-insensitively.
Match only rows where column IS value.
Guard to validates if the filter operator passed to
__MODULE__.filter/3 is a valid operator.
Adds a 'like' filter to the query, allowing for simple pattern matching (SQL LIKE).
Match only rows where column matches all of patterns case-sensitively.
Match only rows where column matches any of patterns case-sensitively.
Adds a 'less than' filter to the query, specifying that the column's value must be less than the specified value.
Adds a 'less than or equal to' filter to the query, specifying that the column's value must be less than or equal to the specified value.
Match only rows where each column in query keys is equal to its associated value. Shorthand for multiple .eq()s.
Applies a "NOT" condition to the query, negating a specified condition.
Match only rows where column is not equal to value.
Only relevant for array and range columns. Match only rows where column and value have an element in common.
Only relevant for range columns. Match only rows where column is mutually exclusive to range and there can be no element between the two ranges.
Only relevant for range columns. Match only rows where every element in column is greater than any element in range.
Only relevant for range columns. Match only rows where every element in column is either contained in range or greater than any element in range.
Only relevant for range columns. Match only rows where every element in column is less than any element in range.
Only relevant for range columns. Match only rows where every element in column is either contained in range or less than any element in range.
Only relevant for text and tsvector columns. Match only rows where column matches the query string in query.
Filters the query by checking if the column's value is within an array of specified values.
Functions
Applies an "AND" condition to a query, allowing multiple conditions on different columns. This can also be scoped to a foreign table if specified.
Unlike most filters, filters is used as-is and needs to follow PostgREST syntax. You also need to make sure it's properly sanitized.
It's currently not possible to do an .and() filter across multiple tables.
You can optionally use the custom DSL to represent conditions instead of a raw string, look at the examples and the Supabase.PostgREST.FilterBuilder.Behaviour.condition() type spec.
Parameters
builder: The Builder instance.columns: A list of conditions that should all be met.opts: Optional parameters, which can include specifying a foreign table.
Examples
iex> PostgREST.all_of(builder, [{:gt, "age", 18}, {:eq, "status", "active"}])
iex> PostgREST.all_of([
iex> {:gt, "age", 18},
iex> {:and, [
iex> {:lt, "salary", 5000},
iex> {:eq, "role", "junior"}
iex> ]}
iex> ])See also
- Supabase logical operations: https://supabase.com/docs/reference/javascript/using-filters#logical-operators
Applies an "OR" condition to a query, combining multiple conditions on different columns where at least one condition must be met. This can also be scoped to a foreign table.
Unlike most filters, filters is used as-is and needs to follow PostgREST syntax. You also need to make sure it's properly sanitized.
It's currently not possible to do an .and() filter across multiple tables.
You can optionally use the custom DSL to represent conditions instead of a raw string, look at the examples and the Supabase.PostgREST.FilterBuilder.Behaviour.condition() type spec.
Parameters
builder: The Builder instance.columns: A list of conditions where at least one should be met.opts: Optional parameters, which can include specifying a foreign table.
Examples
iex> PostgREST.any_of(builder, [{:gt, "age", 18}, {:eq, "status", "active"}])
iex> PostgREST.any_of([
iex> {:gt, "age", 18},
iex> {:or, [
iex> {:eq, "status", "active"},
iex> {:eq, "status", "pending"}
iex> ]},
iex> ])See also
- Further details on logical operations in Supabase: https://supabase.com/docs/reference/javascript/using-filters#logical-operators
Only relevant for jsonb, array, and range columns. Match only rows where every element appearing in column is contained by value.
Parameters
builder: The Builder instance.column: The column to apply the filter.values: It can be a single value (string), a list of values to filter or a map (aka json)
Examples
iex> PostgREST.contained_by(builder, "tags", ["urgent", "new", "old"])See also
- Supabase contained by filter: https://supabase.com/docs/reference/javascript/using-filters#contained-by
Only relevant for jsonb, array, and range columns. Match only rows where column contains every element appearing in value.
Parameters
builder: The Builder instance.column: The column to apply the filter.values: It can be a single value (string), a list of values to filter or a map (aka json)
Examples
iex> PostgREST.contains(builder, "tags", ["urgent", "new"])See also
- Supabase contains filter: https://supabase.com/docs/reference/javascript/using-filters#contains
Match only rows where column is equal to value.
To check if the value of column is NULL, you should use .is() instead.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The value the column must equal, must implementString.Charsprotocol
Examples
iex> PostgREST.eq(builder, "id", 123)See also
- Supabase equality filters: https://supabase.com/docs/reference/javascript/using-filters#equality
Match only rows which satisfy the filter. This is an escape hatch - you hould use the specific filter methods wherever possible.
Unlike most filters, opearator and value are used as-is and need to
follow PostgREST syntax. You also need to make sure they are properly sanitized.
Parameters
column- The column to filter onoperator- The operator to filter with, following PostgREST syntaxvalue- The value to filter with, following PostgREST syntax, must implement theString.Charsprotocol
Examples
iex> PostgREST.filter(builder, "id", "not", 12)
Adds a 'greater than' filter to the query, specifying that the column's value must be greater than the specified value.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The value that the column must be greater than, must implement theString.Charsprotocol
Examples
iex> PostgREST.gt(builder, "age", 21)See also
- Supabase greater than filter: https://supabase.com/docs/reference/javascript/using-filters#greater-than
Adds a 'greater than or equal to' filter to the query, specifying that the column's value must be greater than or equal to the specified value.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The value that the column must be greater than or equal to, must implement theString.Charsprotocol
Examples
iex> PostgREST.gte(builder, "age", 21)See also
- Supabase greater than or equal filter: https://supabase.com/docs/reference/javascript/using-filters#greater-than-or-equal
Adds an 'ilike' filter to the query, allowing for case-insensitive pattern matching (SQL ILIKE).
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The pattern to match against the column's value, ignoring case, must implement theString.Charsprotocol
Examples
iex> PostgREST.ilike(builder, "name", "%john%")See also
- Supabase ilike filter: https://supabase.com/docs/reference/javascript/using-filters#ilike
Match only rows where column matches all of patterns case-insensitively.
Params
column: the column to apply the filtervalues: a list of patterns of filters (needs to implement theString.Charsprotocol)
Examples
iex> PostgREST.ilike_all_of(builder, "name", ["jhon", "maria", "joão"])
Match only rows where column matches any of patterns case-insensitively.
Params
column: the column to apply the filtervalues: a list of patterns of filters (needs to implement theString.Charsprotocol)
Examples
iex> PostgREST.ilike_any_of(builder, "name", ["jhon", "maria", "joão"])
Match only rows where column IS value.
For non-boolean columns, this is only relevant for checking if the value of
column is NULL by setting value to nil.
For boolean columns, you can also set value to true or false and it
will behave the same way as .eq().
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The value to check the column against (typically nil or a boolean).
Examples
iex> PostgREST.is(builder, "name", nil)See also
- Supabase is filter: https://supabase.com/docs/reference/javascript/using-filters#is
Guard to validates if the filter operator passed to
__MODULE__.filter/3 is a valid operator.
Adds a 'like' filter to the query, allowing for simple pattern matching (SQL LIKE).
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The pattern to match against the column's value, must implement theString.Charsprotocol
Examples
iex> PostgREST.like(builder, "name", "%John%")See also
- Supabase like filter: https://supabase.com/docs/reference/javascript/using-filters#like
Match only rows where column matches all of patterns case-sensitively.
Params
column: the column to apply the filtervalues: a list of patterns of filters (needs to implement theString.Charsprotocol)
Examples
iex> PostgREST.like_all_of(builder, "name", ["jhon", "maria", "joão"])
Match only rows where column matches any of patterns case-sensitively.
Params
column: the column to apply the filtervalues: a list of patterns of filters (needs to implement theString.Charsprotocol)
Examples
iex> PostgREST.like_any_of(builder, "name", ["jhon", "maria", "joão"])
Adds a 'less than' filter to the query, specifying that the column's value must be less than the specified value.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The value that the column must be less than, must implement theString.Charsprotocol
Examples
iex> PostgREST.lt(builder, "age", 65)See also
- Supabase less than filter: https://supabase.com/docs/reference/javascript/using-filters#less-than
Adds a 'less than or equal to' filter to the query, specifying that the column's value must be less than or equal to the specified value.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The value that the column must be less than or equal to, must implement theString.Charsprotocol
Examples
iex> PostgREST.lte(builder, "age", 65)See also
- Supabase less than or equal filter: https://supabase.com/docs/reference/javascript/using-filters#less-than-or-equal
Match only rows where each column in query keys is equal to its associated value. Shorthand for multiple .eq()s.
Parameters
query- The object to filter with, with column names as keys mapped to their filter values, and all values must implement theString.Charsprotocol
Examples
iex> PostgREST.match(builder, %{"col1" => true, "col2" => false})
See also
- Supabase ordering results: https://supabase.com/docs/reference/javascript/using-filters#match
Applies a "NOT" condition to the query, negating a specified condition.
Unlike most filters, opearator and value are used as-is and need to
follow PostgREST syntax. You also need
to make sure they are properly sanitized.
Parameters
builder: The Builder instance.column: The column to apply the negation.op: The operator used in the condition (e.g., "eq", "gt").value: The value to compare against, must implement theString.Charsprotocol
Examples
iex> PostgREST.not(builder, "status", "eq", "active")See also
- Supabase negation filters: https://supabase.com/docs/reference/javascript/using-filters#negation
Match only rows where column is not equal to value.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The value that the column must not equal, must implementString.Charsprotocol
Examples
iex> PostgREST.neq(builder, "status", "inactive")See also
- Supabase not equal filter: https://supabase.com/docs/reference/javascript/using-filters#not-equal
Only relevant for array and range columns. Match only rows where column and value have an element in common.
Parameters
builder: The Builder instance.column: The column to apply the filter.values: The array of values that must overlap with the column's value, all elements must implement theString.Charsprotocol
Examples
iex> PostgREST.overlaps(builder, "tags", ["urgent", "old"])See also
- Supabase overlaps filter: https://supabase.com/docs/reference/javascript/using-filters#overlaps
@spec process_condition(Supabase.PostgREST.FilterBuilder.Behaviour.condition()) :: String.t()
Only relevant for range columns. Match only rows where column is mutually exclusive to range and there can be no element between the two ranges.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The adjacent range value, must implement theString.Charsprotocol
Examples
iex> PostgREST.range_adjacent(builder, "scheduled_time", "2021-01-01T10:00:00Z/2021-01-01T12:00:00Z")See also
- Supabase adjacent range filters: https://supabase.com/docs/reference/javascript/using-filters#adjacent
Only relevant for range columns. Match only rows where every element in column is greater than any element in range.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The lower bound value of the range, must implement theString.Charsprotocol
Examples
iex> PostgREST.range_gt(builder, "age", 20)See also
- More on range filters at Supabase: https://supabase.com/docs/reference/javascript/using-filters#range
Only relevant for range columns. Match only rows where every element in column is either contained in range or greater than any element in range.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The starting value of the range, must implement theString.Charsprotocol
Examples
iex> PostgREST.range_gte(builder, "age", 18)See also
- Supabase documentation on range filters: https://supabase.com/docs/reference/javascript/using-filters#range
Only relevant for range columns. Match only rows where every element in column is less than any element in range.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The upper bound value of the range, must implement theString.Charsprotocol
Examples
iex> PostgREST.range_lt(builder, "age", 30)See also
- Supabase range filters: https://supabase.com/docs/reference/javascript/using-filters#range
Only relevant for range columns. Match only rows where every element in column is either contained in range or less than any element in range.
Parameters
builder: The Builder instance.column: The column to apply the filter.value: The ending value of the range, must implement theString.Charsprotocol
Examples
iex> PostgREST.range_lte(builder, "age", 65)See also
- Supabase guide on using range filters: https://supabase.com/docs/reference/javascript/using-filters#range
Only relevant for text and tsvector columns. Match only rows where column matches the query string in query.
Parameters
builder: The Builder instance.column: The column to search.query: The text query for the search.opts: Options for the search, such as type of search (:plain,:phrase, or:websearch) and configuration.
Examples
iex> PostgREST.text_search(builder, "description", "elixir supabase", type: :plain)See also
- Supabase full-text search capabilities: https://supabase.com/docs/reference/javascript/using-filters#full-text-search
Filters the query by checking if the column's value is within an array of specified values.
Parameters
builder: The Builder instance.column: The column to filter.values: A list of acceptable values for the column, all elements must implement theString.Charsprotocol
Examples
iex> PostgREST.in(builder, "status", ["active", "pending", "closed"])See also
- Supabase "IN" filters: https://supabase.com/docs/reference/javascript/using-filters#in