'非稳态' Node中的Seriate模块的语法

时间:2016-05-11 09:24:55

标签: sql-server node.js node-seriate

我有一个对象我想插入我MSSQL数据库的表格中。

根据github上的Seriate docs,这不应该是一个问题。

我的设置如下:

apiRoute.js

module.exports = function(express, schema) {

    var apiRoute = express.Router();

    apiRoute.post('/test-path', function(req, res) {

        schema.test()
        .then(function(results) {
            res.json(results);
        }, function(err) {
           res.json(err); 
        });
    });

    return apiRoute;

}

schema.js

var sql     = require('seriate');
var when    = require('when');



var test = function() {    
    return sql.execute({
        query: "select * from @children",
        params: { 
            children: {
                val: [
                    { id: 1, firstName: "James", middleName: "Paul"},
                    { id: 2, firstName: "John", middleName: "Winston" },
                    { id: 3, firstName: "George", middleName: "Harold" },
                    { id: 4, firstName: "Richard", middleName: "Parkin" }
                ],
                asTable: {
                    id: sql.INT,
                    firstName: sql.NVARCHAR(50),
                    middleName: sql.NVARCHAR(50)
                }
            }
        }
    });
}

module.exports = {
    test: test
}

当我使用Postman进行测试时,请求会一直持续到最终只是超时。

如果我只是在没有asTable部分的情况下执行查询:

 select 1

它运作得很好。

我错过了什么?

1 个答案:

答案 0 :(得分:0)

Have you tried using .step

and this:

result.transaction .commit()

I had the same problem, but when I revised using this method it ran through fine, but you'll need to add a terminary function as well to stop (i.e., callback function, .end, etc.).

Let me know if this doesn't make sense, and I'll post the entire sample code.