SQL表上的Azure移动应用CRUD操作(node.js后端) [英] Azure mobile apps CRUD operations on SQL table (node.js backend)

查看:74
本文介绍了SQL表上的Azure移动应用CRUD操作(node.js后端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里的第一篇文章,因此,如果我的格式有点过错,请不要生气;-) 我正在尝试使用Azure移动应用程序和用于服务器端脚本的node.js开发后端解决方案.这是一条陡峭的曲线,因为我是来自嵌入式世界的javaScript和node.js的新手.我所做的是一个可以将用户添加到MSSQL表的自定义API,使用该表对象可以正常工作.但是,我还需要能够从同一表中删除用户.我添加用户的代码是:

This is my first post here so please don't get mad if my formatting is a bit off ;-) I'm trying to develop a backend solution using Azure mobile apps and node.js for server side scripts. It is a steep curve as I am new to javaScript and node.js coming from the embedded world. What I have made is a custom API that can add users to a MSSQL table, which is working fine using the tables object. However, I also need to be able to delete users from the same table. My code for adding a user is:

var userTable = req.azureMobile.tables('MyfUserInfo');
item.id = uuid.v4();

userTable.insert(item).then( function (){
    console.log("inserted data");
    res.status(200).send(item);
});

有效. Azure node.js文档的状态确实不佳,我一直在寻找有关如何做简单事情的良好示例.相当烦人和耗时. 有关删除操作的SDK文档说它的工作方式与读取相同,但事实并非如此.或我像个潮湿的门一样愚蠢.我的删除代码如下所示-导致异常

It works. The Azure node.js documentation is really not in good shape and I keep searching for good example on how to do simple things. Pretty annoying and time consuming. The SDK documentation on delete operations says it works the same way as read, but that is not true. Or I am dumb as a wet door. My code for deleting looks like this - it results in exception

query = queries.create('MyfUserInfo')
        .where({ id: results[i].id });

userTable.delete(query).then( function(delet){
console.log("deleted id ", delet);
});

我也尝试过,也没有成功

I have also tried this and no success either

userTable.where({ id: item.id }).read()
        .then( function(results) {
        if (results.length > 0) 
        {
            for (var i = 0; i < results.length; i++)
            {
                userTable.delete(results[i].id);
                });
            }
        }

有人可以为我指出正确语法的正确方向,并解释为什么在这里做基本工作这么困难;-)似乎有很多方法可以做完全相同的事情,实际上使我感到困惑. 非常感谢 马丁

Can somebody please point me in the right direction on the correct syntax for this and explain why it has to be so difficult doing basic stuff here ;-) It seems like there are many ways of doing the exact same thing, which really confuses me. Thanks alot Martin

推荐答案

您可以在api中发布SQL

You could issue SQL in your api

var api = {
get: (request, response, next) => {
    var query = {
        sql: 'UPDATE TodoItem SET complete=@completed',
        parameters: [
            { name: 'completed', value: request.params.completed }
        ]
    };

    request.azureMobile.data.execute(query)
    .then(function (results) {
        response.json(results);
    });
}};
module.exports = api;

那是从他们在示例的完整列表在

That is from their sample on GitHub Here is the full list of samples to take a look at

这篇关于SQL表上的Azure移动应用CRUD操作(node.js后端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