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 *
|
GetInstance(::firebase::App *app, const char *url, InitResult *init_result_out)
|
Database *
Gets an instance of FirebaseDatabase for the specified URL.
|
Public functions |
|
---|---|
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.
|
app() const
|
App *
Get the firebase::App that this Database was created with.
|
log_level() const
|
Get the log verbosity of this Database instance.
|
set_log_level(LogLevel log_level)
|
void
Set the log verbosity of this Database instance.
|
set_persistence_enabled(bool enabled)
|
void
Sets whether pending write data will persist between application exits.
|
url() const
|
const char *
Get the URL that this Database was created with.
|
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 Database.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Returns |
GetInstance
Database * GetInstance( ::firebase::App *app, const char *url, InitResult *init_result_out )
Gets an instance of FirebaseDatabase for the specified URL.
If you call GetInstance() multiple times with the same App and URL, you will get the same instance of Database.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Returns |
Public functions
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.
app
App * app() const
Get the firebase::App that this Database was created with.
Details | |
---|---|
Returns |
The firebase::App this Database was created with.
|
log_level
LogLevel log_level() const
Get the log verbosity of this Database instance.
Details | |
---|---|
Returns |
Get the currently configured logging verbosity.
|
set_log_level
void set_log_level( LogLevel log_level )
Set the log verbosity of this Database instance.
The log filtering is cumulative with Firebase App. That is, this library's log messages will only be displayed if they are not filtered out by this library's log level setting and by Firebase App's log level setting.
Details | |||
---|---|---|---|
Parameters |
|
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).
Details | |||
---|---|---|---|
Parameters |
|
url
const char * url() const
~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.