Jump to top

database

interface

The Firebase Database service is available for the default app or a given app.

Example 1

Get the database instance for the default app:

const databaseForDefaultApp = firebase.database();
Example 2

Get the database instance for a secondary app:

const otherApp = firebase.app('otherApp');
const databaseForOtherApp = firebase.database(otherApp);

Properties

app

</>

The current FirebaseApp instance for this Firebase service.

Methods

getServerTime

</>

Returns the current Firebase Database server time as a JavaScript Date object.

getServerTime(): Date;

goOffline

</>

Disconnects from the server (all Database operations will be completed offline).

goOffline(): Promise<void>;

goOnline

</>

Reconnects to the server and synchronizes the offline Database state with the server state.

goOnline(): Promise<void>;

ref

</>

Returns a Reference representing the location in the Database corresponding to the provided path. If no path is provided, the Reference will point to the root of the Database.

ref(path?: undefined | string): Reference;

refFromURL

</>

Returns a Reference representing the location in the Database corresponding to the provided Firebase URL.

refFromURL(url: string): Reference;

setLoggingEnabled

</>

Sets the native logging level for the database module. By default, only warnings and errors are logged natively. Setting this to true will log all database events.

setLoggingEnabled(enabled: boolean): Promise<void>;

setPersistenceCacheSizeBytes

</>

By default Firebase Database will use up to 10MB of disk space to cache data. If the cache grows beyond this size, Firebase Database will start removing data that hasn't been recently used. If you find that your application caches too little or too much data, call this method to change the cache size. This method must be called before creating your first Database reference and only needs to be called once per application.

setPersistenceCacheSizeBytes(bytes: number): Promise<void>;

setPersistenceEnabled

</>

Sets whether persistence is enabled for all database calls for the current app instance.

setPersistenceEnabled(enabled: boolean): Promise<void>;

useEmulator

</>

Modify this Database instance to communicate with the Firebase Database emulator. This must be called synchronously immediately following the first call to firebase.database(). Do not use with production credentials as emulator traffic is not encrypted.

useEmulator(host: string, port: number): void;

Statics

ServerValue

</>

Returns server specific values, such as the server timestamp.

database.ServerValue: ServerValue;