QueryBuilder class

The query builder is primarily used to build database queries or run CRUD operations on a model (i.e., table, collection) of your application.

There are several modifiers (e.g., filter, lookup, omit, sort, limit, page) that you can use to build your queries. For convenience, these modifiers can be chained to build complex queries. As an example, assuming that you have a userOrders model where you keep orders of your users, you can create the following query by chaining multiple modifiers to get the first 100 orders with basket size greater than 50 and sorted by orderDate descending.

var response = await client.db
   .model('userOrders')
   .filter('basketSize > 50')
   .sort('orderDate', 'desc')
   .limit(100)
   .page(1)
   .get();
Inheritance

Constructors

QueryBuilder(String modelName, Fetcher fetcher)
Creates an instance of QueryBuilder to run queries and CRUD operations on your app's database.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

append(dynamic values, String parentId, [bool returnTop = false]) Future<APIResponse>
Appends object(s) to a child-list of the parent object identified by parentId. This method ignores all query modifiers except omit. See table below for applicable modifiers that can be used with this method.
compute(dynamic computations) Future<APIResponse>
Runs the specified computation(s) on the model objects and returns the computation results. This method is typically chained with group and filter methods. See table below for applicable modifiers that can be used with this method.
create(Map<String, dynamic> values) Future<APIResponse<Map<String, dynamic>>>
Creates top level model object(s) in the database. This method ignores all query modifiers except omit. See table below for applicable modifiers that can be used with this method.
createMany(List<Map<String, dynamic>> values) Future<APIResponse<List<Map<String, dynamic>>>>
Creates top level model objects in the database. This method ignores all query modifiers except omit. See table below for applicable modifiers that can be used with this method.
delete() Future<APIResponse<DeleteInfo>>
Deletes the objects matching the query. See table below for applicable modifiers that can be used with this method.
filter(String expression) QueryBuilder
Sets the query expression for selecting/filtering data from your app's database.
get([bool returnCountInfo = false]) Future<APIResponse>
Runs the query defined by the query modifiers and returns matching objects array. This method accepts all the query modifiers except group. See table below for applicable modifiers that can be used with this method.
getRandom(int count) Future<APIResponse<List<Map<String, dynamic>>>>
Retrieves the specified number of objects from the database randomly. See table below for applicable modifiers that can be used with this method.
getSingle() Future<APIResponse<Map<String, dynamic>>>
Runs the query defined by the query modifiers and returns the matching single object. If there are more than one object matching the query, it returns the first one. See table below for applicable modifiers that can be used with this method.
group(Object fieldsOrExpression) QueryBuilder
Groups the objects of the model by the specified expression or by the specified fields. This method is chained with the compute method to calculated group statistics of your models.
limit(int limitCount) QueryBuilder
Limits the max number of objects returned from the database, namely defines the page size for pagination. In combination with page, primarily used to paginate through your data. Even if you do not specify a limit in your database queries, Altogic automatically limits the number of objects returned from the database by setting the default limits.
lookup(Lookup lookup) QueryBuilder
Look up (left outer join) the specified field SimpleLookup of the model or perform specified lookup query ComplexLookup when getting data form the database
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
object([String? id]) DBObject
Gets a DBObject instance that refers to the object with the specified id.
omit(List<String> fields) QueryBuilder
Applies a field mask to the result and returns all the fields except the omitted ones.
page(int pageNumber) QueryBuilder
Paginates to the specified page number. In combination with limit, primarily used to paginate through your data.
searchFuzzy(String fieldName, String text) Future<APIResponse<List<Map<String, dynamic>>>>
Retrieves a list of objects from the database running the full-text (fuzzy) search on the specified field, which must be covered by a full-text search index. If filter is specified it applies the filter query to further narrow down the results. The retrieved objects are sorted automatically in terms of the scores of the full-text search results. See table below for applicable modifiers that can be used with this method.
searchText(String text, [bool returnCountInfo = false]) Future<APIResponse<List<Map<String, dynamic>>>>
Retrieves a list of objects from the database running the text search. It performs a logical OR search of the terms unless specified as a phrase between double-quotes. If filter is specified it applies the filter query to further narrow down the results. The retrieved objects are sorted automatically in terms of the scores of the text search results. See table below for applicable modifiers that can be used with this method.
set(Map<String, dynamic> values, String parentId, [bool returnTop = false]) Future<APIResponse<Map<String, dynamic>>>
Sets the sub-object field value of the parent object identified by parentId. This method ignores all query modifiers except omit. See table below for applicable modifiers that can be used with this method.
sort(String fieldName, Direction sortDirection) QueryBuilder
Sorts the returned objects by the value of the specified field and sort direction
toString() String
A string representation of this object.
inherited
update(Map<String, dynamic> values) Future<APIResponse<UpdateInfo>>
Updates the objects matching the query using the input values. This method directly sets the field values of the objects in the database with the values provided in the input. See table below for applicable modifiers that can be used with this method.
updateFields(dynamic fieldUpdates) Future<APIResponse<UpdateInfo>>
Updates the objects matching the query using the input FieldUpdate instruction(s). See table below for applicable modifiers that can be used with this method.

Operators

operator ==(Object other) bool
The equality operator.
inherited