DEV Community

Discussion on: Persisting a Node API with PostgreSQL, without the help of ORM's like sequelize.

Collapse
 
tvmthomson profile image
Thomson Varkey

I am using PostgreSQL functions instead of query the problem facing is the errror. The errors are driven as result here the code follows

router.post('/insert_update_employee', (req, res) => {
debugger;
data = req.body;
pool.connect((err, client, done) => {
const query = 'SELECT insert_update_employee($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12) ';
const values = [data.ID, data.Name, data.DOB, data.ContactNo, data.EmailAddress, data.SupervisorID, data.PositionID, data.HireDate, data.IsSupervisor, data.ImageUrl, data.UserName, data.IsUpdate];
client.query(query, values, (err, result) => {
done();
if (err) {
debugger;
res.status(400).json({ err });
}
debugger;
res.status(202).send({
status: 'SUccessful',
result: result.rows[0]
});
});
});
});

Collapse
 
ogwurujohnson profile image
Johnson Ogwuru

Hi Thomson, sorry for the late reply. Can you explain a little bit further what the problem is? 😉