nodeJs 쿼리문 예제정리

pizzu·2019년 1월 23일
0
  • INSERT
exports.insert = function (req,res) {
    var value = {
      			'id':req.body.id,
                  'name':req.body.name
                };

    var id = req.body.id;
    var name = req.body.name;
    var query = connection.query('insert into member set ?', value,function(err,result){
        			if(err){
          			console.log(err);
        			} else {
          			console.log("success");
        			}
      		 });	
};
  • SELECT
exports.users = function (req, res) {
    connection.query('select * from member', function (err, rows, fields) {
        res.json(rows);
    });
};
  • UPDATE
exports.update = function (req,res) {
    var value = {
      			'idx' : req.body.idx,
                  'flag' : req.body.flag
                };
    var idx = req.body.idx;
    var flag = req.body.flag;
    var query = connection.query('update schedule set ? WHERE idx = ?', [{ flag: flag}, idx], 
                function(err,result){
      			if(err){
        			console.log(err);
      			} else {
        			console.log("success");
      			}
    			});
};
profile
pizzu's blog

0개의 댓글