edge-sql.js如何设置connectionString?

时间:2013-09-16 21:20:41

标签: sql-server node.js

var edge = require('edge');

var getProduct = edge.func('sql', function () {/*
    select * from Products 
    where ProductId = @myProductId
*/});

getProduct({ myProductId: 10 }, function (error, result) {
    if (error) throw error;
    console.log(result);
});

此代码运行良好,但我将ConnectionString设置为ENVIROMENT_VARIALBE感到不舒服!

set EDGE_SQL_CONNECTION_STRING=Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True

但我找不到另一种方法来做到这一点!即使在GitHub上,我也找不到另一种方法来设置ConnectionString!所以我想知道在OOB edge-sql.js中甚至可以在Code中设置ConnectionString吗?

2 个答案:

答案 0 :(得分:7)

在查看了edge-sql的SourceCode之后,我能够找到它是如何工作的,我想知道为什么在GitHub上用EnviromentVariable描述它?

无论如何这里是在node.js中设置ConnectionString的代码: - )

var edge = require('edge');

var params = {
    connectionString: "Data Source=localhost;Initial Catalog=ITSM_604;Integrated Security=True",
    source: "select top 1 last_name from account_contact"
};

var getContacts = edge.func('sql', params);

getContacts(null, function(error, result){
    if (error) throw error;
    console.log(result);
});

答案 1 :(得分:3)

显然(https://github.com/tjanczuk/edge/issues/65),你也可以内联:

var mySelect = edge.func('sql', {
    source: function () {/*
        select * from Product
    */},
    connectionString: 'your connection string goes here'
});

我也不喜欢环境变量技术。