此 T-SQL 查询的 node.js 等价物是什么
What is the node.js equivalent of this T-SQL query
用于以查询输出格式存储密码的旧系统,
SELECT
HASHBYTES('SHA1', CONVERT(VARCHAR, HASHBYTES('SHA1', CONVERT(NVARCHAR(4000), ’test'))) + 'mysalt')
其中密码是 test
,mysalt
是使用的盐。
结果类似于
0x169A0EF01AA369518D6810E14872A3A003A1F0AA
我必须使用那个加密的密码并创建一个节点函数来获得与上述查询相同的结果
Node.js 不会取代 t-sql 查询。您仍然会使用 t-sql 来查询您的数据库,并使用类似 tedious
module connection to the database. This is an example from https://msdn.microsoft.com/library/mt715784.aspx 的东西来了解如何从 node.js 连接到 SQL 服务器并执行查询。对 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);
}
用于以查询输出格式存储密码的旧系统,
SELECT
HASHBYTES('SHA1', CONVERT(VARCHAR, HASHBYTES('SHA1', CONVERT(NVARCHAR(4000), ’test'))) + 'mysalt')
其中密码是 test
,mysalt
是使用的盐。
结果类似于
0x169A0EF01AA369518D6810E14872A3A003A1F0AA
我必须使用那个加密的密码并创建一个节点函数来获得与上述查询相同的结果
Node.js 不会取代 t-sql 查询。您仍然会使用 t-sql 来查询您的数据库,并使用类似 tedious
module connection to the database. This is an example from https://msdn.microsoft.com/library/mt715784.aspx 的东西来了解如何从 node.js 连接到 SQL 服务器并执行查询。对 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);
}