Flutter

Parse Query Cookbook in Flutter

Introduction

We’ve already seen how a QueryBuilder with get can retrieve a single ParseObject from Back4App. There are many other ways to retrieve data with QueryBuilder - you can retrieve many objects at once, use conditions on the objects you wish to retrieve, and more.

In this guide, you will ding deep into the QueryBuilder class and see all the methods you can use to build your Queries. You will use a simple database class with some mocked data to perform the Queries using Flutter on Back4App.

Prerequisites

To complete this tutorial, you will need:

Goal

Explore the QueryBuilder class different methods.

The QueryBuilder class

Any Parse query operation uses the QueryBuilder object type, which will help you retrieve specific data from your database throughout your app.

To create a new QueryBuilder, you need to pass as a parameter the desired ParseObject subclass, which is the one that will contain your query results.

It is crucial to know that a QueryBuilder will only resolve after calling a retrieve method query, so a query can be set up and several modifiers can be chained before actually being called.

You can read more about the QueryBuilder class here at the official documentation.

Using the JavaScript Console on Back4App

Inside your Back4App application’s dashboard, you will find a very useful API console in which you can run JavaScript code directly. In this guide you will use to store data objects in Back4App. On your App main dashboard go to Core->API Console->Javascript.

Flutter Back4App

Save your Data Objects

To run the queries on this guide you’ll need first to populate your App with some data. Let’s create a sample class called Profile, which mocks a social media profile class using famous people names and the following fields:

  • string type name;
  • Date type birthDay;
  • Number (integer) type friendCount;
  • Array (string list) type favoriteFoods;
  • Array (Number list) type luckyNumbers;
  • GeoPoint type lastLoginLocation;

Here is the Parse.Object classes creation code, so go ahead and run it in your API console:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Add Profile objects and create table
// Adam Sandler
let Profile = new Parse.Object('Profile');
Profile.set('name', 'Adam Sandler');
Profile.set('birthDay', new Date('09/09/1966'));
Profile.set('friendCount', 2);
Profile.set('favoriteFoods', ['Lobster', 'Bread']);
Profile.set('luckyNumbers', [2, 7]);
Profile.set('lastLoginLocation', new Parse.GeoPoint(37.38412167489413, -122.01268034622319));
await Profile.save();

// Britney Spears
Profile = new Parse.Object('Profile');
Profile.set('name', 'Britney Spears');
Profile.set('birthDay', new Date('12/02/1981'));
Profile.set('friendCount', 52);
Profile.set('favoriteFoods', ['Cake', 'Bread']);
Profile.set('luckyNumbers', [22, 7]);
Profile.set('lastLoginLocation', new Parse.GeoPoint(37.38412167489413, -122.01268034622319));
await Profile.save();

// Carson Kressley
Profile = new Parse.Object('Profile');
Profile.set('name', 'Carson Kressley');
Profile.set('birthDay', new Date('11/11/1969'));
Profile.set('friendCount', 12);
Profile.set('favoriteFoods', ['Fish', 'Cookies']);
Profile.set('luckyNumbers', [8, 2]);
Profile.set('lastLoginLocation', new Parse.GeoPoint(37.38412167489413, -122.01268034622319));
await Profile.save();

// Dan Aykroyd
// Creates related object Membership for this user only
let Membership = new Parse.Object('Membership');
Membership.set('name', 'Premium');
Membership.set('expirationDate', new Date('10/10/2030'))
await Membership.save();

Profile = new Parse.Object('Profile');
Profile.set('name', 'Dan Aykroyd');
Profile.set('birthDay', new Date('07/01/1952'));
Profile.set('friendCount', 66);
Profile.set('favoriteFoods', ['Jam', 'Peanut Butter']);
Profile.set('luckyNumbers', [22, 77]);
Profile.set('lastLoginLocation', new Parse.GeoPoint(37.38412167489413, -122.01268034622319));
Profile.set('premiumMembership', Membership);
await Profile.save();

// Eddie Murphy
Profile = new Parse.Object('Profile');
Profile.set('name', 'Eddie Murphy');
Profile.set('birthDay', new Date('04/03/1961'));
Profile.set('friendCount', 49);
Profile.set('favoriteFoods', ['Lettuce', 'Pepper']);
Profile.set('luckyNumbers', [6, 5]);
Profile.set('lastLoginLocation', new Parse.GeoPoint(-27.104919974838154, -52.61428045237739));
await Profile.save();

// Fergie
Profile = new Parse.Object('Profile');
Profile.set('name', 'Fergie');
Profile.set('birthDay', new Date('03/27/1975'));
Profile.set('friendCount', 55);
Profile.set('favoriteFoods', ['Lobster', 'Shrimp']);
Profile.set('luckyNumbers', [13, 7]);
Profile.set('lastLoginLocation', new Parse.GeoPoint(-27.104919974838154, -52.61428045237739));
await Profile.save();

console.log('Success!');

After running this code, you should now have a Profile class in your database with six objects created. Your new class should look like this:

Fluuter Back4App

