node.js - Calling a Postgres db function in Node API -
i trying call postgres function core.get_age(bigint) in queries.js
function getage(req, res, next){ var customer_id= parseint(req.params.customer_id); db.one('select * core.get_age($1)', customer_id) .then(function(data){ res.status(200) .json({ status: 'success', data : data, message: "retrieved age" }); }) } any routes in index.js
router.get('/api/age/:customer_id', db.getage); when call http://localhost:8080/api/age/10 in postman 404 error.
what wrong? first instance trying call postgres function(). trying retrieve postgres table select * from this.this table works function getting 404.
always use .catch promises! point @ problem, invalid number of rows returned in case.
function getage(req, res, next) { db.func('core.get_age', +req.params.customer_id) .then(data => { res.status(200) .json({ status: 'success', data : data, message: "retrieved age" }); }) .catch(error => { console.log(error); next(); }) }
Comments
Post a Comment