sequelize create model code example
Example 1: sequelize cli model generate
npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string
Example 2: create or update in sequelize
async function updateOrCreate (model, where, newItem) {
const foundItem = await model.findOne({where});
if (!foundItem) {
const item = await model.create(newItem)
return {item, created: true};
}
const item = await model.update(newItem, {where});
return {item, created: false};
}
Example 3: sequelize path
app.get('/fruit/:fruitName', function(req, res) {
console.log(req.params.fruitName);
});