Let’s now take a look at examples from every QueryBuilder method, along with brief explanations on what they do. Please note that some methods in this list can take options as an additional argument, but in most cases, it is only related to masterKey usage and not relevant to this guide content, so this possibility will be omitted whenever not relevant.

Query retrievers

These methods are responsible for running the query and retrieving its results, being always present in your query implementation.

Retrieves the count of ParseObject results that meet the query criteria.

1
2
3
4
5
6
7
8
QueryBuilder<ParseObject> queryBuilder = QueryBuilder<ParseObject>(ParseObject('Profile'));
var apiResponse = await queryPlayers.count();
if (apiResponse.success && apiResponse.result != null) {
  int countGames = apiResponse.count;
}
let query = new QueryBuilder('Profile');
let queryResult = await query.count();
console.log(queryResult);

This quick method is used to retrieve a single ParseObject instance when you know its objectId.

1
2
3
4
5
6
7
8
9
10
///To retrieve one object of a Class it is not necessary to create a ParseQuery.
///We can query using ParseObject
final apiResponse = await ParseObject('Profile').get('C6ENdLnFdQ');

if (apiResponse.success && apiResponse.results != null) {
  for (var o in apiResponse.results) {
    final object = o as ParseObject;
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Retrieves a complete list of ParseObjects.

1
2
3
4
5
6
7
8
9
10
///To retrieve all objects of a Class it is not necessary to create a ParseQuery.
///We can query using ParseObject
final apiResponse = await ParseObject('Profile').getAll();

if (apiResponse.success && apiResponse.results != null) {
  for (var o in apiResponse.results) {
    final object = o as ParseObject;
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

This is the basic method for retrieving your query results, always returning an list of ParseObject instances, being empty when none are found.

1
2
3
4
5
6
7
8
9
10
11
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
// When using .query() in a query without other operations, you will
// get every object saved in your class
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var o in apiResponse.results) {
    final object = o as ParseObject;
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Query conditioners

These methods give you the possibility of applying conditional constraints to your query, which are arguably the most important operations in querying.

Remember that these operations can all be chained before the results are retrieved, so many combinations can be achieved to solve your querying needs.

Requires that a key’s value does not match a value in an object returned by a different Parse.Query. Useful for multi-object querying.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereDoesNotMatchKeyInQuery(
  'friendCount',
  'friendCount',
  QueryBuilder<ParseObject>(ParseObject('Profile'))
  ..whereLessThan('friendCount', 50));
parseQuery.whereGreaterThan('friendCount', 10);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')} - friendCount: ${object.get<int>('friendCount')}');
  }
}

Filters objects in which an array type key value must contain every value provided.

1
2
3
4
5
6
7
8
9
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereArrayContainsAll('luckyNumbers', [2, 7]);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a key value is contained in the provided array of values.

1
2
3
4
5
6
7
8
9
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereContainedIn('luckyNumbers', [2, 7]);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a string key value contains the provided text value. Be aware that this condition is case-sensitive.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
// This can be slow in large databases
parseQuery.whereContains('name', 'an');
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Requires that an object contained in the given key does not match another query. Useful for multi-object querying.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
final QueryBuilder<ParseObject> innerQuery = QueryBuilder<ParseObject>(ParseObject('Membership'));
innerQuery.whereGreaterThan('expirationDate', DateTime.now());

final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereDoesNotMatchQuery('premiumMembership', innerQuery);

final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')}');
  }
}

Filters objects where specific key’s value ends with value.

1
2
3
4
5
6
7
8
9
10
11
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereEndsWith('name', 'ie');
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var o in apiResponse.results) {
    final object = o as ParseObject;
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a specific key’s value is equal to the provided value.

1
2
3
4
5
6
7
8
9
10
11
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereEqualTo('friendCount', 2);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var o in apiResponse.results) {
    final object = o as ParseObject;
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a specific key’s value is greater than the provided value.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereGreaterThan('birthDay', DateTime(1980, 08, 19));
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a specific key’s value is greater than or equal to the provided value.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereGreaterThanOrEqualsTo('friendCount', 49);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a specific key’s value is lesser than the provided value.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereLessThan('birthDay', DateTime(1980, 08, 19));
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a specific key’s value is lesser than or equal to the provided value.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereLessThanOrEqualTo('friendCount', 49);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Requires that a key’s value matches a value in an object returned by a different Parse.Query. Useful for multi-object querying.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereMatchesKeyInQuery(
  'friendCount',
  'friendCount',
  QueryBuilder<ParseObject>(ParseObject('Profile'))
  ..whereLessThan('friendCount', 50));
  
final apiResponse = await parseQuery.query();
  
if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')} - friendCount: ${object.get<int>('friendCount')}');
  }
}

Requires that an object contained in the given key matches another query. Useful for multi-object querying.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
final QueryBuilder<ParseObject> innerQuery = QueryBuilder<ParseObject>(ParseObject('Membership'));
innerQuery.whereGreaterThan('expirationDate', DateTime.now());

final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereValueExists('premiumMembership', true);
parseQuery.whereMatchesQuery('premiumMembership', innerQuery);

final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')}');
  }
}

Filters objects in which a key value is not contained in the provided array of values.

