2016-10-14 84 views
3

我在this後閱讀,簡單的表可以有關係數據庫的功能,如聯合等查詢數據時組合表。不幸的是,我一直無法找到如何去做這件事。天青易桌自定義api

在我的情況下,我有一個簡單的表用戶和另一個被稱爲主題選擇具有共同的userid屬性,我需要檢索基於這兩個表中的信息的移動服務應用程序中的信息。

我該如何解決這個問題?

回答

2

您可以從easy api腳本編輯器中操作easy表查詢。

您將看到每個您創建的「簡單表格」的.json和.js文件。將會有一個帶有相同簽名的註釋table.read函數,如下面的示例。取消註釋該功能並修改內容可以讓任何類型的自定義操作服務器端。

所以要做一個「加入」,你可以自己從兩個表中獲取記錄,然後返回一個「組合的」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(); 
    }); 
}); 
3

根據你的描述,我按照這個tutorial開始使用Easy Tables of Azure Mobile App。在我看來,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方法來按預期方式聚合數據。