【问题标题】:How to Update a table from another tables Insert script in Azure backend如何从另一个表更新一个表 在 Azure 后端插入脚本
【发布时间】:2016-06-01 06:52:02
【问题描述】:

我有一个 Xamarin.Forms 移动应用程序,它使用 Azure Easy Tables 设置并适用于所有 CRUD 操作。我现在需要一些 node.js 服务器端功能,这将使我能够从 tableA 上的插入脚本更新增加 tableB 中的列计数。即其中 tableB.someId = tableA.someId

到目前为止我有:

// INSERT into tableA
table.insert(function(context) {

logger.info('Running tableA.insert');

// get tableB
var tableB = azureMobileApps.tables.table('tableB');

// here i need to increase the noOfReviews column on tableB by one
............

我是 Azure node.js 的完整入门者,有人可以帮忙吗?

伊恩

【问题讨论】:

    标签: node.js azure azure-mobile-services


    【解决方案1】:

    您可以使用类似于以下内容的方式从其他表中加载记录:

    table.insert(function (context) {
        var tableB = context.tables('tableB');
        var tableBRecords = tableB.where({ id: 'someId' }).read()
            .then(function (records) {
                records[0].count++;
                return tableB.update(records[0]);
            })
            .then(context.execute);
    });
    

    您可以在http://azure.github.io/azure-mobile-apps-node/global.html#context 找到上下文对象的 API 文档。

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      根据我的理解,我认为您可以尝试执行自定义 SQL 语句来实现增加 tableB 列,该列的值计算 tableA 中的相关列,请参阅“如何:执行自定义 SQL 语句”部分文章https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/#CustomAPI

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-10
        • 1970-01-01
        • 2018-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多