Azure Functions 读取 Azure Mobile App Easy table 数据
Azure Functions read Azure Mobile App Easy table data
我正在尝试弄清楚如何设置到 Azure 函数的输入绑定,使其能够读取 Azure 移动应用程序 Easy tables table 中的所有数据。我一直在搜索几个小时并阅读我能找到的所有文档。
位于 https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings 的 Azure Functions 绑定文档表明我可以为移动应用程序设置绑定 - 文档说这是为了访问 tables,我希望这意味着简单 tables 因为我认为这是移动应用程序中唯一可用的 tables 类型(或者我弄错了?)。在函数编辑器的集成部分设置绑定时,甚至还有一个帮助选项。但是,当您设置绑定时,记录 ID 字段是必需的,但我不想指定记录 ID,我希望函数能够读取 table 中的所有数据。我该怎么做?
最终,我希望能够在 table 中的数据更新(添加、更新、删除)时触发该函数。当函数执行时,我想读取所有数据并对其进行处理。我找不到涵盖此的触发选项,所以我想我将不得不将其设为预定功能 - 有更好的方法吗?
绑定如下:
{
"type": "mobileTable",
"name": "inputRecord",
"tableName": "Alerts",
"id": "{itemId}",
"connection": "APP_URL",
"direction": "in"
}
绑定中的 ID 属性 在我的情况下不需要,但需要。我要放什么才能让它发挥作用?
Easy Tables 还没有内置触发器类型。但是您可以使用最近添加的 webhooks feature of Mobile Apps Easy Tables. Make a HTTP triggered function and configure the webhook to call the function. If you need your function to update the state of the data in easy tables, you can use an output binding 来实现这种情况。
如果您需要与函数中的数据进行更丰富的交互,那么您需要查看引用移动应用程序客户端 SDK NuGet 包并使用 MobileServiceClient 读取数据。这是一个例子:
project.json:
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.Mobile.Client": "3.0.3"
}
}
}
}
run.csx:
using System.Net;
using Microsoft.WindowsAzure.MobileServices;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
MobileServiceClient client = new MobileServiceClient("https://mymobileappssite.azurewebsites.net");
var results = await client.GetTable("todoitem").ReadAsync("");
log.Info($"Got {results.Count()} record(s).");;
return req.CreateResponse(HttpStatusCode.OK, "Hi");
}
我正在尝试弄清楚如何设置到 Azure 函数的输入绑定,使其能够读取 Azure 移动应用程序 Easy tables table 中的所有数据。我一直在搜索几个小时并阅读我能找到的所有文档。
位于 https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings 的 Azure Functions 绑定文档表明我可以为移动应用程序设置绑定 - 文档说这是为了访问 tables,我希望这意味着简单 tables 因为我认为这是移动应用程序中唯一可用的 tables 类型(或者我弄错了?)。在函数编辑器的集成部分设置绑定时,甚至还有一个帮助选项。但是,当您设置绑定时,记录 ID 字段是必需的,但我不想指定记录 ID,我希望函数能够读取 table 中的所有数据。我该怎么做?
最终,我希望能够在 table 中的数据更新(添加、更新、删除)时触发该函数。当函数执行时,我想读取所有数据并对其进行处理。我找不到涵盖此的触发选项,所以我想我将不得不将其设为预定功能 - 有更好的方法吗?
绑定如下:
{
"type": "mobileTable",
"name": "inputRecord",
"tableName": "Alerts",
"id": "{itemId}",
"connection": "APP_URL",
"direction": "in"
}
绑定中的 ID 属性 在我的情况下不需要,但需要。我要放什么才能让它发挥作用?
Easy Tables 还没有内置触发器类型。但是您可以使用最近添加的 webhooks feature of Mobile Apps Easy Tables. Make a HTTP triggered function and configure the webhook to call the function. If you need your function to update the state of the data in easy tables, you can use an output binding 来实现这种情况。
如果您需要与函数中的数据进行更丰富的交互,那么您需要查看引用移动应用程序客户端 SDK NuGet 包并使用 MobileServiceClient 读取数据。这是一个例子:
project.json:
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.Mobile.Client": "3.0.3"
}
}
}
}
run.csx:
using System.Net;
using Microsoft.WindowsAzure.MobileServices;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
MobileServiceClient client = new MobileServiceClient("https://mymobileappssite.azurewebsites.net");
var results = await client.GetTable("todoitem").ReadAsync("");
log.Info($"Got {results.Count()} record(s).");;
return req.CreateResponse(HttpStatusCode.OK, "Hi");
}