Monday, 10 April 2017

Insert function in node in postgre

Hello i am following a tutorial and trying to do a simple insert query but getting 404 error.

function

function insertUser(req, res, next){
  req.body.users = parseInt(req.body.users);
  
  db.none('INSERT INTO office.users VALUES (role_id,office_id,user_name,full_name)'+
           'values(${role_id},${office_id},${user_name},${full_name})', req.body.users)

   .then(function(){
        res.status(200)
        .json({
          status: 'success',
          message: 'Inserted one user'
   });
   })
 .catch(error => {
        console.log(error);
        next();
})
}

The stack trace says problem is near "values".i am not getting it.following i flow with the documentation.Something wrong with the query?

Stack trace

POST /api/users 401 10.020 ms - 43 { [error: syntax error at or near "values"] name: 'error', length: 107, severity: 'ERROR', code: '42601', detail: undefined, hint: undefined, position: '72', internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'src\backend\parser\scan.l', line: '1053', routine: 'scanner_yyerror' }

I am on my 5th day with Node.Bear with me.



via OLDMONK

No comments:

Post a Comment