Sequelize模型不区分大小写

时间:2017-02-08 19:02:42

标签: postgresql sequelize.js amazon-redshift

我正在使用sequelize在Redshift中进行查询。

但是Redshift对表列名称不区分大小写,因此所有表名都是小写的。 续集模型不区分大小写。所以当我查询findById时,它执行这个查询:

SELECT "id", "userId", "summonerId", "name", "profileIconId", "summonerLevel", "revisionDate", "createdAt", "updatedAt" FROM "Lol" AS "Lol" WHERE "Lol"."id" = '463d118c-2139-4679-8cdb-d07249bd7777222';

如果我在Redshift中执行查询,它会起作用,但是sequelize只会让我返回id和name列名,因为只有在模型中名称为小写。

那我怎么能让sequelize不区分大小写呢?我尝试了field选项,但没有用。

所以我的模型是:

lol = sequelize.define('Lol', {
                id: {
                    type: Sequelize.STRING,
                    allowNull: false,
                    unique: true,
                    primaryKey: true,
                    field: 'id'
                },
                userId: {
                    type: Sequelize.STRING,
                    allowNull: false,
                    field: 'userid'
                },
                summonerId: {
                    type: Sequelize.INTEGER,
                    allowNull: false,
                    field: 'summonerid'
                },
                name: {
                    type: Sequelize.STRING,
                    allowNull: false,
                    field: 'name'
                },
                profileIconId: {
                    type: Sequelize.INTEGER,
                    allowNull: false,
                    field: 'profileiconid'
                },
                summonerLevel: {
                    type: Sequelize.INTEGER,
                    allowNull: false,
                    field: 'summonerlevel'
                },
                revisionDate: {
                    type: Sequelize.BIGINT,
                    allowNull: false,
                    field: 'revisiondate'
                },
                createdAt: {
                    type: Sequelize.DATE,
                    allowNull: false,
                    field: 'createdat'
                },
                updatedAt: {
                    type: Sequelize.DATE,
                    allowNull: false,
                    field: 'updatedat'
                }
            }, {
                freezeTableName: true,
                tableName: 'Lol'
            })

1 个答案:

答案 0 :(得分:3)

找到了一条路。

现在我的完整设置是让Redshift与Sequelize一起工作:

var Sequelize = require('sequelize');
Sequelize.HSTORE.types.postgres.oids.push('dummy'); // avoid auto-detection and typarray/pg_type error
AWS.config.update({accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey', region: "xxxxxx"});
var sequelize = new Sequelize('database', 'username', 'password', {
    host: 'hostname',
    dialect: 'postgres',
    port: '5439',
    pool: {
        max: 10,
        min: 0,
        idle: 20000
    },
    returning: false, // cause sql error
    quoteIdentifiers: false, // set case-insensitive
    keepDefaultTimezone: true, // avoid SET TIMEZONE
    databaseVersion: '8.0.2' // avoid SHOW SERVER_VERSION

});