1async function updateOrCreate (model, where, newItem) {
2 // First try to find the record
3 const foundItem = await model.findOne({where});
4 if (!foundItem) {
5 // Item not found, create a new one
6 const item = await model.create(newItem)
7 return {item, created: true};
8 }
9 // Found an item, update it
10 const item = await model.update(newItem, {where});
11 return {item, created: false};
12}
13
1const objectToUpdate = {
2title: 'Hello World',
3description: 'Hello World'
4}
5
6models.Locale.update(objectToUpdate, { where: { id: 2}})
7
8