Filter options

You can use the filtering feature to select what records a certain query will operate on. In order to define a filter, you need to use the appropriate filtering objects. They can be created using the exposed methods field and combineCriteriacombineCriteria is something very specific that provides another way to create nested logical conditions. The advantage of this system is that you are flexible in creating  very complex filters.

Example:

import { field } from "SDK location"
let simpleCriterion = field("username").isEqualTo("Tom");
let combinedCriteria = simpleCriterion.or(field("username").isEqualTo("Dick"));

In order to use these conditions, they need to be added to a query using the .where method

[..]
posts.select().where(field("username").isEqualTo("Harry"));
[..]

Multiple .where calls can be chained, but only the last call will be taken into account. If a complex condition needs to be set for filtering, it has to be created in one go (in-line or not) and passed as an argument to the .where method. 

Note: Be sure that isEqualTo doesn't get a null value as an argument. In this case, the dataset automatically casts this to isEqualTo(false) which ends up with "wrong" results. Use the methods isNull() and isNotNull() for the comparison with null.

Filtering conditions can be nested at any level.

[..]
let flatFilter = field("first_name").isEqualTo("Tom")
                 .or( field("first_name").isEqualTo("Dick"))
                 .or( field("first_name").isEqualTo("Harry"));

let nestedFilter = field("first_name").isEqualTo("Tom")
                   .or( field("first_name").isEqualTo("Dick")
                        .and( field("middle_name").isEqualTo("Harry")));

let anotherNestedFilter = field("first_name").isEqualTo("Tom")
                   .or( field("first_name").isEqualTo("Dick")
                        .and( field("middle_name").isEqualTo("Harry")
                              .or( field("middle_name").isEqualTo("Larry"))));
[..]

Advanced users:

You can find a complete list of the operators supported for filtering in the SDK API Reference.