firebase::database::Database

#include <database.h>

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

Summary

To use the SDK, call firebase::database::Database::GetInstance() to obtain an instance of Database, then use GetReference() to obtain references to child paths within the database. From there you can set data via Query::SetValue(), get data via Query::GetValue(), attach listeners, and more.

Constructors and Destructors

~Database()
Destructor for the Database object.

Public static functions

GetInstance(::firebase::App *app, InitResult *init_result_out)
Get an instance of Database corresponding to the given App.

Public functions

GetApp() const
FIREBASE_DEPRECATED App *
Deprecated. Renamed to app().
Get the firease::App that this Database was created with.
GetReference() const
Get a DatabaseReference to the root of the database.
GetReference(const char *path) const
Get a DatabaseReference for the specified path.
GetReferenceFromUrl(const char *url) const
Get a DatabaseReference for the provided URL, which must belong to the database URL this instance is already connected to.
GoOffline()
void
Shuts down the connection to the Firebase Realtime Database backend until GoOnline() is called.
GoOnline()
void
Resumes the connection to the Firebase Realtime Database backend after a previous GoOffline() call.
PurgeOutstandingWrites()
void
Purge all pending writes to the Firebase Realtime Database server.
SetPersistenceEnabled(bool enabled)
FIREBASE_DEPRECATED void
Deprecated. Renamed to set_persistence_enabled().
Sets whether pending write data will persist between application exits.
app() const
App *
Get the firease::App that this Database was created with.
set_persistence_enabled(bool enabled)
void
Sets whether pending write data will persist between application exits.

Public static functions

GetInstance

Database * GetInstance(
  ::firebase::App *app,
  InitResult *init_result_out
)

Get an instance of Database corresponding to the given App.

Firebase Realtime Database uses firebase::App to communicate with Firebase Authentication to authenticate users to the Database server backend.

If you call GetInstance() multiple times with the same App, you will get the same instance of App.

Details
Parameters
app
Your instance of firebase::App. Firebase Realtime Database will use this to communicate with Firebase Authentication.
init_result_out
Optional: If provided, write the init result here. Will be set to kInitResultSuccess if initialization succeeded, or kInitResultFailedMissingDependency on Android if Google Play services is not available on the current device.
Returns
An instance of Database corresponding to the given App.

Public functions

GetApp

FIREBASE_DEPRECATED App * GetApp() const 

Get the firease::App that this Database was created with.

Deprecated. Renamed to app().

Details
Returns
The firebase::App this Database was created with.

GetReference

DatabaseReference GetReference() const 

Get a DatabaseReference to the root of the database.

Details
Returns
A DatabaseReference to the root of the database.

GetReference

DatabaseReference GetReference(
  const char *path
) const 

Get a DatabaseReference for the specified path.

Details
Returns
A DatabaseReference to the specified path in the database. If you specified an invalid path, the reference's DatabaseReference::IsValid() will return false.

GetReferenceFromUrl

DatabaseReference GetReferenceFromUrl(
  const char *url
) const 

Get a DatabaseReference for the provided URL, which must belong to the database URL this instance is already connected to.

Details
Returns
A DatabaseReference to the specified path in the database. If you specified an invalid path, the reference's DatabaseReference::IsValid() will return false.

GoOffline

void GoOffline()

Shuts down the connection to the Firebase Realtime Database backend until GoOnline() is called.

GoOnline

void GoOnline()

Resumes the connection to the Firebase Realtime Database backend after a previous GoOffline() call.

PurgeOutstandingWrites

void PurgeOutstandingWrites()

Purge all pending writes to the Firebase Realtime Database server.

The Firebase Realtime Database client automatically queues writes and sends them to the server at the earliest opportunity, depending on network connectivity. In some cases (e.g. offline usage) there may be a large number of writes waiting to be sent. Calling this method will purge all outstanding writes so they are abandoned. All writes will be purged, including transactions and onDisconnect() writes. The writes will be rolled back locally, perhaps triggering events for affected event listeners, and the client will not (re-)send them to the Firebase backend.

SetPersistenceEnabled

FIREBASE_DEPRECATED void SetPersistenceEnabled(
  bool enabled
)

Sets whether pending write data will persist between application exits.

The Firebase Database client will cache synchronized data and keep track of all writes you've initiated while your application is running. It seamlessly handles intermittent network connections and re-sends write operations when the network connection is restored. However by default your write operations and cached data are only stored in-memory and will be lost when your app restarts. By setting this value to true, the data will be persisted to on-device (disk) storage and will thus be available again when the app is restarted (even when there is no network connectivity at that time).

Note:SetPersistenceEnabled should be called before creating any instances of DatabaseReference, and only needs to be called once per application. Deprecated. Renamed to set_persistence_enabled().

Details
Parameters
enabled
Set this to true to persist write data to on-device (disk) storage, or false to discard pending writes when the app exists.

app

App * app() const 

Get the firease::App that this Database was created with.

Details
Returns
The firebase::App this Database was created with.

set_persistence_enabled

void set_persistence_enabled(
  bool enabled
)

Sets whether pending write data will persist between application exits.

The Firebase Database client will cache synchronized data and keep track of all writes you've initiated while your application is running. It seamlessly handles intermittent network connections and re-sends write operations when the network connection is restored. However by default your write operations and cached data are only stored in-memory and will be lost when your app restarts. By setting this value to true, the data will be persisted to on-device (disk) storage and will thus be available again when the app is restarted (even when there is no network connectivity at that time).

Note:SetPersistenceEnabled should be called before creating any instances of DatabaseReference, and only needs to be called once per application.

Details
Parameters
enabled
Set this to true to persist write data to on-device (disk) storage, or false to discard pending writes when the app exists.

~Database

 ~Database()

Destructor for the Database object.

When deleted, this instance will be removed from the cache of Database objects. If you call GetInstance() in the future with the same App, a new Database instance will be created.

Send feedback about...

Need help? Visit our support page.