Welcome to Xano, the no-code platform that empowers you to build and deploy backend services without writing a single line of code. In this guide, we'll take a deep dive into the comparison filters available in Xano, which are essential for comparing values, validating data types, and building robust conditional logic within your applications.
The bitwise not filter allows you to flip the binary representation of a value. It takes the ones and turns them into zeros, and the zeros into ones. Here's how to use it:
{% set original_value = 9999 %}
{% set bitwise_not_value = original_value|bitwise_not %}
{{ original_value|sprintf('%b') }} {# Original binary value #}
{{ bitwise_not_value|sprintf('%b') }} {# Bitwise not binary value #}
Note that trailing zeros in the binary representation are not displayed.
The `equals` filter returns a boolean value (true or false) based on whether two values are equal.
{% set value1 = 50 %}
{% set value2 = 50 %}
{{ value1 == value2 }} {# Returns true #}
The `even` and `odd` filters check if a value is even or odd, respectively, and return a boolean.
{% set even_value = 42 %}
{% set odd_value = 15 %}
{{ even_value|even }} {# Returns true #}
{{ odd_value|odd }} {# Returns true #}
Xano offers several filters for comparing values, including `greater`, `greater_or_equal`, `less`, and `less_or_equal`. These filters return a boolean value based on whether the left value is greater than, greater than or equal to, less than, or less than or equal to the right value specified in the filter.
{% set left_value = 33 %}
{{ left_value|greater(55) }} {# Returns false #}
{{ left_value|greater_or_equal(33) }} {# Returns true #}
{{ left_value|less(20) }} {# Returns false #}
{{ left_value|less_or_equal(33) }} {# Returns true #}
The `in` filter checks if a value exists in an array and returns a boolean.
{% set numbers = [1, 2, 3] %}
{{ 2|in(numbers) }} {# Returns true #}
{{ 5|in(numbers) }} {# Returns false #}
Xano provides a set of filters for validating the data type of a value. These filters include `is_array`, `is_boolean`, `is_decimal`, `is_empty`, `is_integer`, `is_null`, `is_object`, and `is_text`. They all return a boolean indicating whether the value matches the specified data type.
{% set my_array = [1, 2, 3] %}
{% set my_object = { 'name': 'John', 'age': 30 } %}
{{ my_array|is_array }} {# Returns true #}
{{ my_object|is_object }} {# Returns true #}
{{ 42|is_integer }} {# Returns true #}
The `not` filter returns the opposite boolean value of the given value.
{% set value = true %}
{{ value|not }} {# Returns false #}
The `not_equals` filter returns a boolean based on whether two values are not equal.
{% set value1 = 25 %}
{% set value2 = 50 %}
{{ value1 != value2 }} {# Returns true #}
The `between` filter is particularly useful when querying database tables. It allows you to determine whether a value in the table falls between a specified left and right value.
sql
SELECT * FROM users WHERE age BETWEEN 18 AND 65;
In Xano, you can apply the `between` filter to a custom query:
{% set left_value = 10 %}
{% set right_value = 80 %}
{% set match = true %} {# Set to false to return non-matching records #}
{% set query %}
SELECT * FROM my_table
WHERE my_column BETWEEN {{ left_value }} AND {{ right_value }}
{% if match %}
AND 1 = 1
{% else %}
AND 1 = 0
{% endif %}
{% endset %}
{{ query|sql("my_database") }}
This query will return records where the value of `my_column` is between 10 and 80.
Xano's comparison filters are powerful tools that enable you to build robust conditional logic and validate data within your applications. Whether you're a no-code enthusiast, citizen developer, traditional developer, or part of a startup or small business, these filters can help you achieve your goals more efficiently.
Remember, you can always visit the Xano community at community.xano.com or reach out to our support team for further assistance.
Happy building!
This transcript was AI generated to allow users to quickly answer technical questions about Xano.
I found it helpful
I need more support