2017-04-11 372 views
-1

從我的nodeapi插入Postgres時遇到問題。在執行插入操作時出現語法錯誤。我試圖從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(); 
 
}) 
 
}

錯誤

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' }

任何人可以幫助我瞭解什麼是錯的?

回答

0

愚蠢的錯誤與變量

這是現在工作

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)

相關問題