azure easy tables custom api

时间:2016-10-14 14:58:50

标签: mysql .net windows azure

我在this帖子中读到,简单表可以具有关联数据库功能,如连接等,用于在查询数据时组合表。不幸的是,我还没有找到很多关于如何做到这一点。

在我的情况下,我有一个简单的表用户和另一个被称为主题选择的共同userid属性,我需要根据这两个表中的信息在移动服务应用中检索信息。

我该怎么做?

2 个答案:

答案 0 :(得分:3)

根据您的描述,我按照此tutorial开始使用Azure移动应用程序的简易表。在我看来,Easy Tables可以为您提供一种为您的移动应用程序添加后端数据存储的简单方法。

我们可以将操作包装到特定的表中,如下所示:

public class UserDataService
{
    MobileServiceClient mobileService;
    IMobileServiceTable<User> userTable;

    public void Initialize()
    {
        mobileService= new MobileServiceClient("http://<your-mobileapp-name>.azurewebsites.net/");
        userTable = mobileService.GetTable<User>();
    }

    public async Task<User> GetUserAsync(string uid)
    {
        return await this.userTable.LoolupAsync(uid);
    }

    public async Task AddUserAsync(User user)
    {
        await this.userTable.InsertAsync(user);
    }
}
  

简易表可以具有关联数据库功能,例如连接等,用于在查询数据时组合表。

据我所知,您可以在Easy Table中添加外键来创建关系。但是,您无法在单个查询中从多个表中检索数据。对于您的方案,您可以调用方法UserDataService.GetUserAsync和SubjectChoiceDataService.GetByUserIdAsync来按预期聚合数据。

答案 1 :(得分:3)

您可以从easy api脚本编辑器中操作easy tables查询。

您将看到每个&#34; easy table&#34;的.json和.js文件。你创造了。将有一个注释的table.read函数,其签名与我下面的示例相同。取消注释此功能并修改内容允许任何类型的自定义操作服务器端。

所以要做一个&#34;加入&#34;您可以自己从两个表中获取记录,然后返回&#34;组合&#34; json对象。

以下是从存储中获取数据并决定何时返回的示例:

table.read(function (context) {
 var response = context.execute();
 response.then(function (records)
     {
        console.log("Records Fetched: " , records);
        // HERE YOU CAN MESS WITH THE DATA
        context.res.status(200).send(records);
        context.done();
     }, function (error)
     {
         console.log(error);
         context.res.status(500).send(error);
             context.done();
     });
});
相关问题