A
A
Alex102142021-06-27 16:34:44
Express.js
Alex10214, 2021-06-27 16:34:44

What to write in sequelize model?

Greetings, due to the lack of knowledge, I ran into a problem. I have a table in mysql and it has a 'side' column and it has a stupid 'enum('buy', 'sell')'. I'm creating a table model and don't know what to write in my model's form. I create a model for sequelize. Please tell me what to write type.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Simkav, 2021-06-27
@Alex10214

In a model in migration
type: DataTypes.ENUM("foo",'bar")
type: Sequelize.ENUM("foo",'bar")

D
DidarSalimgerey, 2021-06-27
@DidarSalimgerey

I do not know if my answer will help, but enum accepts several valid values ​​from which either the first or second value is selected, and so on. There can be more than two values. For example ENUM('value 1', 'value 2').
In the model try to write:

side: {
  type: Sequelize.ENUM('buy', 'shell'),
  default: 'buy' // можно указать значение по default'у
}

and another example:
status: {
   type: Sequelize.ENUM("pending", "cancelled", "paid"),
   defaultValue: "pending"
  },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question