Reputation: 410
I am new to Sequelize, coming from MongoDB and mongoose, in a mongoose schema you can do this to save an object field in the schema,
const userSchema = new Schema({
name: String,
age: String,
address: {} // this right here
})
Now my question is, how can I achieve such in Sequelize?
Upvotes: 1
Views: 1738
Reputation: 22758
You can use JSON datatype of field in Sequelize (this corresponds to JSON datatype in PostgreSQL).
const User = sequelize.define('User', {
name: {
type: DataTypes.STRING,
allowNull: false
},
age: {
type: DataTypes.STRING
},
address: {
type: DataTypes.JSON
}
}, {
});
That way you can write to address
field any JS-object (including an array).
Upvotes: 1