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)
|
Database *
|
Public functions |
|
|---|---|
GetApp() const
|
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)
|
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 |
|
||||
| Returns |
Public functions
GetApp
App * GetApp() const
Get the firease::App that this Database was created with.
| 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
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.
| Details | |||
|---|---|---|---|
| Parameters |
|
~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.

