Tuesday 11 April 2017

Syntax error at or near “$1” with postgres insert in Node

Trouble with insert in Postgres from my nodeapi. I am getting syntax error while performing insert operation. I am trying to insert data from POSTMAN.

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

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

the error

POST /api/users 401 78.263 ms - 43
{ [error: syntax error at or near "$"]
  name: 'error',
  length: 102,
  severity: 'ERROR',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '86',
  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' }

Can anybody help me to understand what is wrong?



via OLDMONK

No comments:

Post a Comment