简体   繁体   中英

Manipulating data using ORM Sequelize / node.js

I am looking to make an async function/class method that will be able to go into my database of tasks and change all the "complete" values to true.

My model is called Task. I think I may be confused on what the model is because I am just trying to set

Task.complete = true;

which is not doing anything. How do I actually access and manipulate the data? I am making a class method.

Task.completeAll() = async function(){

 Task.complete = true;
}

I have been using the .findAll() method on the Task but I thought that would be used to just find data, not necessarily manipulate it.

Thanks.

You should use model methods such as update . For instance:

Task.update({ complete: true }, { })

If you wish to update only certain records just specify where in an options object:

Task.update({ complete: true }, { where: {
  complete: false
}
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM