mysql - how to update user table in node js -
mycode is--
updateuser: function(req, res) { var data = req.body; var option = { name: data.name, mobile: data.mobile, domain: data.domain, } usermodel.update(option, function (error, rows) { console.log('###############',error || rows); if(!res){ //todo: error handling console.log("error", res); res.status(200).send({"status_code": 0, 'message': 'some error occured'}); return; } res.status(200).send({"status_code": 1, 'message': 'succesfully updated'}); }) },
the problem updated user coloumn.
in code how give id of particular update data.
if not writing low level driver, recommend use orm https://github.com/sequelize/sequelize. first example on homepage shows:
var sequelize = require('sequelize'); var sequelize = new sequelize('database', 'username', 'password'); var user = sequelize.define('user', { username: sequelize.string, birthday: sequelize.date }); sequelize.sync().then(function() { return user.create({ username: 'janedoe', birthday: new date(1980, 6, 20) }); }).then(function(jane) { console.log(jane.get()); jane.update({ username: 'a different username now' }).then(function() { console.log(jane.get()); }) });
Comments
Post a Comment