firebase::database::Query

#include <query.h>

TheQuery class is used for reading data.

Summary

Listeners can be attached, which will be triggered when the data changes.

Inheritance

Direct Known Subclasses:firebase::database::DatabaseReference

Constructors and Destructors

Query()
Default constructor.
Query(constQuery & query)
Copy constructor.
Query(Query && query)
Move constructor.
~Query()
Required virtual destructor.

Public functions

AddChildListener(ChildListener *listener)
void
Adds a listener that will be called any time a child is added, removed, modified, or reordered.
AddValueListener(ValueListener *listener)
void
Adds a listener that will be called immediately and then again any time the data changes.
EndAt(Variant order_value)
Get aQuery constrained to nodes with the given sort value or lower.
EndAt(Variant order_value, const char *child_key)
Get aQuery constrained to nodes with the given sort value or lower, and the given key or lower.
EqualTo(Variant order_value)
Get aQuery constrained to nodes with the exact given sort value.
EqualTo(Variant order_value, const char *child_key)
Get aQuery constrained to nodes with the exact given sort value, and the exact given key.
GetReference() const
Gets aDatabaseReference corresponding to the given location.
GetValue()
Gets the value of the query for the given location a single time.
GetValueLastResult()
Gets the result of the most recent call toGetValue().
LimitToFirst(size_t limit)
Gets aQuery limited to only the first results.
LimitToLast(size_t limit)
Gets aQuery limited to only the last results.
OrderByChild(const char *path)
Gets a query in which child nodes are ordered by the values of the specified path.
OrderByChild(const std::string & path)
Gets a query in which child nodes are ordered by the values of the specified path.
OrderByKey()
Gets a query in which child nodes are ordered by their keys.
OrderByPriority()
Gets a query in which child nodes are ordered by their priority.
OrderByValue()
Create a query in which nodes are ordered by their value.
RemoveAllChildListeners()
void
Removes all child listeners that were added byAddChildListener().
RemoveAllValueListeners()
void
Removes all value listeners that were added withAddValueListener().
RemoveChildListener(ChildListener *listener)
void
Removes a listener that was previously added withAddChildListener().
RemoveValueListener(ValueListener *listener)
void
Removes a listener that was previously added withAddValueListener().
SetKeepSynchronized(bool keep_sync)
void
Sets whether this location's data should be kept in sync even if there are no active Listeners.
StartAt(Variant order_value)
Get aQuery constrained to nodes with the given sort value or higher.
StartAt(Variant order_value, const char *child_key)
Get aQuery constrained to nodes with the given sort value or higher, and the given key or higher.
is_valid() const
virtual bool
Returns true if this query is valid, false if it is not valid.
operator=(constQuery & query)
Copy assignment operator.
operator=(Query && query)
Move assignment operator.

Public functions

AddChildListener

voidAddChildListener(ChildListener*listener)

Adds a listener that will be called any time a child is added, removed, modified, or reordered.

Details
Parameters
listener
AChildListener instance, which must remain in memory until you remove the listener from theQuery.

AddValueListener

voidAddValueListener(ValueListener*listener)

Adds a listener that will be called immediately and then again any time the data changes.

Details
Parameters
listener
AValueListener instance, which must remain in memory until you remove the listener from theQuery.

EndAt

QueryEndAt(Variantorder_value)

Get aQuery constrained to nodes with the given sort value or lower.

This method is used to generate a reference to a limited view of the data at this location. TheQuery returned will only refer to child nodes with a value less than or equal to the given value, using the given OrderBy directive (or priority as default).

Details
Parameters
order_value
The highest sort value theQuery should refer to.
Returns
AQuery in this same location, filtering out child nodes that have a higher sort value or key than the sort value or key specified.

EndAt

QueryEndAt(Variantorder_value,constchar*child_key)

Get aQuery constrained to nodes with the given sort value or lower, and the given key or lower.

This method is used to generate a reference to a limited view of the data at this location. TheQuery returned will only refer to child nodes with a value less than or equal to the given value, using the given OrderBy directive (or priority as default), and additionally only child nodes with a key less than or equal to the given key.

