Search And Data Processing

Comparison Filters in Xano: Complete Walkthrough

Summary

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.

Bitwise Not Filter

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:

  1. Create two variables, one for the original value and one for the bitwise not value.
  2. Apply the `bitwise_not` filter to the second variable.
  3. Use the `sprintf` filter with the `%b` format to display the binary representation of both variables.

{% 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.

Equality Filters

Equals Filter

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 #}

Even and Odd Filters

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 #}

Comparison Filters

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 #}

In Filter

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 #}

Data Type Validation Filters

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 #}

Not Filter

The `not` filter returns the opposite boolean value of the given value.

{% set value = true %} {{ value|not }} {# Returns false #}

Not Equals Filter

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 #}

Between Filter

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.

Conclusion

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.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team's progress and create a backend that will scale for free.

Start building for free