5
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 中是否可以在代码中设置 ConnectionString?

4

2 回答 2

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);
});
于 2013-09-17T07:39:35.360 回答
3

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

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

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

于 2013-11-03T03:51:42.103 回答