Known issue This currently does not work properly on all platforms. Please useEndAt(Variant order_value) instead.

Details
Parameters
order_value
The highest sort value theQuery should include.
child_key
The highest key theQuery should include.
Returns
AQuery in this same location, filtering out child nodes that have a higher sort value than the sort value specified, or a higher key than the key specified.

EqualTo

QueryEqualTo(Variantorder_value)

Get aQuery constrained to nodes with the exact given sort value.

This method is used to create a query constrained to only return child nodes with the given value, using the given OrderBy directive (or priority as default).

Details
Parameters
order_value
The exact sort value theQuery should include.
Returns
AQuery in this same location, filtering out child nodes that have a different sort value than the sort value specified.

EqualTo

QueryEqualTo(Variantorder_value,constchar*child_key)

Get aQuery constrained to nodes with the exact given sort value, and the exact given key.

This method is used to create a query constrained to only return the child node with the given value, using the given OrderBy directive (or priority as default), and the given key. Note that there is at most one such child as child key names are unique.

Known issue This currently does not work properly on iOS, tvOS and desktop. Please useEqualTo(Variant order_value) instead.

Details
Parameters
order_value
The exact sort value theQuery should include.
child_key
The exact key theQuery should include.
Returns
AQuery in this same location, filtering out child nodes that have a different sort value than the sort value specified, and containing at most one child with the exact key specified.

GetReference

DatabaseReferenceGetReference()const

Gets aDatabaseReference corresponding to the given location.

Details
Returns
ADatabaseReference corresponding to the same location as theQuery, but without any of the ordering or filtering parameters.

GetValue

Future<DataSnapshot>GetValue()

Gets the value of the query for the given location a single time.

This is an asynchronous operation which takes time to execute, and usesfirebase::Future to return its result.

Details
Returns
AFuture result, which will complete when the operation either succeeds or fails. On thisFuture's completion, if its Error is kErrorNone, the operation succeeded, and theDataSnapshot contains the data in this location.

GetValueLastResult

Future<DataSnapshot>GetValueLastResult()

Gets the result of the most recent call toGetValue().

Details
Returns
Result of the most recent call toGetValue().

LimitToFirst

QueryLimitToFirst(size_tlimit)

Gets aQuery limited to only the first results.

Limits the query to reference only the first N child nodes, using the given OrderBy directive (or priority as default).

Details
Parameters
limit
Number of children to limit theQuery to.
Returns
AQuery in this same location, limited to the specified number of children (taken from the beginning of the sorted list).

LimitToLast

QueryLimitToLast(size_tlimit)

Gets aQuery limited to only the last results.

Details
Parameters
limit
Number of children to limit theQuery to.
Returns
AQuery in this same location, limited to the specified number of children (taken from the end of the sorted list).

OrderByChild

QueryOrderByChild(constchar*path)

Gets a query in which child nodes are ordered by the values of the specified path.

Any previous OrderBy directive will be replaced in the returnedQuery.

Details
Parameters
path
Path to a child node. The value of this node will be used for sorting this query. The pointer you pass in need not remain valid after the call completes.
Returns
AQuery in this same location, with the children are sorted by the value of their own child specified here.

OrderByChild

QueryOrderByChild(conststd::string&path)

Gets a query in which child nodes are ordered by the values of the specified path.

Any previous OrderBy directive will be replaced in the returnedQuery.

Details
Parameters
path
Path to a child node. The value of this node will be used for sorting this query.
Returns
AQuery in this same location, with the children are sorted by the value of their own child specified here.

OrderByKey

QueryOrderByKey()

Gets a query in which child nodes are ordered by their keys.

Any previous OrderBy directive will be replaced in the returnedQuery.

Details
Returns
AQuery in this same location, with the children are sorted by their key.

OrderByPriority

QueryOrderByPriority()

Gets a query in which child nodes are ordered by their priority.

Any previous OrderBy directive will be replaced in the returnedQuery.

