Reputation: 222344
I've previously used a recipe for model definitions very similar to the one from Sequelize documentation, where model definitions are wrapped with factory functions to be fed to sequelize.import
:
module.exports = (sequelize, DataTypes) => {
return sequelize.define('SomeModel', {
field: DataTypes.STRING(100)
});
};
This structure works for me but it is not always convenient to export wrapper function from the module (e.g. when it exports a class for base model that uses DataTypes
but shouldn't be imported with sequelize.import
).
Is Sequelize
fully interchangeable with DataTypes
for data types (DataTypes.STRING
vs Sequelize.STRING
), so factory function could be omitted?
Can DataTypes
be dependent on the dialect that was chosen in sequelize
instance, and thus preferred?
Upvotes: 2
Views: 3033
Reputation: 3326
Yes Sequelize fully interchangeable with DataTypes for data types.
Also datatypes are mapped according to dialect but they are added to Sequelize class so you can use either
Upvotes: 3