使用 SQL 在移动应用程序 Node.js 后端实施 table 加入
Implementing table joins in the Mobile Apps Node.js backend using SQL
由于 Azure 移动应用程序不提供在 table 之间创建关系的方法,我决定在我的 Node.js 后端创建自定义 API 到 return 数据来自相关 tables。这个想法是使用 SQL 在后端实现连接,就像在 Mobile Services Doc.
中解释的那样
问题是我使用的是新的移动应用程序而不是旧的移动服务,所以上面的代码不再有效。据我了解,架构从移动服务更改为移动应用程序,Node.js SDK 是一个快速中间件包。所以现在我们利用 azure-mobile-apps/src/data 模块来处理 sql 操作。
所以我现在必须做这样的事情来读取节点后端内自定义 API 中的 table:
var queries = require('azure-mobile-apps/src/query');
module.exports = {
"get": function (req, res, next) {
var myTable = req.azureMobile.tables('TableName');
var query = queries.create('TableName');
query.where({'id':req.query.userId});
myTable.read(query).then(function(data){
res.send({ some: data });
});
}
};
但是由于 SQL 不再公开,我无法使用 JOIN 命令从相关 table 中获取 return 数据。我将不得不使用循环和对数据库的许多请求,这违背了目的。
-有没有办法在新的移动应用 Node.js SDK 上使用 SQL 在后端实现连接?或者其他更好的方法?
非常感谢!
您可以生成 join
sql stmt 并利用可以包含 sql stmt 的 sqlQuery
对象,然后将 data.execute function to directlu execute the sql stmt. You can refer to the sample https://github.com/Azure/azure-mobile-apps-node/blob/master/samples/custom-api-sql-stmt/api/completeall.js 用于类似的场景.
同时,您可以在 Azure SQL 数据库中创建包含连接 stmt 的视图 table,以便在 Easy APIs 脚本中轻松使用并维护视图 SQL stmt。
由于 Azure 移动应用程序不提供在 table 之间创建关系的方法,我决定在我的 Node.js 后端创建自定义 API 到 return 数据来自相关 tables。这个想法是使用 SQL 在后端实现连接,就像在 Mobile Services Doc.
中解释的那样问题是我使用的是新的移动应用程序而不是旧的移动服务,所以上面的代码不再有效。据我了解,架构从移动服务更改为移动应用程序,Node.js SDK 是一个快速中间件包。所以现在我们利用 azure-mobile-apps/src/data 模块来处理 sql 操作。
所以我现在必须做这样的事情来读取节点后端内自定义 API 中的 table:
var queries = require('azure-mobile-apps/src/query');
module.exports = {
"get": function (req, res, next) {
var myTable = req.azureMobile.tables('TableName');
var query = queries.create('TableName');
query.where({'id':req.query.userId});
myTable.read(query).then(function(data){
res.send({ some: data });
});
}
};
但是由于 SQL 不再公开,我无法使用 JOIN 命令从相关 table 中获取 return 数据。我将不得不使用循环和对数据库的许多请求,这违背了目的。
-有没有办法在新的移动应用 Node.js SDK 上使用 SQL 在后端实现连接?或者其他更好的方法?
非常感谢!
您可以生成 join
sql stmt 并利用可以包含 sql stmt 的 sqlQuery
对象,然后将 data.execute function to directlu execute the sql stmt. You can refer to the sample https://github.com/Azure/azure-mobile-apps-node/blob/master/samples/custom-api-sql-stmt/api/completeall.js 用于类似的场景.
同时,您可以在 Azure SQL 数据库中创建包含连接 stmt 的视图 table,以便在 Easy APIs 脚本中轻松使用并维护视图 SQL stmt。