Details
Returns
AQuery in this same location, with the children are sorted by their priority.

OrderByValue

QueryOrderByValue()

Create a query in which nodes are ordered by their value.

Details
Returns
AQuery in this same location, with the children are sorted by their value.

Query

Query()

Default constructor.

This creates an invalidQuery. Attempting to perform any operations on this reference will fail unless a validQuery has been assigned to it.

Query

Query(constQuery&query)

Copy constructor.

Queries can be copied. Copies exist independently of each other.

Query

Query(Query&&query)

Move constructor.

RemoveAllChildListeners

voidRemoveAllChildListeners()

Removes all child listeners that were added byAddChildListener().

Note: You can remove ChildListeners from a differentQuery than you added them to, as long as the twoQuery instances are equivalent.

RemoveAllValueListeners

voidRemoveAllValueListeners()

Removes all value listeners that were added withAddValueListener().

Note: You can remove ValueListeners from a differentQuery than you added them to, as long as the twoQuery instances are equivalent.

RemoveChildListener

voidRemoveChildListener(ChildListener*listener)

Removes a listener that was previously added withAddChildListener().

Note: You can remove aChildListener from a differentQuery than you added it to, as long as the twoQuery instances are equivalent.

Details
Parameters
listener
AChildListener instance to remove from theQuery. After it is removed, you can delete it or attach it to a new location.

RemoveValueListener

voidRemoveValueListener(ValueListener*listener)

Removes a listener that was previously added withAddValueListener().

Note: You can remove aValueListener from a differentQuery than you added it to, as long as the twoQuery instances are equivalent.

Details
Parameters
listener
AValueListener instance to remove from theQuery. After it is removed, you can delete it or attach it to a new location.

SetKeepSynchronized

voidSetKeepSynchronized(boolkeep_sync)

Sets whether this location's data should be kept in sync even if there are no active Listeners.

By calling SetKeepSynchronized(true) on a given database location, the data for that location will automatically be downloaded and kept in sync, even when no listeners are attached for that location. Additionally, while a location is kept synced, it will not be evicted from the persistent disk cache.

Details
Parameters
keep_sync
If true, set this location to be synchronized. If false, set it to not be synchronized.

StartAt

QueryStartAt(Variantorder_value)

Get aQuery constrained to nodes with the given sort value or higher.

This method is used to generate a reference to a limited view of the data at this location. TheQuery returned will only refer to child nodes with a value greater than or equal to the given value, using the given OrderBy directive (or priority as the default).

Details
Parameters
order_value
The lowest sort value theQuery should include.
Returns
AQuery in this same location, filtering out child nodes that have a lower sort value than the sort value specified.

StartAt

QueryStartAt(Variantorder_value,constchar*child_key)

Get aQuery constrained to nodes with the given sort value or higher, and the given key or higher.

This method is used to generate a reference to a limited view of the data at this location. TheQuery returned will only refer to child nodes with a value greater than or equal to the given value, using the given OrderBy directive (or priority as default), and additionally only child nodes with a key greater than or equal to the given key.

Known issue This currently does not work properly on all platforms. Please useStartAt(Variant order_value) instead.

Details
Parameters
order_value
The lowest sort value theQuery should include.
child_key
The lowest key theQuery should include.
Returns
AQuery in this same location, filtering out child nodes that have a lower sort value than the sort value specified, or a lower key than the key specified.

is_valid

virtualboolis_valid()const

Returns true if this query is valid, false if it is not valid.

An invalid query could be returned by, say, attempting to OrderBy two different items, or callingOrderByChild() with an empty path, or by constructing aQuery with the default constructor. If aQuery is invalid, attempting to add more constraints will also result in an invalidQuery.

Details
Returns
true if this query is valid, false if this query is invalid.

operator=

Query&operator=(constQuery&query)

Copy assignment operator.

Queries can be copied. Copies exist independently of each other.

operator=

Query&operator=(Query&&query)

Move assignment operator.

~Query

virtual~Query()

Required virtual destructor.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-23 UTC.