我正在通过Python选项编写Firebase的Cloud Function . 我对Firebase实时数据库触发器感兴趣;换句话说,我愿意倾听我的实时数据库中发生的事件 .
Python环境为处理实时数据库触发器提供以下签名:
def handleEvent(data, context):
# Triggered by a change to a Firebase RTDB reference.
# Args:
# data (dict): The event payload.
# context (google.cloud.functions.Context): Metadata for the event.
这看起来不错 . data
参数提供2个词典; 'data'
用于在更改前通知数据, 'delta'
用于更改位 .
将此签名与 Node.js
环境进行比较时会产生混淆 . 以下是来自 Node.js
世界的类似签名:
exports.handleEvent = functions.database.ref('/path/{objectId}/').onWrite((change, context) => {}
在此签名中, change
参数非常强大,似乎是 firebase.database.DataSnapshot
类型 . 它有很好的帮助方法,如 hasChild()
或 numChildren()
,它们提供有关已更改对象的信息 .
问题是:Python环境是否有类似的 DataSnapshot
对象?使用Python,我是否必须查询数据库以获取子项数例如?这真的不是't clear what Python environment can and can't .
相关API /参考/文档: