【发布时间】:2015-11-09 07:44:31
【问题描述】:
Sequelize 可以和Redshift 一起使用吗?如果没有,有什么替代方案?我需要一个具有内置事务支持的 Node.js 的 ORM,因此 Sails.js 不是一个选项。我也查看了Bookshelf,但也找不到任何对 Redshift 的支持。
【问题讨论】:
标签: node.js sails.js sequelize.js amazon-redshift bookshelf.js
Sequelize 可以和Redshift 一起使用吗?如果没有,有什么替代方案?我需要一个具有内置事务支持的 Node.js 的 ORM,因此 Sails.js 不是一个选项。我也查看了Bookshelf,但也找不到任何对 Redshift 的支持。
【问题讨论】:
标签: node.js sails.js sequelize.js amazon-redshift bookshelf.js
Redshift 基于 postgres 8.0.2 (http://docs.aws.amazon.com/redshift/latest/dg/c_redshift-and-postgres-sql.html),因此 postgres 和 sequelize 都应该能够连接到它。
我没有任何个人经验,但 redshift 文档建议您可以使用常规 JDBC / ODBC 驱动程序连接到它,所以如果节点驱动程序不起作用,我会感到惊讶
【讨论】:
Sequelize 与 Redshift 不兼容。虽然 Redshift 是在 Postgres 之上编写的,但它是一个柱状数据库,并且主要的核心功能都被重写了。
尝试连接时出现错误“不支持设置时区”
以下线程显示了一些人覆盖时区错误但随后面临其他问题。 'Using Node 'pg' library to connect to Amazon Redshift
如果 Redshift 是强制性的,您可以使用 node-jdbc 包连接 Redshift https://github.com/CraZySacX/node-jdbc
如果 ORM 是强制性的,您应该尝试将数据存储移动到纯 Postgres
【讨论】:
我已经能够使用这些选项让 Sequelize 至少连接到 Redshift(并进行简单的 SELECT 查询):
var Sequelize = require('sequelize');
Sequelize.HSTORE.types.postgres.oids.push('dummy'); // avoid auto-detection and typarray/pg_type error
module.exports = new Sequelize(process.env.REDSHIFT_DATABASE, process.env.REDSHIFT_USER, process.env.REDSHIFT_PASSWORD, {
host: process.env.REDSHIFT_HOST,
port: process.env.REDSHIFT_PORT,
dialect: 'postgres',
pool: false,
keepDefaultTimezone: true, // avoid SET TIMEZONE
databaseVersion: '8.0.2' // avoid SHOW SERVER_VERSION
});
【讨论】:
目前我认为Sequelize 不是连接到 Redshift 的最佳选择。我建议你直接使用node-postgres 模块。
话虽如此,您可能已经有一个使用Sequelize 的项目并希望在这些情况下重用它,您可以执行以下操作。
const Sequelize = require('sequelize');
// sequelize config options documented at
// https://sequelize.org/master/class/lib/sequelize.js~Sequelize.html#instance-constructor-constructor
const config = {
dialect: 'postgres',
host: 'localhost',
port: 5439,
database: '',
username: '',
password: '',
dialectOptions: {
// either set to ssl to true or use the config options documented at
// https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
ssl: true
},
standardConformingStrings: false,
clientMinMessages: false
};
const redshift = new Sequelize(config);
const queryOpts = {type: sequelize.QueryTypes.SELECT, raw:true};
redshift.query('SELECT 1', queryOpts)
.then(console.log)
.catch(console.log);
这将生成以下弃用警告,因为 Redshift 基于 postgres 8.x,因此请考虑直接使用 pg 模块。
(node:5177) [SEQUELIZE0006] DeprecationWarning: This database engine version is not supported, please update your database server. More information https://github.com/sequelize/sequelize/blob/master/ENGINE.md
【讨论】:
SequelizeHostNotFoundError: getaddrinfo ENOTFOUND 我尝试使用端点和 jdbc,但什么也没有