Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Type of field from sequelize model

Is it possible to get the datatype of a given field from a sequelize model. Assume we have a module defined like so

User = sequelize.define 'User',
{
 id:
   type: DataTypes.UUID
   primaryKey: true
   defaultValue: DataTypes.UUIDV4
 firstName:
   type: DataTypes.STRING
   allowNull: false
 middleName:
   type: DataTypes.STRING
   allowNull: true
   defaultValue: null
 lastName:
   type: DataTypes.STRING
   allowNull: true
   defaultValue: null
}

I need to say figure out the data type for firstName. Is there any method within model which can achieve this?

like image 738
sinjar Avatar asked Jan 21 '16 16:01

sinjar


1 Answers

You can access it this way:

User.tableAttributes.firstName.type.constructor.key
like image 185
Adam Avatar answered Sep 25 '22 15:09

Adam