Skip to content

Instantly share code, notes, and snippets.

@BolajiOlajide
Last active September 4, 2019 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BolajiOlajide/ea757da4b809d0c2dacbe1e9c408017e to your computer and use it in GitHub Desktop.
Save BolajiOlajide/ea757da4b809d0c2dacbe1e9c408017e to your computer and use it in GitHub Desktop.
Using sequelize cast
import Sequelize from 'sequelize';
const {
Op,
col: sequelizeCol,
cast: sequelizeCast
} = Sequelize;
// http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#static-method-cast
const valueCast = sequelizeCast(sequelizeCol('value'), 'int');
const settingsQuery = {
where: { name: { [Op.like]: '%QuotaMax' } },
attributes: ['name', [valueCast, 'value']],
order: [[valueCast, 'ASC']]
};
const scoreBands = await models.Setting.findAll(settingsQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment