firebase::database

Namespace for the Firebase Realtime Database C++ SDK.

Summary

Enumerations

Error{
  kErrorNone = 0,
  kErrorDisconnected,
  kErrorExpiredToken,
  kErrorInvalidToken,
  kErrorMaxRetries,
  kErrorNetworkError,
  kErrorOperationFailed,
  kErrorOverriddenBySet,
  kErrorPermissionDenied,
  kErrorUnavailable,
  kErrorUnknownError,
  kErrorWriteCanceled,
  kErrorInvalidVariantType,
  kErrorConflictingOperationInProgress,
  kErrorTransactionAbortedByUser
}
enum
Error code returned by Firebase Realtime Database C++ functions.
TransactionResult{
  kTransactionResultSuccess,
  kTransactionResultAbort
}
enum
Specifies whether the transaction succeeded or not.

Typedefs

DoTransaction)(MutableData *data) typedef
Your own transaction handler, which the Firebase Realtime Database library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.
DoTransactionFunction typedef
std::function< TransactionResult(MutableData *data)>
Your own transaction handler function or lambda, which the Firebase Realtime Database library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.
DoTransactionWithContext)(MutableData *data, void *context) typedef
Your own transaction handler, which the Firebase Realtime Database library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

Functions

GetErrorMessage(Error error)
const char *
Get the human-readable error message corresponding to an error code.
ServerTimestamp()
const Variant &
Get a server-populated value corresponding to the current timestamp.
operator==(const DatabaseReference & lhs, const DatabaseReference & rhs)
bool
Compares two DatabaseReference instances.
operator==(const Query & lhs, const Query & rhs)
bool
Compares two Query instances.

Classes

firebase::database::ChildListener

Child listener interface.

firebase::database::DataSnapshot

A DataSnapshot instance contains data from a Firebase Database location.

firebase::database::Database

Entry point for the Firebase Realtime Database C++ SDK.

firebase::database::DatabaseReference

DatabaseReference represents a particular location in your Database and can be used for reading or writing data to that Database location.

firebase::database::DisconnectionHandler

Allows you to register server-side actions to occur when the client disconnects.

firebase::database::MutableData

Instances of this class encapsulate the data and priority at a location.

firebase::database::Query

The Query class is used for reading data.

firebase::database::ValueListener

Value listener interface.

Enumerations

Error

 Error

Error code returned by Firebase Realtime Database C++ functions.

Properties
kErrorConflictingOperationInProgress

An operation that conflicts with this one is already in progress.

For example, calling SetValue and SetValueAndPriority on a DatabaseReference is not allowed.

kErrorDisconnected

The operation had to be aborted due to a network disconnect.

kErrorExpiredToken

The supplied auth token has expired.

kErrorInvalidToken

The specified authentication token is invalid.

kErrorInvalidVariantType

You specified an invalid Variant type for a field.

For example, a DatabaseReference's Priority and the keys of a Map must be of scalar type (MutableString, StaticString, Int64, Double).

kErrorMaxRetries

The transaction had too many retries.

kErrorNetworkError

The operation could not be performed due to a network error.

kErrorNone

The operation was a success, no error occurred.

kErrorOperationFailed

The server indicated that this operation failed.

kErrorOverriddenBySet

The transaction was overridden by a subsequent set.

kErrorPermissionDenied

This client does not have permission to perform this operation.

kErrorTransactionAbortedByUser

The transaction was aborted, because the user's DoTransaction function returned kTransactionResultAbort instead of kTransactionResultSuccess.

kErrorUnavailable

The service is unavailable.

kErrorUnknownError

An unknown error occurred.

kErrorWriteCanceled

The write was canceled locally.

TransactionResult

 TransactionResult

Specifies whether the transaction succeeded or not.

Properties
kTransactionResultAbort

The transaction did not succeed.

Any changes to the MutableData will be discarded.

kTransactionResultSuccess

The transaction was successful, the MutableData was updated.

Typedefs

DoTransaction

TransactionResult(* DoTransaction)(MutableData *data)

Your own transaction handler, which the Firebase Realtime Database library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

See also:DoTransactionWithContext for more information.

DoTransactionFunction

std::function< TransactionResult(MutableData *data)> DoTransactionFunction

Your own transaction handler function or lambda, which the Firebase Realtime Database library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

See also:DoTransactionWithContext for more information.

DoTransactionWithContext

TransactionResult(* DoTransactionWithContext)(MutableData *data, void *context)

Your own transaction handler, which the Firebase Realtime Database library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

The context you specified to RunTransaction will be passed into this call.

This function will be called, possibly multiple times, with the current data at this location. The function is responsible for inspecting that data and modifying it as desired, then returning a TransactionResult specifying either that the MutableData was modified to a desired new state, or that the transaction should be aborted. Whenever this function is called, the MutableData passed in must be modified from scratch.

Since this function may be called repeatedly for the same transaction, be extremely careful of any side effects that may be triggered by this function. In addition, this function is called from within the Firebase Realtime Database library's run loop, so care is also required when accessing data that may be in use by other threads in your application.

Best practices for this function are to ONLY rely on the data passed in.

See also:DoTransaction for more information.

Details
Parameters
data
Mutable data, which the callback can edit.
context
Context pointer, passed verbatim to the callback.
Returns
The callback should return kTransactionResultSuccess if the data was modified, or kTransactionResultAbort if it was unable to modify the data. If the callback returns kTransactionResultAbort, the RunTransaction() call will return the kErrorTransactionAbortedByUser error code.

Functions

GetErrorMessage

const char * GetErrorMessage(
  Error error
)

Get the human-readable error message corresponding to an error code.

Details
Parameters
error
Error code to get the error message for.
Returns
Statically-allocated string describing the error.

ServerTimestamp

const Variant & ServerTimestamp()

Get a server-populated value corresponding to the current timestamp.

When inserting values into the database, you can use the special value firebase::database::ServerTimestamp() to have the server auto-populate the current timestamp, which is represented as millieconds since the Unix epoch, into the field.

Details
Returns
A special value that tells the server to use the current timestamp.

operator==

bool operator==(
  const DatabaseReference & lhs,
  const DatabaseReference & rhs
)

Compares two DatabaseReference instances.

Details
Parameters
lhs
rhs
A DatabaseReference to compare against.
Returns
True if the DatabaseReference instances have the same URL. False otherwise.

operator==

bool operator==(
  const Query & lhs,
  const Query & rhs
)

Compares two Query instances.

Two Query instances on the same database, in the same location, with the same parameters (OrderBy*, StartAt, EndAt, EqualTo, Limit*) are considered equivalent.

Equivalent Queries have a shared pool of ValueListeners and ChildListeners. When listeners are added or removed from one Query instance, it affects all equivalent Query instances.

Details
Parameters
lhs
The Query to compare against.
rhs
The Query to compare against.
Returns
True if the Query instances have the same database, the same path, and the same parameters, determined by StartAt(), EndAt(), EqualTo(), and the OrderBy and LimitTo methods. False otherwise.