database/lib/modular

Variables

ServerValue

const ServerValue: object

Defined in: database/lib/modular/index.d.ts:226

Server specific values.

Type Declaration

TIMESTAMP

TIMESTAMP: object

A placeholder value for auto-populating the current timestamp.

increment()

increment(delta): object

Returns a placeholder value that can be used to atomically increment the current database value.

Parameters
delta

number

Returns

object

Functions

connectDatabaseEmulator()

connectDatabaseEmulator(db, host, port): void

Defined in: database/lib/modular/index.d.ts:34

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.

Note: on android, hosts 'localhost' and '127.0.0.1' are automatically remapped to '10.0.2.2' (the "host" computer IP address for android emulators) to make the standard development experience easy. If you want to use the emulator on a real android device, you will need to specify the actual host computer IP address.

Parameters

db

Module

host

string

port

number

Returns

void

enableLogging()

enableLogging(enabled, persistent?): any

Defined in: database/lib/modular/index.d.ts:243

Logs debugging information to the console. Not implemented on native.

Parameters

enabled

boolean

persistent?

boolean

Returns

any

forceLongPolling()

forceLongPolling(): void

Defined in: database/lib/modular/index.d.ts:196

Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.

Returns

void

forceWebSockets()

forceWebSockets(): void

Defined in: database/lib/modular/index.d.ts:201

Force the use of websockets instead of longPolling.

Returns

void

getDatabase()

getDatabase(app?, url?): Module

Defined in: database/lib/modular/index.d.ts:18

Returns the instance of the Realtime Database SDK that is associated with the provided FirebaseApp. Initializes a new instance with default settings if no instance exists or if the existing instance uses a custom database URL.

Parameters

app?

FirebaseApp

url?

string

Returns

Module

Database instance

getServerTime()

getServerTime(db): Promise<number>

Defined in: database/lib/modular/index.d.ts:213

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

Parameters

db

Module

Returns

Promise<number>

goOffline()

goOffline(db): Promise<void>

Defined in: database/lib/modular/index.d.ts:67

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

The client automatically maintains a persistent connection to the Database server, which will remain active indefinitely and reconnect when disconnected. However, the goOffline() and goOnline() methods may be used to control the client connection in cases where a persistent connection is undesirable.

While offline, the client will no longer receive data updates from the Database. However, all Database operations performed locally will continue to immediately fire events, allowing your application to continue behaving normally. Additionally, each operation performed locally will automatically be queued and retried upon reconnection to the Database server.

To reconnect to the Database and begin receiving remote events, see goOnline().

Example

const db = getDatabase();;
await goOnline(db);

Parameters

db

Module

Returns

Promise<void>

goOnline()

goOnline(db): Promise<void>

Defined in: database/lib/modular/index.d.ts:83

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

This method should be used after disabling the active connection with goOffline(). Once reconnected, the client will transmit the proper data and fire the appropriate events so that your client "catches up" automatically.

Example

const db = getDatabase();
await goOnline(db);

Parameters

db

Module

Returns

Promise<void>

increment()

increment(delta): object

Defined in: database/lib/modular/index.d.ts:221

Returns a placeholder value that can be used to atomically increment the current database value by the provided delta.

Parameters

delta

number

the amount to modify the current value atomically.

Returns

object

A placeholder value for modifying data atomically server-side.

ref()

ref(db, path?): Reference

Defined in: database/lib/modular/index.d.ts:104

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.

Example

const db = getDatabase();

// Get a reference to the root of the Database
const rootRef = ref(db);

// Get a reference to the /users/ada node
const adaRef = ref(db, "users/ada");

Parameters

db

Module

The Database instance.

path?

string

Optional path representing the location the returned Reference will point. If not provided, the returned Reference will point to the root of the Database.

Returns

Reference

refFromURL()

refFromURL(db, url): Reference

Defined in: database/lib/modular/index.d.ts:115

Generates a Reference from a database URL. Note domain must be the same. Any query parameters are stripped as per the web SDK.

Parameters

db

Module

The Database instance.

url

string

The Firebase URL at which the returned Reference will point.

Returns

Reference

DatabaseReference

serverTimestamp()

serverTimestamp(): object

Defined in: database/lib/modular/index.d.ts:208

Returns a placeholder value for auto-populating the current timestamp (time since the Unix epoch, in milliseconds) as determined by the Firebase servers.

Returns

object

setLoggingEnabled()

setLoggingEnabled(db, enabled): void

Defined in: database/lib/modular/index.d.ts:163

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.

Ensure logging is disabled for production apps, as excessive logging can cause performance issues.

Example

const db = getDatabase();

// Set debug logging if developing
if (__DEV__) {
  setLoggingEnabled(db, true);
}

Parameters

db

Module

The Database instance.

enabled

boolean

Whether debug logging is enabled.

Returns

void

void

setPersistenceCacheSizeBytes()

setPersistenceCacheSizeBytes(db, bytes): void

Defined in: database/lib/modular/index.d.ts:191

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.

Note that the specified cache size is only an approximation and the size on disk may temporarily exceed it at times. Cache sizes smaller than 1 MB or greater than 100 MB are not supported.

Example

const db = getDatabase();

setPersistenceEnabled(db, true);
setPersistenceCacheSizeBytes(db, 2000000); // 2MB

async function bootstrap() {
  // Bootstrapping application
  const snapshot = await ref(db, 'settings').once("value");
}

Parameters

db

Module

The Database instance.

bytes

number

The new size of the cache in bytes.

Returns

void

setPersistenceEnabled()

setPersistenceEnabled(db, enabled): void

Defined in: database/lib/modular/index.d.ts:139

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

Ensure this is called before any database calls are performed, otherwise persistence will only come into effect when the app is next started.

Example

const db = getDatabase();
setPersistenceEnabled(db, true);

async function bootstrap() {
  // Bootstrapping application
  const snapshot = await ref(db, "settings").once("value");
}

Parameters

db

Module

The Database instance.

enabled

boolean

Whether persistence is enabled for the Database service.

Returns

void

References

child

Re-exports child

DatabaseReference

Re-exports DatabaseReference

DataSnapshot

Re-exports DataSnapshot

endAt

Re-exports endAt

endBefore

Re-exports endBefore

equalTo

Re-exports equalTo

get

Re-exports get

keepSynced

Re-exports keepSynced

limitToFirst

Re-exports limitToFirst

limitToLast

Re-exports limitToLast

ListenOptions

Re-exports ListenOptions

off

Re-exports off

onChildAdded

Re-exports onChildAdded

onChildChanged

Re-exports onChildChanged

onChildMoved

Re-exports onChildMoved

onChildRemoved

Re-exports onChildRemoved

onDisconnect

Re-exports onDisconnect

OnDisconnect

Re-exports OnDisconnect

onValue

Re-exports onValue

orderByChild

Re-exports orderByChild

orderByKey

Re-exports orderByKey

orderByPriority

Re-exports orderByPriority

orderByValue

Re-exports orderByValue

push

Re-exports push

query

Re-exports query

Query

Re-exports Query

QueryConstraint

Re-exports QueryConstraint

QueryConstraintType

Re-exports QueryConstraintType

remove

Re-exports remove

runTransaction

Re-exports runTransaction

set

Re-exports set

setPriority

Re-exports setPriority

setWithPriority

Re-exports setWithPriority

startAfter

Re-exports startAfter

startAt

Re-exports startAt

ThenableReference

Re-exports ThenableReference

TransactionOptions

Re-exports TransactionOptions

TransactionResult

Re-exports TransactionResult

Unsubscribe

Re-exports Unsubscribe

update

Re-exports update