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::DatabaseReferenceConstructors and Destructors | |
|---|---|
Query()Default constructor. | |
Query(constQuery & query)Copy constructor. | |
Query(Query && query)Move constructor. | |
~Query()Required virtual destructor. |
Public functions | |
|---|---|
AddChildListener(ChildListener *listener) | voidAdds a listener that will be called any time a child is added, removed, modified, or reordered. |
AddValueListener(ValueListener *listener) | voidAdds 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() | voidRemoves all child listeners that were added byAddChildListener(). |
RemoveAllValueListeners() | voidRemoves all value listeners that were added withAddValueListener(). |
RemoveChildListener(ChildListener *listener) | voidRemoves a listener that was previously added withAddChildListener(). |
RemoveValueListener(ValueListener *listener) | voidRemoves a listener that was previously added withAddValueListener(). |
SetKeepSynchronized(bool keep_sync) | voidSets 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 boolReturns true if this query is valid, false if it is not valid. |
operator=(constQuery & query) | Query &Copy assignment operator. |
operator=(Query && 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 |
|
AddValueListener
voidAddValueListener(ValueListener*listener)
Adds a listener that will be called immediately and then again any time the data changes.
| Details | |||
|---|---|---|---|
| Parameters |
|
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 |
| ||
| 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 |
| ||||
| 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 |
| ||
| 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 |
| ||||
| 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 |
| ||
| 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)
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 |
| ||
| 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 |
| ||
| Returns | AQuery in this same location, with the children are sorted by the value of their own child specified here. |
OrderByKey
QueryOrderByKey()
OrderByPriority
QueryOrderByPriority()
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()
Query
Query(constQuery&query)
Copy constructor.
Queries can be copied. Copies exist independently of each other.
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 |
|
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 |
|
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 |
|
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 |
| ||
| 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 |
| ||||
| 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.
~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.