【发布时间】:2016-10-11 10:24:31
【问题描述】:
这是我第一次使用 SO。我来到这里是因为我最近迁移到了新的 Microsoft Azure 应用服务,并且似乎 node.js 语法等已更改或略有不同。这是我当前使用旧移动服务的代码,我希望迁移到新语法。关于什么变化等方面的参考资料非常有限,我在谷歌上也找不到太多。
function insert(item, user, request) {
var table = tables.getTable('user');
table.where({
userid: item.userid
}).read({
success: upsertItem
});
function upsertItem(existingItems) {
if (existingItems.length > 0) {
item.id = existingItems[0].id;
table.update(item, {
success: function(updatedItem) {
request.respond(200, updatedItem)
}
});
} else {
request.execute();
}
}
}
这是新脚本的示例
var table = module.exports = require('azure-mobile-apps').table();
table.read(function (context) {
return context.execute();
});
我也看过这篇文章,但没有帮助
Azure mobile apps CRUD operations on SQL table (node.js backend)
我的目标是按照我的原始代码执行 UPSERT。如果您可以通过提供确切的转换来帮助我,那将是我的首选答案。
提前感谢您的帮助。
【问题讨论】:
标签: node.js azure azure-mobile-services