简体   繁体   中英

Return Upper Case Column Names from Sequelize Raw MSSQL Query

I'd like to have Sequelize MSSQL raw queries return column names as upper case object attributes. I'm not seeing a config for this in the documentation.

Example:

sequelize.query(sql, opts).then((results) => {
  console.log(results[0]);
});

What I get: // { foo: "bar", baz_pop: "boop" }

What I need: // { FOO: "bar", BAZ_POP: "boop" }

You can use any appropriate SQL when executing query() so you can use UPPER

Example:

await sequelize.query("SELECT UPPER(name) As name FROM departments", { type: Sequelize.QueryTypes.SELECT });

Yields the same SQL:

SELECT UPPER(name) AS name FROM departments

Results:

[ { name: 'DEPT 1' } ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM