Пример получился такой:
index.js
var Sequelize = require('sequelize')
var sequelize = new Sequelize('product', null, null, {
dialect: "sqlite",
storage: './product.sqlite',
})
var Product = sequelize.define('Product', {
owner_id: Sequelize.STRING,
name: Sequelize.STRING,
price: Sequelize.INTEGER
})
sequelize
.sync({ force: true })
.then(function (err) {
const owner_id = 1
Product.bulkCreate([
{
owner_id: 1,
name: 'one',
price: 100
},
{
owner_id: 1,
name: 'one',
price: 200
}
]).then(() => {
return Product.update({ price: 300 }, { where: { owner_id: 1 } })
// хз тут возможно нужно делать транзакцию, если идти этим путем
// Product.findAll({ where: owner_id }).then(products => {
// products.forEach(product => {
// product.price = 300
// product.save()
// })
// })
}).spread((affectedCount, affectedRows) => {
return Product.findAll()
}).then(products => {
console.log(products)
})
}, function (err) {
console.log('An error occurred while creating the table:', err)
})
package.json
{
"name": "sequelize_findAll_update",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"sequelize": "^4.41.2",
"sqlite3": "^4.0.4"
}
}