get method
Reads the query's data once, preferring the server.
-
When the client already holds the query's data complete (server data kept for an active listener, or pending local writes that cover the query, with pending writes laid over it), it answers from that with no round trip.
-
Otherwise it asks the server and waits, with no client timeout while connected. The answer also raises events on the listeners it completes, before this Future completes.
-
When not connected, it waits up to 3 seconds for a connection, then answers from the persisted cache, or fails with
unavailable. AfterFirebaseDatabase.goOfflineit does not wait. -
When the connection drops while the request is out, case 3 applies from then.
-
When the server refuses the read it fails with
permission-denied, never with a cached answer. -
A
.infopath answers from the local state at once.
Other failures keep their code: network-error after two connections that each fell silent,
index-not-defined for a filtered query the rules cannot serve, database-closed after
FirebaseDatabase.close. Without persistence there is no persisted cache, so case 3 ends in
unavailable.
Outside case 1 the answer does not include this client's pending writes.
A query with an order but no range and no limit asks the server for all the data at its path and
orders the children here, as a listener does, so it needs no .indexOn rule. A query with a range or a limit is sent as it is and
fails with index-not-defined when the rules have no .indexOn for its order.
Implementation
Future<DataSnapshot> get() {
final DatabaseReference location = ref;
return database.request<DataSnapshot>((
Repo repo,
void Function(DataSnapshot) complete,
void Function(Object, [StackTrace?]) fail,
) {
repo
.getValue(spec)
.then<void>(
(Node node) =>
complete(DataSnapshot.internal(location, node, spec.index)),
onError: (Object error, StackTrace stackTrace) =>
fail(toApiError(error), stackTrace),
);
});
}