什么是此T-SQL查询的node.js等价物

时间:2016-08-05 02:08:33

标签: sql-server node.js string tsql sha1

遗留系统用于以查询的输出格式存储密码,

SELECT
    HASHBYTES('SHA1', CONVERT(VARCHAR, HASHBYTES('SHA1', CONVERT(NVARCHAR(4000), ’test'))) + 'mysalt')

其中密码为testmysalt是使用的盐。

结果类似于

0x169A0EF01AA369518D6810E14872A3A003A1F0AA

我必须使用该加密密码并创建节点函数以获得与上述查询相同的结果

1 个答案:

答案 0 :(得分:1)

Node.js不会替换t-sql查询。您仍然可以使用t-sql查询数据库,例如tedious模块与数据库的连接。这是https://msdn.microsoft.com/library/mt715784.aspx关于如何从node.js连接到SQL Server并执行查询的示例。对executeStatement函数的一些修改可以帮助你。

var Connection = require('tedious').Connection;  
    var config = {  
        userName: 'yourusername',  
        password: 'yourpassword',  
        server: 'yourserver.database.windows.net',  
        // When you connect to Azure SQL Database, you need these next options.  
        options: {encrypt: true, database: 'AdventureWorks'}  
    };  
    var connection = new Connection(config);  
    connection.on('connect', function(err) {  
        // If no error, then good to proceed.  
        console.log("Connected");  
        executeStatement();  
    });  

    var Request = require('tedious').Request;  
    var TYPES = require('tedious').TYPES;  

    function executeStatement() {  
        request = new Request("SELECT c.CustomerID, c.CompanyName,COUNT(soh.SalesOrderID) AS OrderCount FROM SalesLT.Customer AS c LEFT OUTER JOIN SalesLT.SalesOrderHeader AS soh ON c.CustomerID = soh.CustomerID GROUP BY c.CustomerID, c.CompanyName ORDER BY OrderCount DESC;", function(err) {  
        if (err) {  
            console.log(err);}  
        });  
        var result = "";  
        request.on('row', function(columns) {  
            columns.forEach(function(column) {  
              if (column.value === null) {  
                console.log('NULL');  
              } else {  
                result+= column.value + " ";  
              }  
            });  
            console.log(result);  
            result ="";  
        });  

        request.on('done', function(rowCount, more) {  
        console.log(rowCount + ' rows returned');  
        });  
        connection.execSql(request);  
    }