【问题标题】:Azure Functions read Azure Mobile App Easy table dataAzure Functions 读取 Azure Mobile App Easy 表数据
【发布时间】:2017-05-14 00:48:25
【问题描述】:

我正在尝试弄清楚如何设置与 Azure 函数的输入绑定,使其能够读取 Azure 移动应用程序简易表表中的所有数据。我已经搜索了几个小时并阅读了我能找到的所有文档。

https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings 处的 Azure Functions 绑定文档表明我可以为移动应用设置绑定 - 文档说这是用于访问表,我希望这意味着简单表,因为我认为这是唯一的表在移动应用程序中可用(或者我弄错了吗?)。在函数编辑器的集成部分中设置绑定时,甚至还有一个帮助选项。但是,当您设置绑定时,记录 ID 字段是必需的,但我不想指定记录 ID,我希望函数能够读取表中的所有数据。我该怎么做?

最终,我希望能够在表中的数据更新(添加、更新、删除)时触发该函数。当函数执行时,我想读取所有数据并对其进行处理。我找不到涵盖此问题的触发选项,因此我认为我将不得不将其设为预定功能 - 有没有更好的方法?

这是绑定:

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

绑定中的 id 属性在我的情况下不需要,但需要。我应该放什么让它发挥作用?

【问题讨论】:

    标签: azure azure-functions


    【解决方案1】:

    Easy Tables 还没有内置触发器类型。但是您可以使用最近添加的 Mobile Apps Easy Tables 的webhooks feature 来实现此场景。制作一个 HTTP 触发函数并配置 webhook 以调用该函数。如果您需要您的函数来更新简单表中的数据状态,您可以使用output binding 来执行此操作。

    如果您需要与函数中的数据进行更丰富的交互,那么您需要查看引用移动应用客户端 SDK NuGet 包并使用 MobileServiceClient 读取数据。这是一个例子:

    project.json:

    {
      "frameworks": {
        "net46":{
          "dependencies": {
            "Microsoft.Azure.Mobile.Client": "3.0.3"
          }
        }
      }
    }
    

    运行.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");    
    }
    

    【讨论】:

    • 保罗,谢谢。采取不同的策略,如何从函数中读取 Easy Table 表格内容?假设我想将此从触发函数迁移到计划函数,我需要做什么来配置函数以便它可以从表中提取记录(所有记录)?
    • 我更新了我的答案以演示使用 MobileServiceClient
    • 谢谢。你有 JavaScript(节点)示例吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 2022-07-21
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多