When defining a model you can just as easily pass a string as type, but often using the types defined here
is
beneficial. For example, using DataTypes.BLOB, mean that that column will be returned as an instance of
Buffer when being fetched by sequelize.
Some data types have special properties that can be accessed in order to change the data type.
For example, to get an unsigned integer with zerofill you can do DataTypes.INTEGER.UNSIGNED.ZEROFILL.
The order you access the properties in do not matter, so DataTypes.INTEGER.ZEROFILL.UNSIGNED is fine as
well. The available properties are listed under each data type.
To provide a length for the data type, you can invoke it like a function: INTEGER(2)
Three of the values provided here (NOW, UUIDV1 and UUIDV4) are special default values, that should not
be used to define types. Instead they are used as shorthands for defining default values. For example, to
get a uuid field with a default value generated following v1 of the UUID standard:
A convenience class holding commonly used data types. The datatypes are used when definining a new model using
Sequelize.define
, like this:sequelize.define('model', { column: DataTypes.INTEGER })
When defining a model you can just as easily pass a string as type, but often using the types defined here is beneficial. For example, using
DataTypes.BLOB
, mean that that column will be returned as an instance ofBuffer
when being fetched by sequelize.Some data types have special properties that can be accessed in order to change the data type. For example, to get an unsigned integer with zerofill you can do
DataTypes.INTEGER.UNSIGNED.ZEROFILL
. The order you access the properties in do not matter, soDataTypes.INTEGER.ZEROFILL.UNSIGNED
is fine as well. The available properties are listed under each data type.To provide a length for the data type, you can invoke it like a function:
INTEGER(2)
Three of the values provided here (
NOW
,UUIDV1
andUUIDV4
) are special default values, that should not be used to define types. Instead they are used as shorthands for defining default values. For example, to get a uuid field with a default value generated following v1 of the UUID standard:sequelize.define('model', { uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV1, primaryKey: true } })