Sri*_*amy 7 amazon-web-services node.js amazon-redshift aws-lambda
我无法使用 Node.js 连接到 redshift 数据库。我正在使用 Node JS 版本14.15.1。这个版本有什么问题吗?
以下代码,我在我的本地机器上尝试过,
redshift.js文件
var Redshift = require('node-redshift');
var client = {
user: 'user',
database: 'db',
password: 'password',
port: port,
host: 'hostname',
};
var redshiftClient = new Redshift(client, {rawConnection:true});
module.exports = redshiftClient;
Run Code Online (Sandbox Code Playgroud)
index.js以下是从数据库、文件中获取值的代码
var redshiftClient = require('./redshift.js');
console.log('Before Connection');
redshiftClient.connect(function(err){
console.log('After Connection');
if(err) throw err;
else{
redshiftClient.query('SELECT * FROM "customer"', {raw: true}, function(err, data){
if(err) throw err;
else{
console.log(data);
redshiftClient.close();
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
如果我运行这段代码没有得到错误,甚至这一行也没有被执行console.log('After Connection');
该软件包似乎有点被遗弃,因为这是一个具有确切问题的开放问题
要解决这个问题,您需要手动应用此解决方案
转到node_modules/node-redshift并替换
"dependencies": {
"commander": "^2.9.0",
"migrate": "^0.2.2",
"pg": "^6.1.2",
"sql-bricks": "^1.2.3"
},
Run Code Online (Sandbox Code Playgroud)
进入package.json
"dependencies": {
"commander": "^2.9.0",
"migrate": "^0.2.2",
"pg": "^8.1.5",
"sql-bricks": "^1.2.3"
},
Run Code Online (Sandbox Code Playgroud)
在此目录中运行npm install以更新此包。之后你的代码就可以工作了
| 归档时间: |
|
| 查看次数: |
3910 次 |
| 最近记录: |