本文整理汇总了TypeScript中firebase-functions.database类的典型用法代码示例。如果您正苦于以下问题:TypeScript database类的具体用法?TypeScript database怎么用?TypeScript database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了database类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: verifyJwtAndTransferResultToTrustedLocation
/** Untrusted report data for a PR */
const reportPath = `${tempFolder}/screenshot/reports/{prNumber}/${jwtFormat}/`;
/** Untrusted image data for a PR */
const imagePath = `${tempFolder}/screenshot/images/{prNumber}/${jwtFormat}/`;
/** Trusted report data for a PR */
const trustedReportPath = `screenshot/reports/{prNumber}`;
/**
* Copy valid data from /$temp/screenshot/reports/$prNumber/$secureToken/
* to /screenshot/reports/$prNumber
* Data copied: filenames(image results names), commit(github PR info),
* sha (github PR info), result (true or false for all the tests), travis job number
*/
const testDataPath = `${reportPath}/{dataType}`;
export let testData = firebaseFunctions.database.ref(testDataPath)
.onWrite((event: any) => {
const dataType = event.params.dataType;
if (dataTypes.includes(dataType)) {
return verifyJwtAndTransferResultToTrustedLocation(event, dataType);
}
});
/**
* Copy valid data from /$temp/screenshot/reports/$prNumber/$secureToken/
* to /screenshot/reports/$prNumber
* Data copied: test result for each file/test with ${filename}. The value should be true or false.
*/
const testResultsPath = `${reportPath}/results/{filename}`;
export let testResults = firebaseFunctions.database.ref(testResultsPath)
.onWrite((event: any) => {
示例2: while
name: transaction.name,
note: transaction.note || null,
recurring: change.after.key,
transfer: transaction.transfer || null
});
}
date = date.add(transaction.period);
} while (date.toFbString() <= transaction.end);
return true;
} else if (transaction.delete) {
let trRef = change.after.ref.parent.parent.child('transactions');
let snapshot = await trRef.orderByChild('date').startAt(transaction.delete).once('value');
let values = snapshot.val();
for (let key in values) {
if (values[key].recurring == change.after.key)
await snapshot.child(key).ref.remove();
}
await change.after.ref.child('delete').remove();
return true;
}
}
return false;
}
exports.handleRecurring = functions.database.ref('/{user}/accounts/{account}/recurring/{key}').onWrite(handleRecurring);
exports.createUser = functions.auth.user().onCreate(setupUser);
exports.removeUser = functions.auth.user().onDelete(removeUserData);
示例3: Date
import {WEBCAM_BUCKET, WEBCAM_FOLDER} from './constants'
import {mailLogHandler} from './mail-log-handler'
admin.initializeApp({
...functions.config().firebase,
databaseAuthVariableOverride: {
uid: 'fb-functions'
}
})
/**
* This function is responsible to monitor status change in realtime database
* and append appropriate log to realtime database.
* This does NOT handle have mail status change.
*/
export const logWriter = functions.database.ref('/status').onWrite(async event => {
const now = new Date()
const newStatus = event.data.val()
await logWriterHandler(newStatus, now, admin.database())
})
/**
* This function handles haveMail path change from realtime database
* and append change log to realtime database.
*/
export const mailLogWriter = functions.database.ref('/haveMail').onWrite(async event => {
const now = new Date()
const newStatus: boolean = event.data.val()
await mailLogHandler(newStatus, now, admin.database())
})
示例4: cleanUpPlayer
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
enum PlayerStatuses {
WAITING,
PLAYING,
OFFLINE,
NEW
}
exports.observePlayerChanges = functions.database.ref('players/{pushId}/')
.onUpdate(async (change: functions.Change<functions.database.DataSnapshot>, context: functions.EventContext) => {
const player = change.after.val();
switch(player.status) {
case PlayerStatuses.OFFLINE: {
return cleanUpPlayer(player, context.params.pushId)
.catch((reason) => {
console.error(`Was unable to clean up the user after they left. Details: ${reason}`);
})
}
case PlayerStatuses.PLAYING: {
break;
}
case PlayerStatuses.WAITING: {
return cleanUpPlayer(player, context.params.pushId)
.then(() => {
return findMatch(player, context.params.pushId)
.then(() => {
return change.after.ref.child('status').set(PlayerStatuses.PLAYING);
})
示例5: if
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
export const countUsers = functions.database
.ref('/connections/{connectionId}').onWrite(event => {
const collectionRef = event.data.ref.parent;
const countRef = collectionRef.parent.child('connections-count');
let increment;
if (event.data.exists() && !event.data.previous.exists()) {
increment = 1;
} else if (!event.data.exists() && event.data.previous.exists()) {
increment = -1;
} else {
return null;
}
// Return the promise from countRef.transaction() so our function
// waits for this async event to complete before it exits.
return countRef.transaction(current => {
return (current || 0) + increment;
}).then(() => console.log(`Counter updated.`));
});
export const connectedUsersCount = functions.database
.ref('/connections-count').onDelete(event => {
if (!event.data.exists()) {
const counterRef = event.data.ref;
const collectionRef = counterRef.parent.child('connections');