Azure Functions读取Azure Mobile App Easy表数据 [英] Azure Functions read Azure Mobile App Easy table data

查看:68
本文介绍了Azure Functions读取Azure Mobile App Easy表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何设置与Azure函数的输入绑定,使它能够读取Azure Mobile App Easy表表中的所有数据.我一直在寻找时间,并阅读所有可以找到的文档.

I'm trying to figure out how to setup an input binding to an Azure Function that enables it to read all of the data in an Azure Mobile App Easy tables table. I've been searching for hours and reading every bit of documentation that I can find.

位于 https:/上的Azure函数绑定文档/docs.microsoft.com/zh-CN/azure/azure-functions/functions-triggers-bindings 表示我可以为Mobile Apps设置绑定-文档说这是用于访问表的,我希望这意味着简易表格,因为我认为这是移动应用程序中唯一可用的表格(或者我误会了吗?).在函数"编辑器的集成"部分中设置绑定时,甚至还有一个帮助程序选项.但是,在设置绑定时,记录ID"字段是必需的,但是我不想指定记录ID,我希望函数能够读取表中的所有数据.我该怎么办?

The Azure Functions binding docs at https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings indicate that I can setup a binding for Mobile Apps - the docs says this is for accessing tables, I hope it means Easy tables because that is, I think, the only kind of tables available in a mobile app (or am I mistaken?). There's even a helper option when setting up the binding in the Integrations section of the Functions editor. However, when you setup the binding, the Record ID field is required, but I don't want to specify a record ID, I want the function to be able to read all of the data in the table. How do I do this?

最终,我想要做的就是每当表中的数据更新(添加,更新,删除)时触发该函数.函数执行时,我想读取所有数据并对其进行处理.我找不到涵盖此内容的触发器选项,所以我认为我必须将其设置为计划函数-有更好的方法吗?

Ultimately, what I want to be able to do is trigger the function whenever data in the table is updated (add, update, delete). When the function executes, I want to read all of the data and do something with it. I can't find a trigger option that covers this, so I think I'm going to have to just make this a scheduled function - is there a better way?

这里是绑定:

{
  "type": "mobileTable",
  "name": "inputRecord",
  "tableName": "Alerts",
  "id": "{itemId}",
  "connection": "APP_URL",
  "direction": "in"
}

在我的情况下,绑定中的id属性是不需要的,但它是必需的.我在那里放置什么才能使其正常工作?

It's the id property in the binding that's not needed in my case, but required. What do I put there to make it work?

推荐答案

Easy Tables还没有内置的触发器类型.但是您可以使用最近添加的

There is no built in trigger type for Easy Tables yet. But you can achieve this scenario using the recently added 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 to do that.

如果您需要与函数中的数据进行更丰富的交互,那么您将需要参考Mobile App客户端SDK NuGet包,并使用MobileServiceClient读取数据.这是一个示例:

If you need richer interaction with the data from the function then you'll want to look at referencing the Mobile Apps client SDK NuGet package and use the MobileServiceClient to read the data. Here's an example:

project.json:

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 Functions读取Azure Mobile App Easy表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