firebase:: firestore:: Firestore
#include <firestore.h>
Entry point for the Firebase Firestore C++ SDK.
Summary
To use the SDK, call firebase::firestore::Firestore::GetInstance() to obtain an instance of Firestore, then use Collection() or Document() to obtain references to child paths within the database. From there, you can set data via CollectionReference::Add() and DocumentReference::Set(), or get data via CollectionReference::Get() and DocumentReference::Get(), attach listeners, and more.
Constructors and Destructors |
|
---|---|
Firestore(const Firestore & src)
Deleted copy constructor; Firestore must be created with Firestore::GetInstance().
|
|
~Firestore()
Destructor for the Firestore object.
|
Friend classes |
|
---|---|
csharp::ApiHeaders
|
friend class
|
csharp::TransactionManager
|
friend class
|
Public static functions |
|
---|---|
GetInstance(::firebase::App *app, InitResult *init_result_out)
|
|
GetInstance(InitResult *init_result_out)
|
|
GetInstance(::firebase::App *app, const char *db_name, InitResult *init_result_out)
|
|
GetInstance(const char *db_name, InitResult *init_result_out)
|
|
set_log_level(LogLevel log_level)
|
void
Sets the log verbosity of all Firestore instances.
|
Public functions |
|
---|---|
AddSnapshotsInSyncListener(std::function< void()> callback)
|
virtual ListenerRegistration
Attaches a listener for a snapshots-in-sync event.
|
ClearPersistence()
|
virtual Future< void >
Clears the persistent storage.
|
Collection(const char *collection_path) const
|
virtual CollectionReference
Returns a CollectionReference instance that refers to the collection at the specified path within the database.
|
Collection(const std::string & collection_path) const
|
virtual CollectionReference
Returns a CollectionReference instance that refers to the collection at the specified path within the database.
|
CollectionGroup(const char *collection_id) const
|
virtual Query
Returns a Query instance that includes all documents in the database that are contained in a collection or subcollection with the given collection_id.
|
CollectionGroup(const std::string & collection_id) const
|
virtual Query
Returns a Query instance that includes all documents in the database that are contained in a collection or subcollection with the given collection_id.
|
DisableNetwork()
|
virtual Future< void >
Disables network access for this instance.
|
Document(const char *document_path) const
|
virtual DocumentReference
Returns a DocumentReference instance that refers to the document at the specified path within the database.
|
Document(const std::string & document_path) const
|
virtual DocumentReference
Returns a DocumentReference instance that refers to the document at the specified path within the database.
|
EnableNetwork()
|
virtual Future< void >
Re-enables network usage for this instance after a prior call to DisableNetwork().
|
LoadBundle(const std::string & bundle)
|
virtual Future< LoadBundleTaskProgress >
Loads a Firestore bundle into the local cache.
|
LoadBundle(const std::string & bundle, std::function< void(const LoadBundleTaskProgress &)> progress_callback)
|
virtual Future< LoadBundleTaskProgress >
Loads a Firestore bundle into the local cache, with the provided callback executed for progress updates.
|
NamedQuery(const std::string & query_name)
|
|
RunTransaction(std::function< Error(Transaction &, std::string &)> update)
|
virtual Future< void >
Executes the given update and then attempts to commit the changes applied within the transaction.
|
RunTransaction(TransactionOptions options, std::function< Error(Transaction &, std::string &)> update)
|
virtual Future< void >
Executes the given update and then attempts to commit the changes applied within the transaction.
|
Terminate()
|
virtual Future< void >
Terminates this
Firestore instance. |
WaitForPendingWrites()
|
virtual Future< void >
Waits until all currently pending writes for the active user have been acknowledged by the backend.
|
app() const
|
virtual const App *
Returns the firebase::App that this Firestore was created with.
|
app()
|
virtual App *
Returns the firebase::App that this Firestore was created with.
|
batch() const
|
virtual WriteBatch
Creates a write batch, used for performing multiple writes as a single atomic operation.
|
operator=(const Firestore & src)=delete
|
Deleted copy assignment operator; Firestore must be created with Firestore::GetInstance().
|
set_settings(Settings settings)
|
virtual void
Sets any custom settings used to configure this Firestore object.
|
settings() const
|
virtual Settings
Returns the settings used by this Firestore object.
|
Protected functions |
|
---|---|
Firestore()=default
|
Default constructor, to be used only for mocking
Firestore . |
Friend classes
csharp::ApiHeaders
friend class csharp::ApiHeaders
csharp::TransactionManager
friend class csharp::TransactionManager
Public static functions
GetInstance
Firestore * GetInstance( ::firebase::App *app, InitResult *init_result_out )
Returns an instance of Firestore corresponding to the given App with default database ID.
Firebase Firestore uses firebase::App to communicate with Firebase Authentication to authenticate users to the Firestore server backend.
If you call GetInstance() multiple times with the same App, you will get the same instance of Firestore.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Returns |
GetInstance
Firestore * GetInstance( InitResult *init_result_out )
Returns an instance of Firestore corresponding to the default App with default database ID.
Firebase Firestore uses the default App to communicate with Firebase Authentication to authenticate users to the Firestore server backend.
If you call GetInstance() multiple times, you will get the same instance.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
GetInstance
Firestore * GetInstance( ::firebase::App *app, const char *db_name, InitResult *init_result_out )
Returns an instance of Firestore corresponding to the given App with the given database ID.
Firebase Firestore uses firebase::App to communicate with Firebase Authentication to authenticate users to the Firestore server backend.
If you call GetInstance() multiple times with the same App, you will get the same instance of Firestore.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Returns |
GetInstance
Firestore * GetInstance( const char *db_name, InitResult *init_result_out )
Returns an instance of Firestore corresponding to the default App with the given database ID.
Firebase Firestore uses firebase::App to communicate with Firebase Authentication to authenticate users to the Firestore server backend.
If you call GetInstance() multiple times with the same App, you will get the same instance of Firestore.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Returns |
set_log_level
void set_log_level( LogLevel log_level )
Sets the log verbosity of all Firestore instances.
The default verbosity level is kLogLevelInfo
.
Details | |||
---|---|---|---|
Parameters |
|
Public functions
AddSnapshotsInSyncListener
virtual ListenerRegistration AddSnapshotsInSyncListener( std::function< void()> callback )
Attaches a listener for a snapshots-in-sync event.
Server-generated updates and local changes can affect multiple snapshot listeners. The snapshots-in-sync event indicates that all listeners affected by a given change have fired.
NOTE: The snapshots-in-sync event only indicates that listeners are in sync with each other, but does not relate to whether those snapshots are in sync with the server. Use SnapshotMetadata
in the individual listeners to determine if a snapshot is from the cache or the server.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
A
ListenerRegistration object that can be used to remove the listener. |
ClearPersistence
virtual Future< void > ClearPersistence()
Clears the persistent storage.
This includes pending writes and cached documents.
Must be called while the Firestore instance is not started (after the app is shut down or when the app is first initialized). On startup, this method must be called before other methods (other than settings()
and set_settings()
). If the Firestore instance is still running, the function will complete with an error code of FailedPrecondition
.
Note: ClearPersistence()
is primarily intended to help write reliable tests that use Firestore. It uses the most efficient mechanism possible for dropping existing data but does not attempt to securely overwrite or otherwise make cached data unrecoverable. For applications that are sensitive to the disclosure of cache data in between user sessions we strongly recommend not to enable persistence in the first place.
Collection
virtual CollectionReference Collection( const char *collection_path ) const
Returns a CollectionReference instance that refers to the collection at the specified path within the database.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
The CollectionReference instance.
|
Collection
virtual CollectionReference Collection( const std::string & collection_path ) const
Returns a CollectionReference instance that refers to the collection at the specified path within the database.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
The CollectionReference instance.
|
CollectionGroup
virtual Query CollectionGroup( const char *collection_id ) const
Returns a Query instance that includes all documents in the database that are contained in a collection or subcollection with the given collection_id.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
The Query instance.
|
CollectionGroup
virtual Query CollectionGroup( const std::string & collection_id ) const
Returns a Query instance that includes all documents in the database that are contained in a collection or subcollection with the given collection_id.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
The Query instance.
|
DisableNetwork
virtual Future< void > DisableNetwork()
Disables network access for this instance.
While the network is disabled, any snapshot listeners or Get() calls will return results from cache, and any write operations will be queued until network usage is re-enabled via a call to EnableNetwork().
If the network was already disabled, calling DisableNetwork()
again is a no-op.
Document
virtual DocumentReference Document( const char *document_path ) const
Returns a DocumentReference instance that refers to the document at the specified path within the database.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
The DocumentReference instance.
|
Document
virtual DocumentReference Document( const std::string & document_path ) const
Returns a DocumentReference instance that refers to the document at the specified path within the database.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
The DocumentReference instance.
|
EnableNetwork
virtual Future< void > EnableNetwork()
Re-enables network usage for this instance after a prior call to DisableNetwork().
If the network is currently enabled, calling EnableNetwork()
is a no-op.
Firestore
Firestore( const Firestore & src )=delete
Deleted copy constructor; Firestore must be created with Firestore::GetInstance().
LoadBundle
virtual Future< LoadBundleTaskProgress > LoadBundle( const std::string & bundle )
LoadBundle
virtual Future< LoadBundleTaskProgress > LoadBundle( const std::string & bundle, std::function< void(const LoadBundleTaskProgress &)> progress_callback )
Loads a Firestore bundle into the local cache, with the provided callback executed for progress updates.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Returns |
A
Future that is resolved when the loading is either completed or aborted due to an error. |
NamedQuery
virtual Future< Query > NamedQuery( const std::string & query_name )
Reads a FirestoreQuery
from the local cache, identified by the given name.
Named queries are packaged into bundles on the server side (along with the resulting documents) and loaded into local cache using LoadBundle
. Once in the local cache, you can use this method to extract a query by name.
If a query cannot be found, the returned future will complete with its error()
set to a non-zero error code.
Details | |||
---|---|---|---|
Parameters |
|
RunTransaction
virtual Future< void > RunTransaction( std::function< Error(Transaction &, std::string &)> update )
Executes the given update and then attempts to commit the changes applied within the transaction.
If any document read within the transaction has changed, the update function will be retried. If it fails to commit after 5 attempts, the transaction will fail.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
A Future that will be resolved when the transaction finishes.
|
RunTransaction
virtual Future< void > RunTransaction( TransactionOptions options, std::function< Error(Transaction &, std::string &)> update )
Executes the given update and then attempts to commit the changes applied within the transaction.
If any document read within the transaction has changed, the update function will be retried. If it fails to commit after the max_attempts
specified in the given TransactionOptions
, the transaction will fail.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Returns |
A Future that will be resolved when the transaction finishes.
|
Terminate
virtual Future< void > Terminate()
Terminates this Firestore
instance.
After calling Terminate()
, only the ClearPersistence()
method may be used. Calling any other methods will result in an error.
To restart after termination, simply create a new instance of Firestore
with Firestore::GetInstance()
.
Terminate()
does not cancel any pending writes and any tasks that are awaiting a response from the server will not be resolved. The next time you start this instance, it will resume attempting to send these writes to the server.
Note: under normal circumstances, calling Terminate()
is not required. This method is useful only when you want to force this instance to release all of its resources or in combination with ClearPersistence()
to ensure that all local state is destroyed between test runs.
Details | |
---|---|
Returns |
A
Future that is resolved when the instance has been successfully terminated. |
WaitForPendingWrites
virtual Future< void > WaitForPendingWrites()
Waits until all currently pending writes for the active user have been acknowledged by the backend.
The returned future is resolved immediately without error if there are no outstanding writes. Otherwise, the future is resolved when all previously issued writes (including those written in a previous app session) have been acknowledged by the backend. The future does not wait for writes that were added after the method is called. If you wish to wait for additional writes, you have to call WaitForPendingWrites
again.
Any outstanding WaitForPendingWrites
futures are resolved with an error during user change.
app
virtual const App * app() const
Returns the firebase::App that this Firestore was created with.
Details | |
---|---|
Returns |
The firebase::App this Firestore was created with.
|
app
virtual App * app()
Returns the firebase::App that this Firestore was created with.
Details | |
---|---|
Returns |
The firebase::App this Firestore was created with.
|
batch
virtual WriteBatch batch() const
Creates a write batch, used for performing multiple writes as a single atomic operation.
Unlike transactions, write batches are persisted offline and therefore are preferable when you don't need to condition your writes on read data.
Details | |
---|---|
Returns |
The created WriteBatch object.
|
operator=
Firestore & operator=( const Firestore & src )=delete
Deleted copy assignment operator; Firestore must be created with Firestore::GetInstance().
set_settings
virtual void set_settings( Settings settings )
Sets any custom settings used to configure this Firestore object.
~Firestore
virtual ~Firestore()
Destructor for the Firestore object.
When deleted, this instance will be removed from the cache of Firestore objects. If you call GetInstance() in the future with the same App, a new Firestore instance will be created.