Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize model case insensitive

Tags:

I am using sequelize to make query in Redshift.

However Redshift is case-insensitive for Table Column Names, so all table names are lowercase. And sequelize model isnt case-insensitive. So when I do a query findById, it execute this query:

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

It works if I execute the query inside Redshift, but sequelize just bring me back id and name column names, because only that have the name lowercase in model.

So how I can make sequelize case-insensitive? I tried the field option, but doesnt work.

So my model is:

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'
            })
like image 857
Marckaraujo Avatar asked Feb 08 '17 19:02

Marckaraujo


1 Answers

Found a way.

Here is now my full setting to make Redshift work with 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

});
like image 175
Marckaraujo Avatar answered Oct 11 '22 12:10

Marckaraujo