我正在尝试在读取表中的数据之前从另一个数据库获取数据。但是,我似乎找不到正确访问它的方法。
到目前为止,我得到的最好的是基于Microsoft的文档和StackOverflow的其他一些例子,但它们似乎都失败了。
table.read(function (context) {
var results = context.tables("table2").read();
var text = results[0].column;
context.query.where({ columnName: text });
return context.execute();
});
执行此操作时出现错误,说该列不存在。
根据您的描述,如果我没有误解,您想在 EasyTables 脚本中的 table1 操作中查询 table2。
我们可以利用"use()"
自定义中间件来指定要针对表的每个请求执行的中间件,如 Azure 移动应用 SDK 文档上的描述
例如
var queries = require('azure-mobile-apps/src/query');
var insertMiddleware = function(req,res,next){
var table = req.azureMobile.tables('table2'),
query = queries.create('table2')
.where({ TestProperty : req.body.testproperty });
table.read(query).then(function(results) {
if(results){
req.someStoreData = somehander(results); //some hander operations here to get what you want to store and will use in next step
next();
}else{
res.send("no data");
}
});
};
table.insert.use(insertMiddleware, table.operation);
table.insert(function (context) {
console.log(context.req.someStoreData);
return context.execute();
});
更多例子:
async function filterByAllowedDomain(context) {
var domains = await context.tables('domains')
.where({ allowed: true })
.read();
var categories = await context.tables('categories')
.where(function (ids) {
return this.domainId in ids;
}, domains.map(d => d.id))
.read();
context.query.where(function (ids) {
return this.categoryId in ids;
}, categories.map(c => c.id));
return context.execute(); }
azure-mobile-apps-node sdk 中的tables
模块包含用于将表添加到 Azure 移动应用的功能。它返回一个可以附加到快速应用程序的路由器,其中包含一些用于注册表的附加函数。它实际上利用了Azure SQL(Azure上的SQL Server数据库服务(。
希望对您有所帮助。