【问题标题】:Azure Mobile Services Prevent duplicate entriesAzure 移动服务 防止重复条目
【发布时间】:2016-09-13 01:38:01
【问题描述】:

我正在使用带有 Easy Tables 的 Azure 移动服务,并希望防止基于特定列(名称)将重复条目插入到我的一个表中。我知道主键必须在 Id 列上,因此我希望更改 Azure 上的 javascript 文件以检查该列中是否已存在数据,如果存在则阻止新记录。

这是我目前所拥有的:

Table.js

var table = module.exports = require('azure-mobile-apps').table();

    table.insert(function (context) {
        // Check for duplicate on name column

    });

【问题讨论】:

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


    【解决方案1】:

    尝试以下方法:

    var table = module.exports = require('azure-mobile-apps').table();
    
    table.insert(function (context) {
        return table.read({ name: context.item.name }).then(function (results) {
            if(results.length > 0)
                context.res.status(400).send("A record with that name already exists");
            else
                return context.execute();
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 2015-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多