The Firebase Realtime Database reference builder interface.

Access via \[`functions.database.ref()`\](functions.database#.ref).

**Signature:**

    export declare class RefBuilder<Ref extends string> 

## Constructors

| Constructor | Modifiers | Description |
|---|---|---|
| [(constructor)(triggerResource, options)](https://firebase.google.com/docs/reference/functions/firebase-functions.database.refbuilder#databaserefbuilderconstructor) |   | Constructs a new instance of the `RefBuilder` class |

## Methods

| Method | Modifiers | Description |
|---|---|---|
| [onCreate(handler)](https://firebase.google.com/docs/reference/functions/firebase-functions.database.refbuilder#databaserefbuilderoncreate) |   | Event handler that fires every time new data is created in Firebase Realtime Database. |
| [onDelete(handler)](https://firebase.google.com/docs/reference/functions/firebase-functions.database.refbuilder#databaserefbuilderondelete) |   | Event handler that fires every time data is deleted from Firebase Realtime Database. |
| [onUpdate(handler)](https://firebase.google.com/docs/reference/functions/firebase-functions.database.refbuilder#databaserefbuilderonupdate) |   | Event handler that fires every time data is updated in Firebase Realtime Database. |
| [onWrite(handler)](https://firebase.google.com/docs/reference/functions/firebase-functions.database.refbuilder#databaserefbuilderonwrite) |   | Event handler that fires every time a Firebase Realtime Database write of any kind (creation, update, or delete) occurs. |

## database.RefBuilder.(constructor)

Constructs a new instance of the `RefBuilder` class

**Signature:**

    constructor(triggerResource: () => string | Expression<string>, options: DeploymentOptions);

### Parameters

| Parameter | Type | Description |
|---|---|---|
| triggerResource | () =\> string \| [Expression](https://firebase.google.com/docs/reference/functions/firebase-functions.params.expression#paramsexpression_class)\<string\> |   |
| options | [DeploymentOptions](https://firebase.google.com/docs/reference/functions/firebase-functions.deploymentoptions#deploymentoptions_interface) |   |

## database.RefBuilder.onCreate()

Event handler that fires every time new data is created in Firebase Realtime Database.

**Signature:**

    onCreate(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| handler | (snapshot: [DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class), context: [EventContext](https://firebase.google.com/docs/reference/functions/firebase-functions.eventcontext#eventcontext_interface)\<ParamsOf\<Ref\>\>) =\> PromiseLike\<any\> \| any | Event handler that runs every time new data is created in Firebase Realtime Database. |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/firebase-functions.cloudfunction#cloudfunction_interface)\<[DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class)\>

A function that you can export and deploy.

## database.RefBuilder.onDelete()

Event handler that fires every time data is deleted from Firebase Realtime Database.

**Signature:**

    onDelete(handler: (snapshot: DataSnapshot, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<DataSnapshot>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| handler | (snapshot: [DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class), context: [EventContext](https://firebase.google.com/docs/reference/functions/firebase-functions.eventcontext#eventcontext_interface)\<ParamsOf\<Ref\>\>) =\> PromiseLike\<any\> \| any | Event handler that runs every time data is deleted from Firebase Realtime Database. |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/firebase-functions.cloudfunction#cloudfunction_interface)\<[DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class)\>

A function that you can export and deploy.

## database.RefBuilder.onUpdate()

Event handler that fires every time data is updated in Firebase Realtime Database.

**Signature:**

    onUpdate(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| handler | (change: [Change](https://firebase.google.com/docs/reference/functions/firebase-functions.change#change_class)\<[DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class)\>, context: [EventContext](https://firebase.google.com/docs/reference/functions/firebase-functions.eventcontext#eventcontext_interface)\<ParamsOf\<Ref\>\>) =\> PromiseLike\<any\> \| any | Event handler which is run every time a Firebase Realtime Database write occurs. |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/firebase-functions.cloudfunction#cloudfunction_interface)\<[Change](https://firebase.google.com/docs/reference/functions/firebase-functions.change#change_class)\<[DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class)\>\>

A function which you can export and deploy.

## database.RefBuilder.onWrite()

Event handler that fires every time a Firebase Realtime Database write of any kind (creation, update, or delete) occurs.

**Signature:**

    onWrite(handler: (change: Change<DataSnapshot>, context: EventContext<ParamsOf<Ref>>) => PromiseLike<any> | any): CloudFunction<Change<DataSnapshot>>;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| handler | (change: [Change](https://firebase.google.com/docs/reference/functions/firebase-functions.change#change_class)\<[DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class)\>, context: [EventContext](https://firebase.google.com/docs/reference/functions/firebase-functions.eventcontext#eventcontext_interface)\<ParamsOf\<Ref\>\>) =\> PromiseLike\<any\> \| any | Event handler that runs every time a Firebase Realtime Database write occurs. |

**Returns:**

[CloudFunction](https://firebase.google.com/docs/reference/functions/firebase-functions.cloudfunction#cloudfunction_interface)\<[Change](https://firebase.google.com/docs/reference/functions/firebase-functions.change#change_class)\<[DataSnapshot](https://firebase.google.com/docs/reference/functions/firebase-functions.database.datasnapshot#databasedatasnapshot_class)\>\>

A function that you can export and deploy.