1
2
3
4
5
6
7
8
9
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereNotContainedIn('luckyNumbers', [2, 7]);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects where specific key’s value starts with value.

1
2
3
4
5
6
7
8
9
10
11
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereStartsWith('name', 'Adam');
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var o in apiResponse.results) {
    final object = o as ParseObject;
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a specific key’s value is not equal to the provided value.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));

parseQuery.whereNotEqualTo('friendCount', 2);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Filters objects in which a key value is set or no.

1
2
3
4
5
6
7
8
9
10
11
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
//true - retrieve documents with field set
//false - retrieve documents without field set
parseQuery.whereValueExists('premiumMembership', true);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Query ordering

Essential in most queries, ordering can be easily achieved in Parse and even chained between two or more ordering constraints.

Sort the results in ascending order, this can be chained without overwriting previous orderings. Multiple keys can be used to solve ordering ties.

1
2
3
4
5
6
7
8
9
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.orderByAscending('name');
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Sort the results in descending order, this can be chained without overwriting previous orderings. Multiple keys can be used to solve ordering ties.

1
2
3
4
5
6
7
8
9
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.orderByDescending('name');
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - ${object.get<String>('name')}');
  }
}

Field selecting

These methods affect which field values can be in your query results.

Return all fields in the returned objects except the ones specified.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.excludeKeys(['name']);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    //Name = null
    print('${object.objectId} - Name: ${object.get<String>('name')} - Birthday: ${object.get<DateTime>('birthDay')}');
  }
}

Includes nested ParseObjects for the provided key.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.includeObject(['premiumMembership']);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    //Name = null
    print('${object.objectId} - Name: ${object.get<String>('name')} - premiumMembership: ${object.get<ParseObject>('premiumMembership').toString()}');
  }
}

Return only the specified fields in the returned objects.

1
2
3
4
5
6
7
8
9
10
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.keysToReturn(['name']);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    //Birthday = null
    print('${object.objectId} - Name: ${object.get<String>('name')} - Birthday: ${object.get<DateTime>('birthDay')}');
  }
}

Geopoint querying

These are methods specific to GeoPoint querying.

1
2
3
4
5
6
7
8
9
10
11
12
13
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereNear(
  'lastLoginLocation',
  ParseGeoPoint(latitude: 37.38412167489413, longitude: -122.01268034622319)
);

final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')} - GeoPoint: ${object.get<ParseGeoPoint>('lastLoginLocation').toJson()}');
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereWithinGeoBox(
  'lastLoginLocation',
  ParseGeoPoint(latitude: 37.38412167489413, longitude: -122.01268034622319),
  ParseGeoPoint(latitude: 37.28412167489413, longitude: -121.91268034622319)
);
  
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')} - GeoPoint: ${object.get<ParseGeoPoint>('lastLoginLocation').toJson()}');
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereWithinKilometers(
  'lastLoginLocation',
  ParseGeoPoint(latitude: 37.38412167489413, longitude: -122.01268034622319),
  100
);

final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')} - GeoPoint: ${object.get<ParseGeoPoint>('lastLoginLocation').toJson()}');
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereWithinMiles(
  'lastLoginLocation',
  ParseGeoPoint(latitude: 37.38412167489413, longitude: -122.01268034622319),
  100
);

final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')} - GeoPoint: ${object.get<ParseGeoPoint>('lastLoginLocation').toJson()}');
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.whereWithinRadians(
  'lastLoginLocation',
  ParseGeoPoint(latitude: 37.38412167489413, longitude: -122.01268034622319),
  100
);

final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')} - GeoPoint: ${object.get<ParseGeoPoint>('lastLoginLocation').toJson()}');
  }
}

Pagination

These methods are related to pagination utilities, useful for queries that will retrieve a large number of results.

1
2
3
4
5
6
7
8
9
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.setAmountToSkip(2);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')}');
  }
}
1
2
3
4
5
6
7
8
9
final QueryBuilder<ParseObject> parseQuery = QueryBuilder<ParseObject>(ParseObject('Profile'));
parseQuery.setLimit(2);
final apiResponse = await parseQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')}');
  }
}

Compound query

These method will create compound queries, which can combine more than one ParseQuery instance to achieve more complex results.

Compose a compound query that is the OR of the passed queries.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
final QueryBuilder<ParseObject> query1 = QueryBuilder<ParseObject>(ParseObject('Profile'));
query1.whereGreaterThan('friendCount', 10);

final QueryBuilder<ParseObject> query2 = QueryBuilder<ParseObject>(ParseObject('Profile'));
query2.whereLessThan('friendCount', 50);

QueryBuilder<ParseObject> mainQuery = QueryBuilder.or(
  ParseObject("Profile"),
  [query1, query2],
);

final apiResponse = await mainQuery.query();

if (apiResponse.success && apiResponse.results != null) {
  for (var object in apiResponse.results as List<ParseObject>) {
    print('${object.objectId} - Name: ${object.get<String>('name')}');
  }
}

Conclusion

At the end of this guide, you learned how to perform every data query method in Parse. In the next guide, you will learn about complex Parse querying in Flutter.