In code from 2016 using sequelize ORM, I see model types defined with this pattern:
module.exports = function(sequelize, DataTypes) {
const Tasks = sequelize.define("Tasks", { id: {
type: DataTypes.INTEGER,
[ ...etc.]
However in the current sequelize docs you see most prominently documented: Sequelize.INTEGER
(or other type then integer).
At the same time in the current docs I find also DataTypes
still documented/used
: here.
On same page the Sequelize.INTEGER
is used..., is that only for deferrables or something?
I tried to find whether this altered over time or something but could not find it.
When Sequelize.INTEGER
is 'current solution' could I just alter above code into:
module.exports = function(sequelize, Sequelize) {
const Tasks = sequelize.define("Tasks", { id: {
type: Sequelize.INTEGER,
[ ...etc.]
Or would using Sequelize
as argument somehow make this fail?
The second parameter in both of them is just the sequelize
package itself You can use any of them which is on you what you want to use
const Sequelize = require('sequelize');
You'll notice in your index.js of models (if you set up as suggested) that you do something like the below, where you are passing in sequelize
as the second argument.
const model = require(path.join(__dirname, file))(sequelize, Sequelize);
This exposes the data types. It doesn't matter what you call it. For example I am calling it abc
in below code you can use any name
module.exports = (sequelize, abc) => {
const Driver = sequelize.define('Driver', {
firstName: {
type: abc.STRING(),
allowNull: false
},
last_name: {
type: abc.TEXT,
allowNull: true
},
email: {
type: abc.TEXT,
allowNull: false
},
password: {
type: abc.TEXT,
allowNull: true
}
Same with migrations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With