2016-06-23 13 views
0

AzureのEasy APIを使用して、Azureのクエリの結果を解析する方法を知りたいですか?私にとっては、関数(結果)の内部にオブジェクトを作成すると無限ループになり、最終的にhttpcode 500が返されるようです。 助けてください。結果を解析し、それをJavascriptオブジェクトに格納し、その結果をJsonとして返す方法が必要です。ノードjsのazureテーブルの結果を解析する方法

var azureMobileApps = require('azure-mobile-apps'); 
var queries = require('azure-mobile-apps/src/query'); 

var api = { 
     get: (req, res, next) => { 
      if(Object.keys(req.query).length === 0) { 
      res.status(400).type('text/plain').send("Error! Please add event id"); 
      return; 
      } 

     if(req.query.eventId === 'undefined' || req.query.eventId.length === 0) { 
      res.status(400).type('text/plain').send("Error! missing eventId parameter"); 
      console.log("worked!"); 
      return;  
     } 
     var query = { 
      sql: 'Select .... where [email protected]' 
      , 
      parameters: [ 
       { name: 'eventId', value: req.query.eventId } 
      ] 
     }; 

     req.azureMobile.data.execute(query) 
      .then(function (results) { 
       TODO: here! Parse results, add properties to objects and then return that instead! 
       res.status(200).type('application/json').send({sessions: results}); 
      },function(error){ 
       console.log('Found an error: ', error); 
      }); 
    } 
}; 

api.get.access = 'authenticated'; 
module.exports = api; 
+0

こんにちは、今問題を解決しましたか?アップデートがある場合は、私に知らせてください。 –

答えて

2

コードスニペットに問題はありません。 node.jsバックエンドモバイルアプリでは、req.azureMobile.data.execute(query)は照会された結果の配列リストを返します。 Azure Dev Teamが提供するGitHub https://github.com/Azure/azure-mobile-apps-node/blob/master/samples/custom-api-sql-stmt/api/completeall.jsのコードサンプルを示します。

Node.jsのモバイルアプリケーションは、Expressjsフレームワークに基づいています。 res.json(obj)を使用するだけで、jsonレスポンスを直接返すことができます。

問題がある場合は、通常、stmt例外により問題が発生します。 queryオブジェクトがデータを照会する前に正しいかどうかを再度確認してください。

nodejsバックエンドモバイルアプリケーションのトラブルシューティングには、Visual Studio Team Services(Visual Studio Online)を使用できます。

さらに詳しい内容はお気軽にお問い合わせください。

関連する問題